Jump to content

Recommended Posts

Posted

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.

Posted
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);
        }
    }

 

Posted
@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

Posted

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.

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.