fancynpcs: Wrap packets in Npc#update method in bundle packet (1.12.9+)

This commit is contained in:
Oliver
2025-11-21 21:10:48 +01:00
parent da7bc075aa
commit d6dc456f2a
3 changed files with 21 additions and 13 deletions

View File

@@ -1 +1 @@
2.8.0.311 2.8.0.312

View File

@@ -231,6 +231,8 @@ public class Npc_1_21_11 extends Npc {
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
List<Packet<? super ClientGamePacketListener>> packets = new ArrayList<>();
PlayerTeam team = new PlayerTeam(new Scoreboard(), "npc-" + localName); PlayerTeam team = new PlayerTeam(new Scoreboard(), "npc-" + localName);
team.getPlayers().clear(); team.getPlayers().clear();
team.getPlayers().add(npc instanceof ServerPlayer npcPlayer ? npcPlayer.getGameProfile().name() : npc.getStringUUID()); team.getPlayers().add(npc instanceof ServerPlayer npcPlayer ? npcPlayer.getGameProfile().name() : npc.getStringUUID());
@@ -268,11 +270,11 @@ public class Npc_1_21_11 extends Npc {
} }
ClientboundPlayerInfoUpdatePacket playerInfoPacket = new ClientboundPlayerInfoUpdatePacket(actions, getEntry(npcPlayer, serverPlayer)); ClientboundPlayerInfoUpdatePacket playerInfoPacket = new ClientboundPlayerInfoUpdatePacket(actions, getEntry(npcPlayer, serverPlayer));
serverPlayer.connection.send(playerInfoPacket); packets.add(playerInfoPacket);
} }
boolean isTeamCreatedForPlayer = this.isTeamCreated.getOrDefault(player.getUniqueId(), false); boolean isTeamCreatedForPlayer = this.isTeamCreated.getOrDefault(player.getUniqueId(), false);
serverPlayer.connection.send(ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(team, !isTeamCreatedForPlayer)); packets.add(ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(team, !isTeamCreatedForPlayer));
isTeamCreated.put(player.getUniqueId(), true); isTeamCreated.put(player.getUniqueId(), true);
npc.setGlowingTag(data.isGlowing()); npc.setGlowingTag(data.isGlowing());
@@ -297,7 +299,7 @@ public class Npc_1_21_11 extends Npc {
if (!equipmentList.isEmpty()) { if (!equipmentList.isEmpty()) {
ClientboundSetEquipmentPacket setEquipmentPacket = new ClientboundSetEquipmentPacket(npc.getId(), equipmentList); ClientboundSetEquipmentPacket setEquipmentPacket = new ClientboundSetEquipmentPacket(npc.getId(), equipmentList);
serverPlayer.connection.send(setEquipmentPacket); packets.add(setEquipmentPacket);
} }
if (npc instanceof ServerPlayer) { if (npc instanceof ServerPlayer) {
@@ -320,7 +322,7 @@ public class Npc_1_21_11 extends Npc {
} else { } else {
if (sittingVehicle != null) { if (sittingVehicle != null) {
ClientboundRemoveEntitiesPacket removeSittingVehiclePacket = new ClientboundRemoveEntitiesPacket(sittingVehicle.getId()); ClientboundRemoveEntitiesPacket removeSittingVehiclePacket = new ClientboundRemoveEntitiesPacket(sittingVehicle.getId());
serverPlayer.connection.send(removeSittingVehiclePacket); packets.add(removeSittingVehiclePacket);
} }
} }
@@ -333,9 +335,11 @@ public class Npc_1_21_11 extends Npc {
attributeInstance.setBaseValue(data.getScale()); attributeInstance.setBaseValue(data.getScale());
ClientboundUpdateAttributesPacket updateAttributesPacket = new ClientboundUpdateAttributesPacket(npc.getId(), List.of(attributeInstance)); ClientboundUpdateAttributesPacket updateAttributesPacket = new ClientboundUpdateAttributesPacket(npc.getId(), List.of(attributeInstance));
serverPlayer.connection.send(updateAttributesPacket); packets.add(updateAttributesPacket);
} }
ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(packets);
serverPlayer.connection.send(bundlePacket);
} }
@Override @Override

