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

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