From 27c83150345907903c22e2397221a7faec80c083 Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Thu, 3 Apr 2025 06:52:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?perf(bukkit):=20=E4=BC=98=E5=8C=96=E6=96=B9?= =?UTF-8?q?=E5=9D=97=E7=8A=B6=E6=80=81=E6=98=A0=E5=B0=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bukkit/plugin/network/PacketConsumers.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java index 424b361e6..0b2d8cdb9 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java @@ -61,6 +61,11 @@ public class PacketConsumers { mappingsMOD[entry.getKey()] = entry.getValue(); } } + for (int i = 0; i < mappingsMOD.length; i++) { + if (BlockStateUtils.isVanillaBlock(i)) { + mappingsMOD[i] = remap(i); + } + } BLOCK_LIST = new IntIdentityList(registrySize); BIOME_LIST = new IntIdentityList(RegistryUtils.currentBiomeRegistrySize()); } @@ -70,8 +75,7 @@ public class PacketConsumers { } public static int remapMOD(int stateId) { - int modStateId = mappingsMOD[stateId]; - return BlockStateUtils.isVanillaBlock(modStateId) ? remap(modStateId) : modStateId; + return mappingsMOD[stateId]; } public static final TriConsumer LEVEL_CHUNK_WITH_LIGHT = (user, event, packet) -> { From db9d7516b67357bcfaefb3aa95cfe43591e420ab Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Thu, 3 Apr 2025 07:25:39 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(entity):=20=E4=BF=AE=E5=A4=8D=20shulker?= =?UTF-8?q?=20=E4=B8=8D=E5=BC=80=E5=A3=B3=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/furniture/hitbox/ShulkerHitBox.java | 17 ++++++++++++++--- .../craftengine/bukkit/util/Reflections.java | 6 ++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerHitBox.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerHitBox.java index f4d61ad0d..583bdef6b 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerHitBox.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerHitBox.java @@ -36,7 +36,7 @@ public class ShulkerHitBox extends AbstractHitBox { ShulkerData.Peek.addEntityDataIfNotDefaultValue(peek, this.cachedShulkerValues); ShulkerData.Color.addEntityDataIfNotDefaultValue((byte) 0, this.cachedShulkerValues); -// ShulkerData.AttachFace.addEntityDataIfNotDefaultValue(DirectionUtils.toNMSDirection(direction), this.cachedShulkerValues); + // ShulkerData.AttachFace.addEntityDataIfNotDefaultValue(DirectionUtils.toNMSDirection(direction), this.cachedShulkerValues); ShulkerData.NoGravity.addEntityDataIfNotDefaultValue(true, this.cachedShulkerValues); ShulkerData.Silent.addEntityDataIfNotDefaultValue(true, this.cachedShulkerValues); ShulkerData.MobFlags.addEntityDataIfNotDefaultValue((byte) 0x01, this.cachedShulkerValues); // 无ai @@ -119,16 +119,27 @@ public class ShulkerHitBox extends AbstractHitBox { public void addSpawnPackets(int[] entityIds, double x, double y, double z, float yaw, Quaternionf conjugated, BiConsumer packets) { Vector3f offset = conjugated.transform(new Vector3f(position())); try { + double originalY = y + offset.y; + double integerPart = Math.floor(originalY); + double fractionalPart = originalY - integerPart; + double processedY = (fractionalPart >= 0.5) ? integerPart + 1 : originalY; packets.accept(Reflections.constructor$ClientboundAddEntityPacket.newInstance( - entityIds[0], UUID.randomUUID(), x + offset.x, y + offset.y, z - offset.z, 0, yaw, + entityIds[0], UUID.randomUUID(), x + offset.x, originalY, z - offset.z, 0, yaw, Reflections.instance$EntityType$ITEM_DISPLAY, 0, Reflections.instance$Vec3$Zero, 0 ), false); packets.accept(Reflections.constructor$ClientboundAddEntityPacket.newInstance( - entityIds[1], UUID.randomUUID(), x + offset.x, y + offset.y, z - offset.z, 0, yaw, + entityIds[1], UUID.randomUUID(), x + offset.x, processedY, z - offset.z, 0, yaw, Reflections.instance$EntityType$SHULKER, 0, Reflections.instance$Vec3$Zero, 0 ), false); packets.accept(Reflections.constructor$ClientboundSetEntityDataPacket.newInstance(entityIds[1], List.copyOf(this.cachedShulkerValues)), false); packets.accept(FastNMS.INSTANCE.constructor$ClientboundSetPassengersPacket(entityIds[0], entityIds[1]), false); + if (originalY != processedY) { + double deltaY = originalY - processedY; + short ya = (short) (deltaY * 8192); + packets.accept(Reflections.constructor$ClientboundMoveEntityPacket$Pos.newInstance( + entityIds[1], (short) 0, ya, (short) 0, true + ), false); + } if (VersionHelper.isVersionNewerThan1_20_5()) { Object attributeInstance = Reflections.constructor$AttributeInstance.newInstance(Reflections.instance$Holder$Attribute$scale, (Consumer) (o) -> {}); Reflections.method$AttributeInstance$setBaseValue.invoke(attributeInstance, scale); diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/Reflections.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/Reflections.java index 6932a75b8..3da93b0fd 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/Reflections.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/Reflections.java @@ -6050,4 +6050,10 @@ public class Reflections { clazz$BlockStateBase, clazz$BlockState, clazz$Mirror ) ); + + public static final Constructor constructor$ClientboundMoveEntityPacket$Pos = requireNonNull( + ReflectionUtils.getDeclaredConstructor( + clazz$ClientboundMoveEntityPacket$Pos, int.class, short.class, short.class, short.class, boolean.class + ) + ); }