Need help on opening mobs inventory when the mob is tamed and the owner is sneaking.

Started by eDdniom on

Topic category: Help with modding (Java Edition)

Last seen on 12:53, 20. May 2024
Joined Oct 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Need help on opening mobs inventory when the mob is tamed and the owner is sneaking.

I made a pet mob that has an inventory but in mcreator you can't set a condition for when the inventory could be open, is there a way to add conditions? 

Last seen on 09:24, 19. May 2024
Joined Mar 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It's annoying trying to feed…
Fri, 05/17/2024 - 07:45

It's annoying trying to feed a pet with inventory,  I tried making a procedure for it but the items in the inventory kept disappearing, instead I edited the code, where the override for the inventory is I wrote a line before the first 'if' : 

if (sourceentity.isShiftKeyDown()) {

 

and a bracket at the close  " } "      

                                                                                                                                                  }

example:

 

@Override

public InteractionResult mobInteract(Player sourceentity, InteractionHand hand) {
ItemStack itemstack = sourceentity.getItemInHand(hand);
InteractionResult retval = InteractionResult.sidedSuccess(this.level().isClientSide());
if (sourceentity.isShiftKeyDown()) {
if (sourceentity instanceof ServerPlayer serverPlayer) {
NetworkHooks.openScreen(serverPlayer, new MenuProvider() {
@Override
public Component getDisplayName() {
return Component.literal("thief");
}

@Override
public AbstractContainerMenu createMenu(int id, Inventory inventory, Player player) {
FriendlyByteBuf packetBuffer = new FriendlyByteBuf(Unpooled.buffer());
packetBuffer.writeBlockPos(sourceentity.blockPosition());
packetBuffer.writeByte(0);
packetBuffer.writeVarInt(ThiefEntity.this.getId());
return new ThiefGUIMenu(id, inventory, packetBuffer);
}
}, buf -> {
buf.writeBlockPos(sourceentity.blockPosition());
buf.writeByte(0);
buf.writeVarInt(this.getId());
});
}
}

 

It has worked so far, and he hasn't stolen anything. drops the inventory on death

Last seen on 12:53, 20. May 2024
Joined Oct 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Yeah It works great, but you…
Fri, 05/17/2024 - 12:47

Yeah It works great, but you can open the inventory even if the pet is not tamed, that's the problem

Last seen on 09:24, 19. May 2024
Joined Mar 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
problem solved I think   …
Sat, 05/18/2024 - 03:02

problem solved I think

 

(sourceentity.isShiftKeyDown() && (this.isTame() && this.isOwnedBy(sourceentity)))
Last seen on 12:53, 20. May 2024
Joined Oct 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
yes, tried to do it myself…
Sat, 05/18/2024 - 13:02

yes, tried to do it myself but it did not work as intended, now it works great, thank you :)