Jump to content

How to prevent entity left click clientside?


StylexTV

Recommended Posts

How would I prevent the Minecraft#player from attacking an entity (left clicking it) if he plays on a vanilla server?

I already tried using the AttackEntityEvent and LivingAttackEvent and both actually get fired clientside but I can't seem to cancel them.

Link to comment
Share on other sites

10 minutes ago, diesieben07 said:

ClickInputEvent can be used to prevent all left clicks.

 

Thank you for that hint. I solved it by doing this:


    @SubscribeEvent
    public void onUserAttack(InputEvent.ClickInputEvent event) {
        if(event.isAttack()) {
            if(Minecraft.getInstance().objectMouseOver.getType()==RayTraceResult.Type.ENTITY) {
                EntityRayTraceResult result=(EntityRayTraceResult) Minecraft.getInstance().objectMouseOver;
                //example to check if target is of type pig
                if(result.getEntity().getType()==EntityType.PIG) event.setCanceled(true);
            }
        }
    }

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.