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

Started by eDdniom on

Topic category: Help with Minecraft modding (Java Edition)

Active 1 month ago
Joined Oct 2020
Points:
667

User statistics:

  • Modifications: 0
  • Forum topics: 9
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 20
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? 

Active 6 months ago
Joined Mar 2024
Points:
114

User statistics:

  • Modifications: 0
  • Forum topics: 0
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 8
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

Active 1 month ago
Joined Oct 2020
Points:
667

User statistics:

  • Modifications: 0
  • Forum topics: 9
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 20
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

Active 6 months ago
Joined Mar 2024
Points:
114

User statistics:

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

problem solved I think

 

(sourceentity.isShiftKeyDown() && (this.isTame() && this.isOwnedBy(sourceentity)))
Active 1 month ago
Joined Oct 2020
Points:
667

User statistics:

  • Modifications: 0
  • Forum topics: 9
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 20
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 :)

Active 7 months ago
Joined Sep 2024
Points:
96

User statistics:

  • Modifications: 0
  • Forum topics: 5
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 17
hey i have the same problem…
Sun, 09/22/2024 - 12:13

hey i have the same problem how i can fix it with a procedure? oder a code  if is a code  please snt here  or a screenshot of the procedure :)