fancynpcs: Try to fix npcs disappearing

This commit is contained in:
Oliver
2025-11-21 14:34:07 +01:00
parent d7c6f1bc81
commit 0a6aa9da80
9 changed files with 57 additions and 16 deletions

View File

@@ -1 +1 @@
2.8.0.310 2.8.0.311

View File

@@ -17,6 +17,7 @@ import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.RemoteChatSession; import net.minecraft.network.chat.RemoteChatSession;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.*; import net.minecraft.network.protocol.game.*;
import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@@ -106,6 +107,7 @@ public class Npc_1_20_6 extends Npc {
return; return;
} }
List<Packet<? super ClientGamePacketListener>> packets = new ArrayList<>();
if (npc instanceof ServerPlayer npcPlayer) { if (npc instanceof ServerPlayer npcPlayer) {
EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions = EnumSet.noneOf(ClientboundPlayerInfoUpdatePacket.Action.class); EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions = EnumSet.noneOf(ClientboundPlayerInfoUpdatePacket.Action.class);
@@ -116,7 +118,7 @@ public class Npc_1_20_6 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);
if (data.isSpawnEntity()) { if (data.isSpawnEntity()) {
npc.setPos(data.getLocation().x(), data.getLocation().y(), data.getLocation().z()); npc.setPos(data.getLocation().x(), data.getLocation().y(), data.getLocation().z());
@@ -136,6 +138,9 @@ public class Npc_1_20_6 extends Npc {
}, removeNpcsFromPlayerlistDelay, TimeUnit.MILLISECONDS); }, removeNpcsFromPlayerlistDelay, TimeUnit.MILLISECONDS);
} }
ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(packets);
serverPlayer.connection.send(bundlePacket);
update(player); update(player);
} }

View File

@@ -17,6 +17,7 @@ import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.RemoteChatSession; import net.minecraft.network.chat.RemoteChatSession;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.*; import net.minecraft.network.protocol.game.*;
import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@@ -105,6 +106,7 @@ public class Npc_1_21_1 extends Npc {
return; return;
} }
List<Packet<? super ClientGamePacketListener>> packets = new ArrayList<>();
if (npc instanceof ServerPlayer npcPlayer) { if (npc instanceof ServerPlayer npcPlayer) {
EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions = EnumSet.noneOf(ClientboundPlayerInfoUpdatePacket.Action.class); EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions = EnumSet.noneOf(ClientboundPlayerInfoUpdatePacket.Action.class);
@@ -115,7 +117,7 @@ public class Npc_1_21_1 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);
if (data.isSpawnEntity()) { if (data.isSpawnEntity()) {
npc.setPos(data.getLocation().x(), data.getLocation().y(), data.getLocation().z()); npc.setPos(data.getLocation().x(), data.getLocation().y(), data.getLocation().z());
@@ -135,7 +137,7 @@ public class Npc_1_21_1 extends Npc {
Vec3.ZERO, Vec3.ZERO,
data.getLocation().getYaw() data.getLocation().getYaw()
); );
serverPlayer.connection.send(addEntityPacket); packets.add(addEntityPacket);
isVisibleForPlayer.put(player.getUniqueId(), true); isVisibleForPlayer.put(player.getUniqueId(), true);
@@ -148,6 +150,9 @@ public class Npc_1_21_1 extends Npc {
}, removeNpcsFromPlayerlistDelay, TimeUnit.MILLISECONDS); }, removeNpcsFromPlayerlistDelay, TimeUnit.MILLISECONDS);
} }
ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(packets);
serverPlayer.connection.send(bundlePacket);
update(player); update(player);
} }

View File

