StylexTV Posted April 8, 2020 Posted April 8, 2020 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. Quote
StylexTV Posted April 8, 2020 Author Posted April 8, 2020 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); } } } Quote
Recommended Posts
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.