diff --git a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java index 634505689..2d1e45d4d 100644 --- a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java +++ b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java @@ -168,14 +168,14 @@ public class CitizensNPC extends AbstractNPC { } private void resetCachedCoord() { - if (cachedCoord != null) { - CHUNK_LOADERS.remove(NPC_METADATA_MARKER, CHUNK_LOADERS); - CHUNK_LOADERS.remove(cachedCoord, this); - if (CHUNK_LOADERS.get(cachedCoord).size() == 0) { - cachedCoord.setForceLoaded(false); - } - cachedCoord = null; + if (cachedCoord == null) + return; + CHUNK_LOADERS.remove(NPC_METADATA_MARKER, CHUNK_LOADERS); + CHUNK_LOADERS.remove(cachedCoord, this); + if (CHUNK_LOADERS.get(cachedCoord).size() == 0) { + cachedCoord.setForceLoaded(false); } + cachedCoord = null; } @Override @@ -344,7 +344,8 @@ public class CitizensNPC extends AbstractNPC { } } - if (!getNavigator().isNavigating() && updateCounter++ > Setting.PACKET_UPDATE_DELAY.asInt()) { + boolean isLiving = getEntity() instanceof LivingEntity; + if (updateCounter++ > Setting.PACKET_UPDATE_DELAY.asInt()) { if (Setting.KEEP_CHUNKS_LOADED.asBoolean()) { ChunkCoord currentCoord = new ChunkCoord(getStoredLocation()); if (!currentCoord.equals(cachedCoord)) { @@ -354,24 +355,18 @@ public class CitizensNPC extends AbstractNPC { cachedCoord = currentCoord; } } - updateCounter = 0; - - Player player = getEntity().getType() == EntityType.PLAYER ? (Player) getEntity() : null; - NMS.sendPositionUpdate(player, getEntity(), getStoredLocation()); - } - - if (getEntity() instanceof LivingEntity) { - if (updateCounter == 0) { + if (isLiving) { updateCustomName(); } + updateCounter = 0; + } + + if (isLiving) { String nameplateVisible = data(). get(NPC.NAMEPLATE_VISIBLE_METADATA, true).toString(); ((LivingEntity) getEntity()).setCustomNameVisible(Boolean.parseBoolean(nameplateVisible)); - if (data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) { - NMS.setKnockbackResistance((LivingEntity) getEntity(), 1D); - } else { - NMS.setKnockbackResistance((LivingEntity) getEntity(), 0D); - } + NMS.setKnockbackResistance((LivingEntity) getEntity(), + data().get(NPC.DEFAULT_PROTECTED_METADATA, true) ? 1D : 0D); } if (SUPPORT_SILENT && data().has(NPC.SILENT_METADATA)) { diff --git a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/entity/EntityHumanNPC.java b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/entity/EntityHumanNPC.java index 87e4451c8..a1cf26699 100644 --- a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/entity/EntityHumanNPC.java +++ b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/entity/EntityHumanNPC.java @@ -51,13 +51,11 @@ import net.minecraft.server.v1_10_R1.EnumItemSlot; import net.minecraft.server.v1_10_R1.EnumProtocolDirection; import net.minecraft.server.v1_10_R1.GenericAttributes; import net.minecraft.server.v1_10_R1.IBlockData; -import net.minecraft.server.v1_10_R1.MathHelper; import net.minecraft.server.v1_10_R1.MinecraftServer; import net.minecraft.server.v1_10_R1.NavigationAbstract; import net.minecraft.server.v1_10_R1.NetworkManager; import net.minecraft.server.v1_10_R1.Packet; import net.minecraft.server.v1_10_R1.PacketPlayOutEntityEquipment; -import net.minecraft.server.v1_10_R1.PacketPlayOutEntityHeadRotation; import net.minecraft.server.v1_10_R1.PathType; import net.minecraft.server.v1_10_R1.PlayerInteractManager; import net.minecraft.server.v1_10_R1.WorldServer; @@ -415,11 +413,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable return; updateCounter = 0; Location current = getBukkitEntity().getLocation(packetLocationCache); - Packet[] packets = new Packet[navigating ? EnumItemSlot.values().length : EnumItemSlot.values().length + 1]; - if (!navigating) { - packets[5] = new PacketPlayOutEntityHeadRotation(this, - (byte) MathHelper.d(NMSImpl.getHeadYaw(this) * 256.0F / 360.0F)); - } + Packet[] packets = new Packet[EnumItemSlot.values().length]; int i = 0; for (EnumItemSlot slot : EnumItemSlot.values()) { packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot)); diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/EntityHumanNPC.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/EntityHumanNPC.java index b7970d1e6..52ebb37b6 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/EntityHumanNPC.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/EntityHumanNPC.java @@ -53,13 +53,11 @@ import net.minecraft.server.v1_11_R1.EnumProtocolDirection; import net.minecraft.server.v1_11_R1.GenericAttributes; import net.minecraft.server.v1_11_R1.IBlockData; import net.minecraft.server.v1_11_R1.IChatBaseComponent; -import net.minecraft.server.v1_11_R1.MathHelper; import net.minecraft.server.v1_11_R1.MinecraftServer; import net.minecraft.server.v1_11_R1.NavigationAbstract; import net.minecraft.server.v1_11_R1.NetworkManager; import net.minecraft.server.v1_11_R1.Packet; import net.minecraft.server.v1_11_R1.PacketPlayOutEntityEquipment; -import net.minecraft.server.v1_11_R1.PacketPlayOutEntityHeadRotation; import net.minecraft.server.v1_11_R1.PathType; import net.minecraft.server.v1_11_R1.PlayerInteractManager; import net.minecraft.server.v1_11_R1.WorldServer; @@ -427,11 +425,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable updateCounter = 0; Location current = getBukkitEntity().getLocation(packetLocationCache); - Packet[] packets = new Packet[navigating ? EnumItemSlot.values().length : EnumItemSlot.values().length + 1]; - if (!navigating) { - packets[5] = new PacketPlayOutEntityHeadRotation(this, - (byte) MathHelper.d(NMSImpl.getHeadYaw(this) * 256.0F / 360.0F)); - } + Packet[] packets = new Packet[EnumItemSlot.values().length]; int i = 0; for (EnumItemSlot slot : EnumItemSlot.values()) { packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot)); diff --git a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/entity/EntityHumanNPC.java b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/entity/EntityHumanNPC.java index 3f89f2377..cac5b8115 100644 --- a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/entity/EntityHumanNPC.java +++ b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/entity/EntityHumanNPC.java @@ -55,13 +55,11 @@ import net.minecraft.server.v1_12_R1.EnumProtocolDirection; import net.minecraft.server.v1_12_R1.GenericAttributes; import net.minecraft.server.v1_12_R1.IBlockData; import net.minecraft.server.v1_12_R1.IChatBaseComponent; -import net.minecraft.server.v1_12_R1.MathHelper; import net.minecraft.server.v1_12_R1.MinecraftServer; import net.minecraft.server.v1_12_R1.NavigationAbstract; import net.minecraft.server.v1_12_R1.NetworkManager; import net.minecraft.server.v1_12_R1.Packet; import net.minecraft.server.v1_12_R1.PacketPlayOutEntityEquipment; -import net.minecraft.server.v1_12_R1.PacketPlayOutEntityHeadRotation; import net.minecraft.server.v1_12_R1.PathType; import net.minecraft.server.v1_12_R1.PlayerInteractManager; import net.minecraft.server.v1_12_R1.WorldServer; @@ -444,11 +442,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable updateCounter = 0; Location current = getBukkitEntity().getLocation(packetLocationCache); - Packet[] packets = new Packet[navigating ? EnumItemSlot.values().length : EnumItemSlot.values().length + 1]; - if (!navigating) { - packets[5] = new PacketPlayOutEntityHeadRotation(this, - (byte) MathHelper.d(NMSImpl.getHeadYaw(this) * 256.0F / 360.0F)); - } + Packet[] packets = new Packet[EnumItemSlot.values().length]; int i = 0; for (EnumItemSlot slot : EnumItemSlot.values()) { packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot)); diff --git a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/EntityHumanNPC.java b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/EntityHumanNPC.java index b53dcc9b2..4958a3574 100644 --- a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/EntityHumanNPC.java +++ b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/EntityHumanNPC.java @@ -55,13 +55,11 @@ import net.minecraft.server.v1_13_R2.EnumProtocolDirection; import net.minecraft.server.v1_13_R2.GenericAttributes; import net.minecraft.server.v1_13_R2.IBlockData; import net.minecraft.server.v1_13_R2.IChatBaseComponent; -import net.minecraft.server.v1_13_R2.MathHelper; import net.minecraft.server.v1_13_R2.MinecraftServer; import net.minecraft.server.v1_13_R2.NavigationAbstract; import net.minecraft.server.v1_13_R2.NetworkManager; import net.minecraft.server.v1_13_R2.Packet; import net.minecraft.server.v1_13_R2.PacketPlayOutEntityEquipment; -import net.minecraft.server.v1_13_R2.PacketPlayOutEntityHeadRotation; import net.minecraft.server.v1_13_R2.PathType; import net.minecraft.server.v1_13_R2.PlayerInteractManager; import net.minecraft.server.v1_13_R2.WorldServer; @@ -435,11 +433,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable updateCounter = 0; Location current = getBukkitEntity().getLocation(packetLocationCache); - Packet[] packets = new Packet[navigating ? EnumItemSlot.values().length : EnumItemSlot.values().length + 1]; - if (!navigating) { - packets[5] = new PacketPlayOutEntityHeadRotation(this, - (byte) MathHelper.d(NMSImpl.getHeadYaw(this) * 256.0F / 360.0F)); - } + Packet[] packets = new Packet[EnumItemSlot.values().length]; int i = 0; for (EnumItemSlot slot : EnumItemSlot.values()) { packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot)); diff --git a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/EntityHumanNPC.java b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/EntityHumanNPC.java index ef2039eef..4cba1fd9f 100644 --- a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/EntityHumanNPC.java +++ b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/EntityHumanNPC.java @@ -54,13 +54,11 @@ import net.minecraft.server.v1_14_R1.EnumProtocolDirection; import net.minecraft.server.v1_14_R1.GenericAttributes; import net.minecraft.server.v1_14_R1.IBlockData; import net.minecraft.server.v1_14_R1.IChatBaseComponent; -import net.minecraft.server.v1_14_R1.MathHelper; import net.minecraft.server.v1_14_R1.MinecraftServer; import net.minecraft.server.v1_14_R1.NavigationAbstract; import net.minecraft.server.v1_14_R1.NetworkManager; import net.minecraft.server.v1_14_R1.Packet; import net.minecraft.server.v1_14_R1.PacketPlayOutEntityEquipment; -import net.minecraft.server.v1_14_R1.PacketPlayOutEntityHeadRotation; import net.minecraft.server.v1_14_R1.PathType; import net.minecraft.server.v1_14_R1.PlayerInteractManager; import net.minecraft.server.v1_14_R1.Vec3D; @@ -440,11 +438,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable updateCounter = 0; Location current = getBukkitEntity().getLocation(packetLocationCache); - Packet[] packets = new Packet[navigating ? EnumItemSlot.values().length : EnumItemSlot.values().length + 1]; - if (!navigating) { - packets[5] = new PacketPlayOutEntityHeadRotation(this, - (byte) MathHelper.d(NMSImpl.getHeadYaw(this) * 256.0F / 360.0F)); - } + Packet[] packets = new Packet[EnumItemSlot.values().length]; int i = 0; for (EnumItemSlot slot : EnumItemSlot.values()) { packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot)); diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/EntityHumanNPC.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/EntityHumanNPC.java index 513550373..784329f0f 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/EntityHumanNPC.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/EntityHumanNPC.java @@ -54,13 +54,11 @@ import net.minecraft.server.v1_15_R1.EnumProtocolDirection; import net.minecraft.server.v1_15_R1.GenericAttributes; import net.minecraft.server.v1_15_R1.IBlockData; import net.minecraft.server.v1_15_R1.IChatBaseComponent; -import net.minecraft.server.v1_15_R1.MathHelper; import net.minecraft.server.v1_15_R1.MinecraftServer; import net.minecraft.server.v1_15_R1.NavigationAbstract; import net.minecraft.server.v1_15_R1.NetworkManager; import net.minecraft.server.v1_15_R1.Packet; import net.minecraft.server.v1_15_R1.PacketPlayOutEntityEquipment; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntityHeadRotation; import net.minecraft.server.v1_15_R1.PathType; import net.minecraft.server.v1_15_R1.PlayerInteractManager; import net.minecraft.server.v1_15_R1.Vec3D; @@ -450,11 +448,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable updateCounter = 0; Location current = getBukkitEntity().getLocation(packetLocationCache); - Packet[] packets = new Packet[navigating ? EnumItemSlot.values().length : EnumItemSlot.values().length + 1]; - if (!navigating) { - packets[5] = new PacketPlayOutEntityHeadRotation(this, - (byte) MathHelper.d(NMSImpl.getHeadYaw(this) * 256.0F / 360.0F)); - } + Packet[] packets = new Packet[EnumItemSlot.values().length]; int i = 0; for (EnumItemSlot slot : EnumItemSlot.values()) { packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot)); diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EntityHumanNPC.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EntityHumanNPC.java index 9ab9ee6c4..5b199947e 100644 --- a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EntityHumanNPC.java +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EntityHumanNPC.java @@ -46,13 +46,11 @@ import net.minecraft.server.v1_8_R3.Entity; import net.minecraft.server.v1_8_R3.EntityPlayer; import net.minecraft.server.v1_8_R3.EnumProtocolDirection; import net.minecraft.server.v1_8_R3.GenericAttributes; -import net.minecraft.server.v1_8_R3.MathHelper; import net.minecraft.server.v1_8_R3.MinecraftServer; import net.minecraft.server.v1_8_R3.NavigationAbstract; import net.minecraft.server.v1_8_R3.NetworkManager; import net.minecraft.server.v1_8_R3.Packet; import net.minecraft.server.v1_8_R3.PacketPlayOutEntityEquipment; -import net.minecraft.server.v1_8_R3.PacketPlayOutEntityHeadRotation; import net.minecraft.server.v1_8_R3.PlayerInteractManager; import net.minecraft.server.v1_8_R3.WorldServer; import net.minecraft.server.v1_8_R3.WorldSettings; @@ -404,11 +402,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable return; updateCounter = 0; Location current = getBukkitEntity().getLocation(packetLocationCache); - Packet[] packets = new Packet[navigating ? this.inventory.armor.length : this.inventory.armor.length + 1]; - if (!navigating) { - packets[this.inventory.armor.length] = new PacketPlayOutEntityHeadRotation(this, - (byte) MathHelper.d(NMSImpl.getHeadYaw(this) * 256.0F / 360.0F)); - } + Packet[] packets = new Packet[this.inventory.armor.length]; for (int i = 0; i < this.inventory.armor.length; i++) { packets[i] = new PacketPlayOutEntityEquipment(getId(), i, getEquipment(i)); }