@@ -19,6 +19,7 @@ import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.RemoteChatSession; import net.minecraft.network.chat.RemoteChatSession;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.*; import net.minecraft.network.protocol.game.*;
import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.Identifier; import net.minecraft.resources.Identifier;
@@ -111,6 +112,7 @@ public class Npc_1_21_11 extends Npc {
return; return;
} }
List<Packet<? super ClientGamePacketListener>> packets = new ArrayList<>();
if (npc instanceof ServerPlayer npcPlayer) { if (npc instanceof ServerPlayer npcPlayer) {
EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions = EnumSet.noneOf(ClientboundPlayerInfoUpdatePacket.Action.class); EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions = EnumSet.noneOf(ClientboundPlayerInfoUpdatePacket.Action.class);
@@ -121,7 +123,7 @@ 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);
if (data.isSpawnEntity()) { if (data.isSpawnEntity()) {
npc.setPos(data.getLocation().x(), data.getLocation().y(), data.getLocation().z()); npc.setPos(data.getLocation().x(), data.getLocation().y(), data.getLocation().z());
@@ -141,7 +143,7 @@ public class Npc_1_21_11 extends Npc {
Vec3.ZERO, Vec3.ZERO,
data.getLocation().getYaw() data.getLocation().getYaw()
); );
serverPlayer.connection.send(addEntityPacket); packets.add(addEntityPacket);
isVisibleForPlayer.put(player.getUniqueId(), true); isVisibleForPlayer.put(player.getUniqueId(), true);
@@ -154,6 +156,9 @@ public class Npc_1_21_11 extends Npc {
}, removeNpcsFromPlayerlistDelay, TimeUnit.MILLISECONDS); }, removeNpcsFromPlayerlistDelay, TimeUnit.MILLISECONDS);
} }
ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(packets);
serverPlayer.connection.send(bundlePacket);
update(player); update(player);
} }

View File

@@ -17,6 +17,7 @@ import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.RemoteChatSession; import net.minecraft.network.chat.RemoteChatSession;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.*; import net.minecraft.network.protocol.game.*;
import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@@ -106,6 +107,7 @@ public class Npc_1_21_3 extends Npc {
return; return;
} }
List<Packet<? super ClientGamePacketListener>> packets = new ArrayList<>();
if (npc instanceof ServerPlayer npcPlayer) { if (npc instanceof ServerPlayer npcPlayer) {
EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions = EnumSet.noneOf(ClientboundPlayerInfoUpdatePacket.Action.class); EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions = EnumSet.noneOf(ClientboundPlayerInfoUpdatePacket.Action.class);
@@ -116,7 +118,7 @@ public class Npc_1_21_3 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);
if (data.isSpawnEntity()) { if (data.isSpawnEntity()) {
npc.setPos(data.getLocation().x(), data.getLocation().y(), data.getLocation().z()); npc.setPos(data.getLocation().x(), data.getLocation().y(), data.getLocation().z());
@@ -136,7 +138,7 @@ public class Npc_1_21_3 extends Npc {
Vec3.ZERO, Vec3.ZERO,
data.getLocation().getYaw() data.getLocation().getYaw()
); );
serverPlayer.connection.send(addEntityPacket); packets.add(addEntityPacket);
isVisibleForPlayer.put(player.getUniqueId(), true); isVisibleForPlayer.put(player.getUniqueId(), true);
@@ -149,6 +151,9 @@ public class Npc_1_21_3 extends Npc {
}, removeNpcsFromPlayerlistDelay, TimeUnit.MILLISECONDS); }, removeNpcsFromPlayerlistDelay, TimeUnit.MILLISECONDS);
} }
ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(packets);
serverPlayer.connection.send(bundlePacket);
update(player); update(player);
} }

View File

