Posted December 29, 20213 yr How do I access the mobs (specifically passive animals) in order to modify them, making them invincible for example. I'm new to minecraft modding. Thanks so much for any help.
December 29, 20213 yr Author 5 hours ago, diesieben07 said: It depends on what aspects you want to modify. For invincibility there are two options: Subscribe to EntityJoinWorldEvent (once PR 8264 is merged use that event instead). In there call Entity#setInvulnerable(true) for all entities that you want to be invulnerable. Alternatively you can use LivingAttackEvent. Cancel it to prevent damage to a living entity. This allows more fine grained control. For other aspects that you want to modify, you'll have to provide details. Can I just ask, I wrote this quick code, should this not work? It doesn't seem to: @EventHandler public void attack(LivingDamageEvent event) { if (event.getEntity() instanceof EntityCow) { event.setCanceled(true); } }
December 29, 20213 yr Author @EventHandler public void attack(LivingDamageEvent event) { if (event.getEntity() instanceof EntityCow) { event.setCanceled(true); } } I'm new to minecraft mods, why does this not trigger when I hit a cow and cancel the damage? Thank you
December 30, 20213 yr because you didn't read the technicalities, you just copied the event handler. make that method static and put the EventBusSubscriber annotation on the containing class. there is a second option and it looks like you tried to follow that one, but just go with the option one (above).
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.