View File

@@ -231,6 +231,8 @@ public class Npc_1_21_9 extends Npc {
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
List<Packet<? super ClientGamePacketListener>> packets = new ArrayList<>();
PlayerTeam team = new PlayerTeam(new Scoreboard(), "npc-" + localName); PlayerTeam team = new PlayerTeam(new Scoreboard(), "npc-" + localName);
team.getPlayers().clear(); team.getPlayers().clear();
team.getPlayers().add(npc instanceof ServerPlayer npcPlayer ? npcPlayer.getGameProfile().name() : npc.getStringUUID()); team.getPlayers().add(npc instanceof ServerPlayer npcPlayer ? npcPlayer.getGameProfile().name() : npc.getStringUUID());
@@ -268,11 +270,11 @@ public class Npc_1_21_9 extends Npc {
} }
ClientboundPlayerInfoUpdatePacket playerInfoPacket = new ClientboundPlayerInfoUpdatePacket(actions, getEntry(npcPlayer, serverPlayer)); ClientboundPlayerInfoUpdatePacket playerInfoPacket = new ClientboundPlayerInfoUpdatePacket(actions, getEntry(npcPlayer, serverPlayer));
serverPlayer.connection.send(playerInfoPacket); packets.add(playerInfoPacket);
} }
boolean isTeamCreatedForPlayer = this.isTeamCreated.getOrDefault(player.getUniqueId(), false); boolean isTeamCreatedForPlayer = this.isTeamCreated.getOrDefault(player.getUniqueId(), false);
serverPlayer.connection.send(ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(team, !isTeamCreatedForPlayer)); packets.add(ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(team, !isTeamCreatedForPlayer));
isTeamCreated.put(player.getUniqueId(), true); isTeamCreated.put(player.getUniqueId(), true);
npc.setGlowingTag(data.isGlowing()); npc.setGlowingTag(data.isGlowing());
@@ -297,7 +299,7 @@ public class Npc_1_21_9 extends Npc {
if (!equipmentList.isEmpty()) { if (!equipmentList.isEmpty()) {
ClientboundSetEquipmentPacket setEquipmentPacket = new ClientboundSetEquipmentPacket(npc.getId(), equipmentList); ClientboundSetEquipmentPacket setEquipmentPacket = new ClientboundSetEquipmentPacket(npc.getId(), equipmentList);
serverPlayer.connection.send(setEquipmentPacket); packets.add(setEquipmentPacket);
} }
if (npc instanceof ServerPlayer) { if (npc instanceof ServerPlayer) {
@@ -320,7 +322,7 @@ public class Npc_1_21_9 extends Npc {
} else { } else {
if (sittingVehicle != null) { if (sittingVehicle != null) {
ClientboundRemoveEntitiesPacket removeSittingVehiclePacket = new ClientboundRemoveEntitiesPacket(sittingVehicle.getId()); ClientboundRemoveEntitiesPacket removeSittingVehiclePacket = new ClientboundRemoveEntitiesPacket(sittingVehicle.getId());
serverPlayer.connection.send(removeSittingVehiclePacket); packets.add(removeSittingVehiclePacket);
} }
} }
@@ -333,9 +335,11 @@ public class Npc_1_21_9 extends Npc {
attributeInstance.setBaseValue(data.getScale()); attributeInstance.setBaseValue(data.getScale());
ClientboundUpdateAttributesPacket updateAttributesPacket = new ClientboundUpdateAttributesPacket(npc.getId(), List.of(attributeInstance)); ClientboundUpdateAttributesPacket updateAttributesPacket = new ClientboundUpdateAttributesPacket(npc.getId(), List.of(attributeInstance));
serverPlayer.connection.send(updateAttributesPacket); packets.add(updateAttributesPacket);
} }
ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(packets);
serverPlayer.connection.send(bundlePacket);
} }
@Override @Override