@@ -17,6 +17,7 @@ import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.RemoteChatSession; import net.minecraft.network.chat.RemoteChatSession;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.*; import net.minecraft.network.protocol.game.*;
import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@@ -106,6 +107,7 @@ public class Npc_1_21_4 extends Npc {
return; return;
} }
List<Packet<? super ClientGamePacketListener>> packets = new ArrayList<>();
if (npc instanceof ServerPlayer npcPlayer) { if (npc instanceof ServerPlayer npcPlayer) {
EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions = EnumSet.noneOf(ClientboundPlayerInfoUpdatePacket.Action.class); EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions = EnumSet.noneOf(ClientboundPlayerInfoUpdatePacket.Action.class);
@@ -116,7 +118,7 @@ public class Npc_1_21_4 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);
if (data.isSpawnEntity()) { if (data.isSpawnEntity()) {
npc.setPos(data.getLocation().x(), data.getLocation().y(), data.getLocation().z()); npc.setPos(data.getLocation().x(), data.getLocation().y(), data.getLocation().z());
@@ -136,7 +138,7 @@ public class Npc_1_21_4 extends Npc {
Vec3.ZERO, Vec3.ZERO,
data.getLocation().getYaw() data.getLocation().getYaw()
); );
serverPlayer.connection.send(addEntityPacket); packets.add(addEntityPacket);
isVisibleForPlayer.put(player.getUniqueId(), true); isVisibleForPlayer.put(player.getUniqueId(), true);
@@ -149,6 +151,9 @@ public class Npc_1_21_4 extends Npc {
}, removeNpcsFromPlayerlistDelay, TimeUnit.MILLISECONDS); }, removeNpcsFromPlayerlistDelay, TimeUnit.MILLISECONDS);
} }
ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(packets);
serverPlayer.connection.send(bundlePacket);
update(player); update(player);
} }

View File

@@ -17,6 +17,7 @@ import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.RemoteChatSession; import net.minecraft.network.chat.RemoteChatSession;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.*; import net.minecraft.network.protocol.game.*;
import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@@ -106,6 +107,7 @@ public class Npc_1_21_5 extends Npc {
return; return;
} }
List<Packet<? super ClientGamePacketListener>> packets = new ArrayList<>();
if (npc instanceof ServerPlayer npcPlayer) { if (npc instanceof ServerPlayer npcPlayer) {
EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions = EnumSet.noneOf(ClientboundPlayerInfoUpdatePacket.Action.class); EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions = EnumSet.noneOf(ClientboundPlayerInfoUpdatePacket.Action.class);
@@ -116,7 +118,7 @@ public class Npc_1_21_5 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);
if (data.isSpawnEntity()) { if (data.isSpawnEntity()) {
npc.setPos(data.getLocation().x(), data.getLocation().y(), data.getLocation().z()); npc.setPos(data.getLocation().x(), data.getLocation().y(), data.getLocation().z());
@@ -136,7 +138,7 @@ public class Npc_1_21_5 extends Npc {
Vec3.ZERO, Vec3.ZERO,
data.getLocation().getYaw() data.getLocation().getYaw()
); );
serverPlayer.connection.send(addEntityPacket); packets.add(addEntityPacket);
isVisibleForPlayer.put(player.getUniqueId(), true); isVisibleForPlayer.put(player.getUniqueId(), true);
@@ -149,6 +151,9 @@ public class Npc_1_21_5 extends Npc {
}, removeNpcsFromPlayerlistDelay, TimeUnit.MILLISECONDS); }, removeNpcsFromPlayerlistDelay, TimeUnit.MILLISECONDS);
} }
ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(packets);
serverPlayer.connection.send(bundlePacket);
update(player); update(player);
} }
@@ -208,6 +213,7 @@ public class Npc_1_21_5 extends Npc {
ClientboundRotateHeadPacket rotateHeadPacket = new ClientboundRotateHeadPacket(npc, (byte) (location.getYaw() * angelMultiplier)); ClientboundRotateHeadPacket rotateHeadPacket = new ClientboundRotateHeadPacket(npc, (byte) (location.getYaw() * angelMultiplier));
serverPlayer.connection.send(rotateHeadPacket); serverPlayer.connection.send(rotateHeadPacket);
} }
@Override @Override
public void update(Player player, boolean swingArm) { public void update(Player player, boolean swingArm) {
if (npc == null) { if (npc == null) {

View File

@@ -17,6 +17,7 @@ import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.RemoteChatSession; import net.minecraft.network.chat.RemoteChatSession;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.*; import net.minecraft.network.protocol.game.*;
import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@@ -106,6 +107,7 @@ public class Npc_1_21_6 extends Npc {
return; return;
} }
List<Packet<? super ClientGamePacketListener>> packets = new ArrayList<>();
if (npc instanceof ServerPlayer npcPlayer) { if (npc instanceof ServerPlayer npcPlayer) {
EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions = EnumSet.noneOf(ClientboundPlayerInfoUpdatePacket.Action.class); EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions = EnumSet.noneOf(ClientboundPlayerInfoUpdatePacket.Action.class);
@@ -116,7 +118,7 @@ public class Npc_1_21_6 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);
if (data.isSpawnEntity()) { if (data.isSpawnEntity()) {
npc.setPos(data.getLocation().x(), data.getLocation().y(), data.getLocation().z()); npc.setPos(data.getLocation().x(), data.getLocation().y(), data.getLocation().z());
@@ -136,7 +138,7 @@ public class Npc_1_21_6 extends Npc {
Vec3.ZERO, Vec3.ZERO,
data.getLocation().getYaw() data.getLocation().getYaw()
); );
serverPlayer.connection.send(addEntityPacket); packets.add(addEntityPacket);
isVisibleForPlayer.put(player.getUniqueId(), true); isVisibleForPlayer.put(player.getUniqueId(), true);
@@ -149,6 +151,9 @@ public class Npc_1_21_6 extends Npc {
}, removeNpcsFromPlayerlistDelay, TimeUnit.MILLISECONDS); }, removeNpcsFromPlayerlistDelay, TimeUnit.MILLISECONDS);
} }
ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(packets);
serverPlayer.connection.send(bundlePacket);
update(player); update(player);
} }

