Jump to content

[1.17.1] Overriding Vanilla method


KopoL

Recommended Posts

Forge 1.17.1
Hello. I want to do something like scare mobs potion effect. It basically would make mobs ignore the player, just like on gamemode creative. I discovered that when I give player disableDamage ability (player.abilities.disableDamage), mobs start to ignore the player. But I don't want to make player invulnerable (I'll use tags).
Then I found this method in MobEntity class:

public boolean canAttack(LivingEntity target) {
      return target.getType() == EntityType.PLAYER && ((PlayerEntity)target).abilities.disableDamage ? false : super.canAttack(target);
   }


I just need to somehow override/change/...? it to something like

return target.getType() == EntityType.PLAYER && ((PlayerEntity)target).getTags().contains("scare_mobs") ? false && ((PlayerEntity)target).abilities.disableDamage ? false : super.canAttack(target);)

but I don't really know how. What is the best way to do this, without breaking the game?

Edited by KopoL
Link to comment
Share on other sites

  • KopoL changed the title to [1.17.1] Overriding Vanilla method

Okay, thank you. But do you think of any other way to prevent them from attacking the player without making him invulnerable - without using abilities? Because using core modding is my final solution, If I had any other option I'd prefer to use it.

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.