diff --git a/src/main/java/noppes/npcs/DataInventory.java b/src/main/java/noppes/npcs/DataInventory.java index c4e5b8c9a..992a68ae5 100644 --- a/src/main/java/noppes/npcs/DataInventory.java +++ b/src/main/java/noppes/npcs/DataInventory.java @@ -22,6 +22,7 @@ public class DataInventory implements IInventory { public HashMap items = new HashMap(); public HashMap dropchance = new HashMap(); public HashMap weapons = new HashMap(); + public HashMap prevWeapons = new HashMap(); public HashMap armor = new HashMap(); public int minExp = 0; diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index 657b6d455..647941ff7 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -358,5 +358,14 @@ public class PacketHandlerClient extends PacketHandlerServer{ else if(type == EnumPacketClient.STOP_SOUNDS) { ScriptSoundController.Instance.stopAllSounds(); } + else if(type == EnumPacketClient.SYNC_WEAPON) { + Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(buffer.readInt()); + if(!(entity instanceof EntityNPCInterface)) + return; + EntityNPCInterface npc = (EntityNPCInterface) entity; + int weaponSlotIndex = buffer.readInt(); + ItemStack stack = ItemStack.loadItemStackFromNBT(Server.readNBT(buffer)); + npc.inventory.weapons.put(weaponSlotIndex,stack); + } } } diff --git a/src/main/java/noppes/npcs/constants/EnumPacketClient.java b/src/main/java/noppes/npcs/constants/EnumPacketClient.java index 091588edd..4796a0bd5 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketClient.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketClient.java @@ -49,5 +49,6 @@ public enum EnumPacketClient { STOP_SOUND_FOR, PAUSE_SOUNDS, CONTINUE_SOUNDS, - STOP_SOUNDS + STOP_SOUNDS, + SYNC_WEAPON } diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 38058b2b5..67ddcf18f 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -23,9 +23,11 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemBow; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.play.server.S04PacketEntityEquipment; import net.minecraft.pathfinding.PathNavigate; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; +import net.minecraft.server.MinecraftServer; import net.minecraft.util.*; import net.minecraft.world.World; import net.minecraft.world.WorldServer; @@ -197,6 +199,21 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti if (this.ticksExisted % 10 == 0) { EventHooks.onNPCUpdate(this); } + for(int i=1;i<3;i++){ + ItemStack itemstack = inventory.prevWeapons.get(i); + ItemStack itemstack1 = inventory.weapons.get(i); + if (!ItemStack.areItemStacksEqual(itemstack1, itemstack)) + { + NBTTagCompound itemNBT = new NBTTagCompound(); + if(itemstack1!=null){ + itemstack1.writeToNBT(itemNBT); + } + for(Object obj: MinecraftServer.getServer().getConfigurationManager().playerEntityList){ + Server.sendData((EntityPlayerMP) obj, EnumPacketClient.SYNC_WEAPON, getEntityId(), i, itemNBT); + } + inventory.prevWeapons.put(i,itemstack1 == null ? null : itemstack1.copy()); + } + } this.timers.update(); } } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index a90216a0a..2a7ee13a9 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -436,7 +436,7 @@ public class ScriptNpc extends ScriptLiving imp npc.inventory.setOffHand(null); else npc.inventory.setOffHand(item.getMCItemStack()); - npc.script.clientNeedsUpdate = true; + //npc.script.clientNeedsUpdate = true; } /**