View File

@@ -19,6 +19,7 @@ import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.RemoteChatSession; import net.minecraft.network.chat.RemoteChatSession;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.*; import net.minecraft.network.protocol.game.*;
import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@@ -111,6 +112,7 @@ public class Npc_1_21_9 extends Npc {
return; return;
} }
List<Packet<? super ClientGamePacketListener>> packets = new ArrayList<>();
if (npc instanceof ServerPlayer npcPlayer) { if (npc instanceof ServerPlayer npcPlayer) {
EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions = EnumSet.noneOf(ClientboundPlayerInfoUpdatePacket.Action.class); EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions = EnumSet.noneOf(ClientboundPlayerInfoUpdatePacket.Action.class);
@@ -121,7 +123,7 @@ 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);
if (data.isSpawnEntity()) { if (data.isSpawnEntity()) {
npc.setPos(data.getLocation().x(), data.getLocation().y(), data.getLocation().z()); npc.setPos(data.getLocation().x(), data.getLocation().y(), data.getLocation().z());
@@ -141,7 +143,7 @@ public class Npc_1_21_9 extends Npc {
Vec3.ZERO, Vec3.ZERO,
data.getLocation().getYaw() data.getLocation().getYaw()
); );
serverPlayer.connection.send(addEntityPacket); packets.add(addEntityPacket);
isVisibleForPlayer.put(player.getUniqueId(), true); isVisibleForPlayer.put(player.getUniqueId(), true);
@@ -154,6 +156,9 @@ public class Npc_1_21_9 extends Npc {
}, removeNpcsFromPlayerlistDelay, TimeUnit.MILLISECONDS); }, removeNpcsFromPlayerlistDelay, TimeUnit.MILLISECONDS);
} }
ClientboundBundlePacket bundlePacket = new ClientboundBundlePacket(packets);
serverPlayer.connection.send(bundlePacket);
update(player); update(player);
} }