mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-21 01:02:19 +00:00
Implemented a better synchronisation system for left hand item and projectile item, similar to main hand and armor items system for vanilla
This commit is contained in:
1 parent
8aa9d16d8e
commit
21c16e5341
5 files changed
+30
-2
No files matched your search
@@ -22,6 +22,7 @@ public class DataInventory implements IInventory {
|
||||
public HashMap<Integer,ItemStack> items = new HashMap<Integer,ItemStack>();
|
||||
public HashMap<Integer,Double> dropchance = new HashMap<Integer,Double>();
|
||||
public HashMap<Integer,ItemStack> weapons = new HashMap<Integer, ItemStack>();
|
||||
public HashMap<Integer,ItemStack> prevWeapons = new HashMap<Integer, ItemStack>();
|
||||
public HashMap<Integer,ItemStack> armor = new HashMap<Integer, ItemStack>();
|
||||
|
||||
public int minExp = 0;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,5 +49,6 @@ public enum EnumPacketClient {
|
||||
STOP_SOUND_FOR,
|
||||
PAUSE_SOUNDS,
|
||||
CONTINUE_SOUNDS,
|
||||
STOP_SOUNDS
|
||||
STOP_SOUNDS,
|
||||
SYNC_WEAPON
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -436,7 +436,7 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
|
||||
npc.inventory.setOffHand(null);
|
||||
else
|
||||
npc.inventory.setOffHand(item.getMCItemStack());
|
||||
npc.script.clientNeedsUpdate = true;
|
||||
//npc.script.clientNeedsUpdate = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user