Send equipment packets when equipment changes

This commit is contained in:
fullwall 2021-01-24 19:25:59 +08:00
parent 80187501d0
commit 9cbc1c6bd8
8 changed files with 104 additions and 9 deletions

View File

@ -49,6 +49,7 @@ import net.minecraft.server.v1_10_R1.EnumItemSlot;
import net.minecraft.server.v1_10_R1.EnumProtocolDirection; import net.minecraft.server.v1_10_R1.EnumProtocolDirection;
import net.minecraft.server.v1_10_R1.GenericAttributes; import net.minecraft.server.v1_10_R1.GenericAttributes;
import net.minecraft.server.v1_10_R1.IBlockData; import net.minecraft.server.v1_10_R1.IBlockData;
import net.minecraft.server.v1_10_R1.ItemStack;
import net.minecraft.server.v1_10_R1.MinecraftServer; import net.minecraft.server.v1_10_R1.MinecraftServer;
import net.minecraft.server.v1_10_R1.NavigationAbstract; import net.minecraft.server.v1_10_R1.NavigationAbstract;
import net.minecraft.server.v1_10_R1.NetworkManager; import net.minecraft.server.v1_10_R1.NetworkManager;
@ -63,12 +64,14 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
private PlayerControllerJump controllerJump; private PlayerControllerJump controllerJump;
private PlayerControllerLook controllerLook; private PlayerControllerLook controllerLook;
private PlayerControllerMove controllerMove; private PlayerControllerMove controllerMove;
private final Map<EnumItemSlot, ItemStack> equipmentCache = Maps.newEnumMap(EnumItemSlot.class);
private boolean isTracked = false; private boolean isTracked = false;
private int jumpTicks = 0; private int jumpTicks = 0;
private PlayerNavigation navigation; private PlayerNavigation navigation;
private final CitizensNPC npc; private final CitizensNPC npc;
private final Location packetLocationCache = new Location(null, 0, 0, 0); private final Location packetLocationCache = new Location(null, 0, 0, 0);
private final SkinPacketTracker skinTracker; private final SkinPacketTracker skinTracker;
private int updateCounter = 0; private int updateCounter = 0;
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile, public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
@ -403,7 +406,16 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
private void updatePackets(boolean navigating) { private void updatePackets(boolean navigating) {
if (updateCounter++ <= Setting.PACKET_UPDATE_DELAY.asInt()) updateCounter++;
boolean itemChanged = false;
for (EnumItemSlot slot : EnumItemSlot.values()) {
ItemStack equipment = getEquipment(slot);
if (!ItemStack.equals(equipmentCache.get(slot), equipment)) {
itemChanged = true;
}
equipmentCache.put(slot, equipment);
}
if (updateCounter++ <= Setting.PACKET_UPDATE_DELAY.asInt() && !itemChanged)
return; return;
updateCounter = 0; updateCounter = 0;
Location current = getBukkitEntity().getLocation(packetLocationCache); Location current = getBukkitEntity().getLocation(packetLocationCache);

View File

@ -51,6 +51,7 @@ import net.minecraft.server.v1_11_R1.EnumProtocolDirection;
import net.minecraft.server.v1_11_R1.GenericAttributes; import net.minecraft.server.v1_11_R1.GenericAttributes;
import net.minecraft.server.v1_11_R1.IBlockData; import net.minecraft.server.v1_11_R1.IBlockData;
import net.minecraft.server.v1_11_R1.IChatBaseComponent; import net.minecraft.server.v1_11_R1.IChatBaseComponent;
import net.minecraft.server.v1_11_R1.ItemStack;
import net.minecraft.server.v1_11_R1.MinecraftServer; import net.minecraft.server.v1_11_R1.MinecraftServer;
import net.minecraft.server.v1_11_R1.NavigationAbstract; import net.minecraft.server.v1_11_R1.NavigationAbstract;
import net.minecraft.server.v1_11_R1.NetworkManager; import net.minecraft.server.v1_11_R1.NetworkManager;
@ -65,12 +66,14 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
private PlayerControllerJump controllerJump; private PlayerControllerJump controllerJump;
private PlayerControllerLook controllerLook; private PlayerControllerLook controllerLook;
private PlayerControllerMove controllerMove; private PlayerControllerMove controllerMove;
private final Map<EnumItemSlot, ItemStack> equipmentCache = Maps.newEnumMap(EnumItemSlot.class);
private boolean isTracked = false; private boolean isTracked = false;
private int jumpTicks = 0; private int jumpTicks = 0;
private PlayerNavigation navigation; private PlayerNavigation navigation;
private final CitizensNPC npc; private final CitizensNPC npc;
private final Location packetLocationCache = new Location(null, 0, 0, 0); private final Location packetLocationCache = new Location(null, 0, 0, 0);
private final SkinPacketTracker skinTracker; private final SkinPacketTracker skinTracker;
private int updateCounter = 0; private int updateCounter = 0;
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile, public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
@ -414,7 +417,16 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
private void updatePackets(boolean navigating) { private void updatePackets(boolean navigating) {
if (updateCounter++ <= Setting.PACKET_UPDATE_DELAY.asInt()) updateCounter++;
boolean itemChanged = false;
for (EnumItemSlot slot : EnumItemSlot.values()) {
ItemStack equipment = getEquipment(slot);
if (!ItemStack.equals(equipmentCache.get(slot), equipment)) {
itemChanged = true;
}
equipmentCache.put(slot, equipment);
}
if (updateCounter++ <= Setting.PACKET_UPDATE_DELAY.asInt() && !itemChanged)
return; return;
updateCounter = 0; updateCounter = 0;

View File

@ -55,6 +55,7 @@ import net.minecraft.server.v1_12_R1.EnumProtocolDirection;
import net.minecraft.server.v1_12_R1.GenericAttributes; import net.minecraft.server.v1_12_R1.GenericAttributes;
import net.minecraft.server.v1_12_R1.IBlockData; import net.minecraft.server.v1_12_R1.IBlockData;
import net.minecraft.server.v1_12_R1.IChatBaseComponent; import net.minecraft.server.v1_12_R1.IChatBaseComponent;
import net.minecraft.server.v1_12_R1.ItemStack;
import net.minecraft.server.v1_12_R1.MinecraftServer; import net.minecraft.server.v1_12_R1.MinecraftServer;
import net.minecraft.server.v1_12_R1.NavigationAbstract; import net.minecraft.server.v1_12_R1.NavigationAbstract;
import net.minecraft.server.v1_12_R1.NetworkManager; import net.minecraft.server.v1_12_R1.NetworkManager;
@ -69,12 +70,14 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
private PlayerControllerJump controllerJump; private PlayerControllerJump controllerJump;
private PlayerControllerLook controllerLook; private PlayerControllerLook controllerLook;
private PlayerControllerMove controllerMove; private PlayerControllerMove controllerMove;
private final Map<EnumItemSlot, ItemStack> equipmentCache = Maps.newEnumMap(EnumItemSlot.class);
private int jumpTicks = 0; private int jumpTicks = 0;
private PlayerNavigation navigation; private PlayerNavigation navigation;
private final CitizensNPC npc; private final CitizensNPC npc;
private final Location packetLocationCache = new Location(null, 0, 0, 0); private final Location packetLocationCache = new Location(null, 0, 0, 0);
private final SkinPacketTracker skinTracker; private final SkinPacketTracker skinTracker;
private PlayerlistTrackerEntry trackerEntry; private PlayerlistTrackerEntry trackerEntry;
private int updateCounter = 0; private int updateCounter = 0;
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile, public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
@ -441,7 +444,16 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
private void updatePackets(boolean navigating) { private void updatePackets(boolean navigating) {
if (updateCounter++ <= Setting.PACKET_UPDATE_DELAY.asInt()) updateCounter++;
boolean itemChanged = false;
for (EnumItemSlot slot : EnumItemSlot.values()) {
ItemStack equipment = getEquipment(slot);
if (!ItemStack.equals(equipmentCache.get(slot), equipment)) {
itemChanged = true;
}
equipmentCache.put(slot, equipment);
}
if (updateCounter++ <= Setting.PACKET_UPDATE_DELAY.asInt() && !itemChanged)
return; return;
updateCounter = 0; updateCounter = 0;

View File

@ -55,6 +55,7 @@ import net.minecraft.server.v1_13_R2.EnumProtocolDirection;
import net.minecraft.server.v1_13_R2.GenericAttributes; import net.minecraft.server.v1_13_R2.GenericAttributes;
import net.minecraft.server.v1_13_R2.IBlockData; import net.minecraft.server.v1_13_R2.IBlockData;
import net.minecraft.server.v1_13_R2.IChatBaseComponent; import net.minecraft.server.v1_13_R2.IChatBaseComponent;
import net.minecraft.server.v1_13_R2.ItemStack;
import net.minecraft.server.v1_13_R2.MinecraftServer; import net.minecraft.server.v1_13_R2.MinecraftServer;
import net.minecraft.server.v1_13_R2.NavigationAbstract; import net.minecraft.server.v1_13_R2.NavigationAbstract;
import net.minecraft.server.v1_13_R2.NetworkManager; import net.minecraft.server.v1_13_R2.NetworkManager;
@ -69,12 +70,14 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
private PlayerControllerJump controllerJump; private PlayerControllerJump controllerJump;
private PlayerControllerLook controllerLook; private PlayerControllerLook controllerLook;
private PlayerControllerMove controllerMove; private PlayerControllerMove controllerMove;
private final Map<EnumItemSlot, ItemStack> equipmentCache = Maps.newEnumMap(EnumItemSlot.class);
private int jumpTicks = 0; private int jumpTicks = 0;
private PlayerNavigation navigation; private PlayerNavigation navigation;
private final CitizensNPC npc; private final CitizensNPC npc;
private final Location packetLocationCache = new Location(null, 0, 0, 0); private final Location packetLocationCache = new Location(null, 0, 0, 0);
private final SkinPacketTracker skinTracker; private final SkinPacketTracker skinTracker;
private PlayerlistTrackerEntry trackerEntry; private PlayerlistTrackerEntry trackerEntry;
private int updateCounter = 0; private int updateCounter = 0;
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile, public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
@ -432,7 +435,16 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
private void updatePackets(boolean navigating) { private void updatePackets(boolean navigating) {
if (updateCounter++ <= Setting.PACKET_UPDATE_DELAY.asInt()) updateCounter++;
boolean itemChanged = false;
for (EnumItemSlot slot : EnumItemSlot.values()) {
ItemStack equipment = getEquipment(slot);
if (!ItemStack.equals(equipmentCache.get(slot), equipment)) {
itemChanged = true;
}
equipmentCache.put(slot, equipment);
}
if (updateCounter++ <= Setting.PACKET_UPDATE_DELAY.asInt() && !itemChanged)
return; return;
updateCounter = 0; updateCounter = 0;

View File

@ -53,6 +53,7 @@ import net.minecraft.server.v1_14_R1.EnumProtocolDirection;
import net.minecraft.server.v1_14_R1.GenericAttributes; import net.minecraft.server.v1_14_R1.GenericAttributes;
import net.minecraft.server.v1_14_R1.IBlockData; import net.minecraft.server.v1_14_R1.IBlockData;
import net.minecraft.server.v1_14_R1.IChatBaseComponent; import net.minecraft.server.v1_14_R1.IChatBaseComponent;
import net.minecraft.server.v1_14_R1.ItemStack;
import net.minecraft.server.v1_14_R1.MinecraftServer; import net.minecraft.server.v1_14_R1.MinecraftServer;
import net.minecraft.server.v1_14_R1.NavigationAbstract; import net.minecraft.server.v1_14_R1.NavigationAbstract;
import net.minecraft.server.v1_14_R1.NetworkManager; import net.minecraft.server.v1_14_R1.NetworkManager;
@ -68,12 +69,14 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
private PlayerControllerJump controllerJump; private PlayerControllerJump controllerJump;
private PlayerControllerLook controllerLook; private PlayerControllerLook controllerLook;
private PlayerControllerMove controllerMove; private PlayerControllerMove controllerMove;
private final Map<EnumItemSlot, ItemStack> equipmentCache = Maps.newEnumMap(EnumItemSlot.class);
private int jumpTicks = 0; private int jumpTicks = 0;
private PlayerNavigation navigation; private PlayerNavigation navigation;
private final CitizensNPC npc; private final CitizensNPC npc;
private final Location packetLocationCache = new Location(null, 0, 0, 0); private final Location packetLocationCache = new Location(null, 0, 0, 0);
private PlayerlistTracker playerlistTracker; private PlayerlistTracker playerlistTracker;
private final SkinPacketTracker skinTracker; private final SkinPacketTracker skinTracker;
private int updateCounter = 0; private int updateCounter = 0;
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile, public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
@ -436,7 +439,16 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
private void updatePackets(boolean navigating) { private void updatePackets(boolean navigating) {
if (updateCounter++ <= Setting.PACKET_UPDATE_DELAY.asInt()) updateCounter++;
boolean itemChanged = false;
for (EnumItemSlot slot : EnumItemSlot.values()) {
ItemStack equipment = getEquipment(slot);
if (!ItemStack.equals(equipmentCache.get(slot), equipment)) {
itemChanged = true;
}
equipmentCache.put(slot, equipment);
}
if (updateCounter++ <= Setting.PACKET_UPDATE_DELAY.asInt() && !itemChanged)
return; return;
updateCounter = 0; updateCounter = 0;

View File

@ -53,6 +53,7 @@ import net.minecraft.server.v1_15_R1.EnumProtocolDirection;
import net.minecraft.server.v1_15_R1.GenericAttributes; import net.minecraft.server.v1_15_R1.GenericAttributes;
import net.minecraft.server.v1_15_R1.IBlockData; import net.minecraft.server.v1_15_R1.IBlockData;
import net.minecraft.server.v1_15_R1.IChatBaseComponent; import net.minecraft.server.v1_15_R1.IChatBaseComponent;
import net.minecraft.server.v1_15_R1.ItemStack;
import net.minecraft.server.v1_15_R1.MinecraftServer; import net.minecraft.server.v1_15_R1.MinecraftServer;
import net.minecraft.server.v1_15_R1.NavigationAbstract; import net.minecraft.server.v1_15_R1.NavigationAbstract;
import net.minecraft.server.v1_15_R1.NetworkManager; import net.minecraft.server.v1_15_R1.NetworkManager;
@ -68,12 +69,14 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
private PlayerControllerJump controllerJump; private PlayerControllerJump controllerJump;
private PlayerControllerLook controllerLook; private PlayerControllerLook controllerLook;
private PlayerControllerMove controllerMove; private PlayerControllerMove controllerMove;
private final Map<EnumItemSlot, ItemStack> equipmentCache = Maps.newEnumMap(EnumItemSlot.class);
private int jumpTicks = 0; private int jumpTicks = 0;
private PlayerNavigation navigation; private PlayerNavigation navigation;
private final CitizensNPC npc; private final CitizensNPC npc;
private final Location packetLocationCache = new Location(null, 0, 0, 0); private final Location packetLocationCache = new Location(null, 0, 0, 0);
private PlayerlistTracker playerlistTracker; private PlayerlistTracker playerlistTracker;
private final SkinPacketTracker skinTracker; private final SkinPacketTracker skinTracker;
private int updateCounter = 0; private int updateCounter = 0;
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile, public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
@ -447,9 +450,17 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
private void updatePackets(boolean navigating) { private void updatePackets(boolean navigating) {
if (updateCounter++ <= Setting.PACKET_UPDATE_DELAY.asInt()) updateCounter++;
boolean itemChanged = false;
for (EnumItemSlot slot : EnumItemSlot.values()) {
ItemStack equipment = getEquipment(slot);
if (!ItemStack.equals(equipmentCache.get(slot), equipment)) {
itemChanged = true;
}
equipmentCache.put(slot, equipment);
}
if (updateCounter++ <= Setting.PACKET_UPDATE_DELAY.asInt() && !itemChanged)
return; return;
updateCounter = 0; updateCounter = 0;
Location current = getBukkitEntity().getLocation(packetLocationCache); Location current = getBukkitEntity().getLocation(packetLocationCache);
Packet<?>[] packets = new Packet[EnumItemSlot.values().length]; Packet<?>[] packets = new Packet[EnumItemSlot.values().length];

View File

@ -77,12 +77,14 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
private PlayerControllerJump controllerJump; private PlayerControllerJump controllerJump;
private PlayerControllerLook controllerLook; private PlayerControllerLook controllerLook;
private PlayerControllerMove controllerMove; private PlayerControllerMove controllerMove;
private final Map<EnumItemSlot, ItemStack> equipmentCache = Maps.newEnumMap(EnumItemSlot.class);
private int jumpTicks = 0; private int jumpTicks = 0;
private PlayerNavigation navigation; private PlayerNavigation navigation;
private final CitizensNPC npc; private final CitizensNPC npc;
private final Location packetLocationCache = new Location(null, 0, 0, 0); private final Location packetLocationCache = new Location(null, 0, 0, 0);
private PlayerlistTracker playerlistTracker; private PlayerlistTracker playerlistTracker;
private final SkinPacketTracker skinTracker; private final SkinPacketTracker skinTracker;
private int updateCounter = 0; private int updateCounter = 0;
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile, public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
@ -478,7 +480,16 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
private void updatePackets(boolean navigating) { private void updatePackets(boolean navigating) {
if (updateCounter++ <= Setting.PACKET_UPDATE_DELAY.asInt()) updateCounter++;
boolean itemChanged = false;
for (EnumItemSlot slot : EnumItemSlot.values()) {
ItemStack equipment = getEquipment(slot);
if (!ItemStack.equals(equipmentCache.get(slot), equipment)) {
itemChanged = true;
}
equipmentCache.put(slot, equipment);
}
if (updateCounter++ <= Setting.PACKET_UPDATE_DELAY.asInt() && !itemChanged)
return; return;
updateCounter = 0; updateCounter = 0;

View File

@ -15,6 +15,7 @@ import org.bukkit.util.Vector;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import gnu.trove.map.hash.TIntObjectHashMap;
import net.citizensnpcs.Settings.Setting; import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.NPCEnderTeleportEvent; import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
@ -46,6 +47,7 @@ import net.minecraft.server.v1_8_R3.Entity;
import net.minecraft.server.v1_8_R3.EntityPlayer; import net.minecraft.server.v1_8_R3.EntityPlayer;
import net.minecraft.server.v1_8_R3.EnumProtocolDirection; import net.minecraft.server.v1_8_R3.EnumProtocolDirection;
import net.minecraft.server.v1_8_R3.GenericAttributes; import net.minecraft.server.v1_8_R3.GenericAttributes;
import net.minecraft.server.v1_8_R3.ItemStack;
import net.minecraft.server.v1_8_R3.MinecraftServer; import net.minecraft.server.v1_8_R3.MinecraftServer;
import net.minecraft.server.v1_8_R3.NavigationAbstract; import net.minecraft.server.v1_8_R3.NavigationAbstract;
import net.minecraft.server.v1_8_R3.NetworkManager; import net.minecraft.server.v1_8_R3.NetworkManager;
@ -59,12 +61,14 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
private PlayerControllerJump controllerJump; private PlayerControllerJump controllerJump;
private PlayerControllerLook controllerLook; private PlayerControllerLook controllerLook;
private PlayerControllerMove controllerMove; private PlayerControllerMove controllerMove;
private final TIntObjectHashMap<ItemStack> equipmentCache = new TIntObjectHashMap<ItemStack>();
private int jumpTicks = 0; private int jumpTicks = 0;
private PlayerNavigation navigation; private PlayerNavigation navigation;
private final CitizensNPC npc; private final CitizensNPC npc;
private final Location packetLocationCache = new Location(null, 0, 0, 0); private final Location packetLocationCache = new Location(null, 0, 0, 0);
private final SkinPacketTracker skinTracker; private final SkinPacketTracker skinTracker;
private PlayerlistTrackerEntry trackerEntry; private PlayerlistTrackerEntry trackerEntry;
private int updateCounter = 0; private int updateCounter = 0;
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile, public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
@ -402,7 +406,16 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
private void updatePackets(boolean navigating) { private void updatePackets(boolean navigating) {
if (updateCounter++ <= Setting.PACKET_UPDATE_DELAY.asInt()) updateCounter++;
boolean itemChanged = false;
for (int slot = 0; slot < this.inventory.armor.length; slot++) {
ItemStack equipment = getEquipment(slot);
if (!ItemStack.equals(equipmentCache.get(slot), equipment)) {
itemChanged = true;
}
equipmentCache.put(slot, equipment);
}
if (updateCounter++ <= Setting.PACKET_UPDATE_DELAY.asInt() && !itemChanged)
return; return;
updateCounter = 0; updateCounter = 0;
Location current = getBukkitEntity().getLocation(packetLocationCache); Location current = getBukkitEntity().getLocation(packetLocationCache);