From 191e94df0f8651470124825e6a4fc0754a1b669b Mon Sep 17 00:00:00 2001 From: zimzaza4 <3625282098@qq.com> Date: Sun, 7 Jul 2024 04:14:06 +0800 Subject: [PATCH] fix --- .../geysermodelengine/model/EntityTask.java | 24 ++++++++----------- .../packet/EntityMetadataPacket.java | 22 +++++++++++++++++ .../packet/EntityTeleportPacket.java | 2 ++ .../packet/entity/PacketEntity.java | 19 +++++++-------- src/main/resources/config.yml | 2 +- 5 files changed, 44 insertions(+), 25 deletions(-) create mode 100644 src/main/java/re/imc/geysermodelengine/packet/EntityMetadataPacket.java diff --git a/src/main/java/re/imc/geysermodelengine/model/EntityTask.java b/src/main/java/re/imc/geysermodelengine/model/EntityTask.java index aa8f5c0..6ac8e44 100644 --- a/src/main/java/re/imc/geysermodelengine/model/EntityTask.java +++ b/src/main/java/re/imc/geysermodelengine/model/EntityTask.java @@ -110,7 +110,7 @@ public class EntityTask { spawnAnimationPlayed = true; } - if (tick > 1 && tick % 5 == 0) { + if (tick % 5 == 0) { for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { if (FloodgateApi.getInstance().isFloodgatePlayer(onlinePlayer.getUniqueId())) { @@ -134,9 +134,10 @@ public class EntityTask { */ } } else { - - entity.sendEntityDestroyPacket(Collections.singletonList(onlinePlayer)); - viewers.remove(onlinePlayer); + if (viewers.contains(onlinePlayer)) { + entity.sendEntityDestroyPacket(Collections.singletonList(onlinePlayer)); + viewers.remove(onlinePlayer); + } } } } @@ -212,18 +213,16 @@ public class EntityTask { } public void sendEntityData(Player player, int delay) { - // System.out.println("TYPE: " + "modelengine:" + model.getActiveModel().getBlueprint().getName().toLowerCase()); PlayerUtils.setCustomEntity(player, model.getEntity().getEntityId(), "modelengine:" + model.getActiveModel().getBlueprint().getName().toLowerCase()); - model.getEntity().sendSpawnPacket(Collections.singletonList(player)); Bukkit.getScheduler().runTaskLaterAsynchronously(GeyserModelEngine.getInstance(), () -> { // PlayerUtils.sendCustomSkin(player, model.getEntity(), model.getActiveModel().getBlueprint().getName()); - if (looping) { - playBedrockAnimation(lastAnimation, Set.of(player), looping, 0f); - } - sendHitBox(player); - sendScale(player, true); + model.getEntity().sendSpawnPacket(Collections.singletonList(player)); + Bukkit.getScheduler().runTaskLaterAsynchronously(GeyserModelEngine.getInstance(), () -> { + if (looping) { + playBedrockAnimation(lastAnimation, Set.of(player), looping, 0f); + } sendHitBox(player); sendScale(player, true); updateVisibility(player, true); @@ -411,9 +410,6 @@ public class EntityTask { if (player.isDead()) { return false; } - if (player.getWorld() != entity.getWorld()) { - return false; - } if (GeyserModelEngine.getInstance().getJoinedPlayer() != null && GeyserModelEngine.getInstance().getJoinedPlayer().getIfPresent(player) != null) { return false; } diff --git a/src/main/java/re/imc/geysermodelengine/packet/EntityMetadataPacket.java b/src/main/java/re/imc/geysermodelengine/packet/EntityMetadataPacket.java new file mode 100644 index 0000000..edc32d6 --- /dev/null +++ b/src/main/java/re/imc/geysermodelengine/packet/EntityMetadataPacket.java @@ -0,0 +1,22 @@ +package re.imc.geysermodelengine.packet; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.WrappedDataWatcher; + +public class EntityMetadataPacket implements WrapperPacket { + private final int id; + + public EntityMetadataPacket(int id) { + this.id = id; + } + + @Override + public PacketContainer encode() { + PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); + packet.getIntegers().write(0, id); + WrappedDataWatcher watcher = new WrappedDataWatcher(); + packet.getWatchableCollectionModifier().writeSafely(0, watcher.getWatchableObjects()); + return packet; + } +} diff --git a/src/main/java/re/imc/geysermodelengine/packet/EntityTeleportPacket.java b/src/main/java/re/imc/geysermodelengine/packet/EntityTeleportPacket.java index 439bbf7..9dbd221 100644 --- a/src/main/java/re/imc/geysermodelengine/packet/EntityTeleportPacket.java +++ b/src/main/java/re/imc/geysermodelengine/packet/EntityTeleportPacket.java @@ -20,6 +20,8 @@ public class EntityTeleportPacket implements WrapperPacket { packet.getDoubles().write(0, loc.getX()); packet.getDoubles().write(1, loc.getY()); packet.getDoubles().write(2, loc.getZ()); + packet.getBytes().write(1, (byte) (loc.getPitch() * 256.0F / 360.0F)); + packet.getBytes().write(0, (byte) (loc.getYaw() * 256.0F / 360.0F)); return packet; } } diff --git a/src/main/java/re/imc/geysermodelengine/packet/entity/PacketEntity.java b/src/main/java/re/imc/geysermodelengine/packet/entity/PacketEntity.java index cac56d8..c355ecd 100644 --- a/src/main/java/re/imc/geysermodelengine/packet/entity/PacketEntity.java +++ b/src/main/java/re/imc/geysermodelengine/packet/entity/PacketEntity.java @@ -21,10 +21,7 @@ import org.bukkit.util.BoundingBox; import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import re.imc.geysermodelengine.packet.EntityDestroyPacket; -import re.imc.geysermodelengine.packet.EntityHurtAnimationPacket; -import re.imc.geysermodelengine.packet.EntitySpawnPacket; -import re.imc.geysermodelengine.packet.EntityTeleportPacket; +import re.imc.geysermodelengine.packet.*; import java.util.*; import java.util.concurrent.CompletableFuture; @@ -52,7 +49,7 @@ public class PacketEntity implements Entity { @Override public boolean teleport(@NotNull Location location) { - this.location = location; + this.location = location.clone(); sendLocationPacket(viewers); return true; } @@ -77,7 +74,9 @@ public class PacketEntity implements Entity { public void sendSpawnPacket(Collection players) { EntitySpawnPacket packet = new EntitySpawnPacket(id, uuid, type, location); + EntityMetadataPacket metadataPacket = new EntityMetadataPacket(id); players.forEach(player -> ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet.encode())); + players.forEach(player -> ProtocolLibrary.getProtocolManager().sendServerPacket(player, metadataPacket.encode())); } public void sendLocationPacket(Collection players) { EntityTeleportPacket packet = new EntityTeleportPacket(id, location); @@ -88,13 +87,16 @@ public class PacketEntity implements Entity { public void sendHurtPacket(Collection players) { EntityHurtAnimationPacket packet = new EntityHurtAnimationPacket(id); players.forEach(player -> ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet.encode())); - } public void sendEntityDestroyPacket(Collection players) { EntityDestroyPacket packet = new EntityDestroyPacket(id); players.forEach(player -> ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet.encode())); + } + @Override + public int getEntityId() { + return id; } // ---------------- @@ -181,10 +183,7 @@ public class PacketEntity implements Entity { return null; } - @Override - public int getEntityId() { - return 0; - } + @Override public int getFireTicks() { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index fc71979..bf38848 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,4 +1,4 @@ -data-send-delay: 0 +data-send-delay: 5 entity-view-distance: 50 join-send-delay: 20 model-entity-type: BAT # must be a living entity