Entity Inventory opens only if the entity is tamed

Started by el_m4gician on

Topic category: Help with MCreator software

Joined Aug 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Entity Inventory opens only if the entity is tamed

Hello everyone, I wonder if someone can resolve this problem. I have a custom entity that can be tamed. But I want that the entity allows you to get in his inventory only if that entity is tamed. I have already a little GUI made for this, I just want to make a horse-inventory-like for the entity. Any suggestions?

 

My version is V2022.1. 

Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You have to edit the entity…
Mon, 08/22/2022 - 04:44

You have to edit the entity code, but it is just one extra if statement. In your entityname.java class find the Interaction Result

@Override
    public InteractionResult mobInteract(Player sourceentity, InteractionHand hand) {

directly after this line add to tell if the entity is tamed by the source entity

 if (entity instanceof TamableAnimal _tamIsTamedBy && sourceentity instanceof LivingEntity _livEnt
 ? _tamIsTamedBy.isOwnedBy(_livEnt)
 : false) {

Then add a bracket at the end of the class to close the if statement and your good to go! Allows a binding gui on an entity where it only opens if the entity is tamed by the player. In a similar manner, you can prevent a binded gui from opening for just about any if statement you can think of.