Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.5] Add metals that Piglins won't attack


izofar
 Share

Recommended Posts

Part 1) I want to add an armor material that piglins won't attack. I've traced a single line of code... if only I could modify! In IForgeItem#makesPiglinsNeutral, the input is checked that it is of gold material. How do I add my custom Armor material to this? Do I need reflection, or does forge allow an easier way to achieve/override this?

This method is called by IForgeItemStack#makesPiglinsNeutral, which is called by entity.monster.piglin.PiglinTasks#isWearingGold, called by PiglinMobSensor#doTick to update MemoryModuleType.NEAREST_TARGETABLE_PLAYER_NOT_WEARING_GOLD

Part 2) I want to extend this behavior to piglin brutes. This likely requires an exponentially more difficult workaround. Any insight to this, and generally overriding vanilla mob features that aren't represented in Forge events?

Link to comment
Share on other sites

6 hours ago, diesieben07 said:

You override this method in your item class.

The IForgeItem method ends up being called in the following snippet by makesPiglingsNeutral:

public static boolean isWearingGold(LivingEntity p_234460_0_) {
      for(ItemStack itemstack : p_234460_0_.getArmorSlots()) {
         Item item = itemstack.getItem();
         if (itemstack.makesPiglinsNeutral(p_234460_0_)) {
            return true;
         }
      }

      return false;
   }

And the default IForgeItemStack method is:

default boolean makesPiglinsNeutral(LivingEntity wearer)
    {
        return getStack().getItem().makesPiglinsNeutral(getStack(), wearer);
    }

Will getItem().makesPiglingsNeutral return my overridden method? Or the default, since getItem() will return type Item rather than my ModdedArmorItem class?

Link to comment
Share on other sites

Just now, izofar said:

Will getItem().makesPiglingsNeutral return my overridden method? Or the default, since getItem() will return type Item rather than my ModdedArmorItem class?

yes, if the ItemStack consists of your item

  • Thanks 1
Link to comment
Share on other sites

20 minutes ago, izofar said:

Will getItem().makesPiglingsNeutral return my overridden method? Or the default, since getItem() will return type Item rather than my ModdedArmorItem class?

Please learn the basics of OOP and Java.

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
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.