From c1f4e50b0444abc090743600986661996aea68b3 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 3 Apr 2025 15:02:40 -0400 Subject: [PATCH] Fix Inventory Armor Contents for Linked Items --- .../java/noppes/npcs/items/ItemLinked.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/noppes/npcs/items/ItemLinked.java b/src/main/java/noppes/npcs/items/ItemLinked.java index 011f971ea..9e6209eeb 100644 --- a/src/main/java/noppes/npcs/items/ItemLinked.java +++ b/src/main/java/noppes/npcs/items/ItemLinked.java @@ -4,6 +4,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; +import net.minecraft.network.play.server.S04PacketEntityEquipment; import net.minecraft.world.World; import noppes.npcs.CustomNpcs; import noppes.npcs.EventHooks; @@ -44,12 +45,26 @@ public class ItemLinked extends ItemCustomizable { } else if (linkedItem == null) { if (entity instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) entity; - player.inventory.setInventorySlotContents(itemSlot, null); // Remove the item - player.inventory.markDirty(); // Ensure inventory updates + player.inventory.setInventorySlotContents(itemSlot, null); + player.inventory.markDirty(); // Sync inventory with client if (player instanceof EntityPlayerMP) { - ((EntityPlayerMP) player).sendContainerToPlayer(player.inventoryContainer); + EntityPlayerMP playerMP = (EntityPlayerMP) player; + int equipmentSlot = -1; + // In vanilla 1.7.10, container slots 36-39 are the armor slots: + // slot 36: boots, 37: leggings, 38: chestplate, 39: helmet. + if (itemSlot >= 36 && itemSlot < 40) { + // Map container slot to equipment slot: boots=1, leggings=2, chestplate=3, helmet=4. + equipmentSlot = itemSlot - 35; + } + if (equipmentSlot != -1) { + playerMP.playerNetServerHandler.sendPacket( + new S04PacketEntityEquipment(player.getEntityId(), equipmentSlot, null) + ); + } else { + playerMP.sendContainerToPlayer(player.inventoryContainer); + } } } }