From 8c23bf5bd4d7fea75d46d2946376ae58a47c6205 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 6 Jul 2025 11:58:54 +0200 Subject: [PATCH] Fix 1.21 DisplayEntities --- .../steamwar/entity/PacketConstructor21.java | 34 +++++++++++++++++++ .../de/steamwar/entity/PacketConstructor.java | 29 ++++++++++++++++ .../src/de/steamwar/entity/RBlockDisplay.java | 3 +- .../src/de/steamwar/entity/RDisplay.java | 31 +++++++++-------- .../src/de/steamwar/entity/REntity.java | 4 +++ .../src/de/steamwar/entity/RItemDisplay.java | 5 +-- .../src/de/steamwar/entity/RTextDisplay.java | 9 ++--- 7 files changed, 93 insertions(+), 22 deletions(-) create mode 100644 SpigotCore/SpigotCore_21/src/de/steamwar/entity/PacketConstructor21.java create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/entity/PacketConstructor.java diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/entity/PacketConstructor21.java b/SpigotCore/SpigotCore_21/src/de/steamwar/entity/PacketConstructor21.java new file mode 100644 index 00000000..67e501e4 --- /dev/null +++ b/SpigotCore/SpigotCore_21/src/de/steamwar/entity/PacketConstructor21.java @@ -0,0 +1,34 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.entity; + +import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; +import net.minecraft.world.entity.PositionMoveRotation; +import net.minecraft.world.phys.Vec3; + +import java.util.Collections; + +public class PacketConstructor21 implements PacketConstructor{ + @Override + public Object teleportPacket(int entityId, double x, double y, double z, float yaw, float pitch) { + PositionMoveRotation rot = new PositionMoveRotation(new Vec3(x, y, z), Vec3.ZERO, pitch, yaw); + return new ClientboundTeleportEntityPacket(entityId, rot, Collections.emptySet(), false); + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/PacketConstructor.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/PacketConstructor.java new file mode 100644 index 00000000..6fe49aa8 --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/PacketConstructor.java @@ -0,0 +1,29 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.entity; + +import de.steamwar.core.Core; +import de.steamwar.core.VersionDependent; + +public interface PacketConstructor { + public static final PacketConstructor impl = VersionDependent.getVersionImpl(Core.getInstance()); + + Object teleportPacket(int entityId, double x, double y, double z, float yaw, float pitch); +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java index 5f4c4d50..3a00ae9c 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java @@ -21,6 +21,7 @@ package de.steamwar.entity; import de.steamwar.Reflection; import de.steamwar.core.BountifulWrapper; +import de.steamwar.core.Core; import lombok.Getter; import org.bukkit.Location; import org.bukkit.Material; @@ -59,7 +60,7 @@ public class RBlockDisplay extends RDisplay { private static final Class iBlockDataClass = Reflection.getClass("net.minecraft.world.level.block.state.BlockState"); private static final Reflection.Method getState = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.block.data.CraftBlockData"), "getState", iBlockDataClass); - private static final Object blockWatcher = BountifulWrapper.impl.getDataWatcherObject(22, iBlockDataClass); + private static final Object blockWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 23 : 22, iBlockDataClass); private void getBlock(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || !block.getAsString(true).equals(DEFAULT_BLOCK.getAsString(true))) { packetSink.accept(blockWatcher, getState.invoke(block)); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java index 863dc658..d176054d 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RDisplay.java @@ -20,6 +20,7 @@ package de.steamwar.entity; import de.steamwar.core.BountifulWrapper; +import de.steamwar.core.Core; import lombok.Getter; import lombok.NonNull; import org.bukkit.Color; @@ -110,10 +111,10 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getTransformData); } - private static final Object translationWatcher = BountifulWrapper.impl.getDataWatcherObject(10, Vector3f.class); - private static final Object leftRotationWatcher = BountifulWrapper.impl.getDataWatcherObject(12, Quaternionf.class); - private static final Object scaleWatcher = BountifulWrapper.impl.getDataWatcherObject(11, Vector3f.class); - private static final Object rightRotationWatcher = BountifulWrapper.impl.getDataWatcherObject(13, Quaternionf.class); + private static final Object translationWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 11 : 10, Vector3f.class); + private static final Object leftRotationWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 13 : 12, Quaternionf.class); + private static final Object scaleWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 12 : 11, Vector3f.class); + private static final Object rightRotationWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 14 : 13, Quaternionf.class); private void getTransformData(boolean ignoreDefault, BiConsumer dataSink) { if (ignoreDefault || !transform.equals(DEFAULT_TRANSFORM)) { @@ -129,8 +130,8 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getInterpolationDuration); } - private static final Object transformationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(8, Integer.class); - private static final Object positionOrRotationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(9, Integer.class); + private static final Object transformationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 9 : 8, Integer.class); + private static final Object positionOrRotationInterpolationDurationWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 10 : 9, Integer.class); private void getInterpolationDuration(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || interpolationDelay != 0) { @@ -144,7 +145,7 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getViewRange); } - private static final Object viewRangeWatcher = BountifulWrapper.impl.getDataWatcherObject(16, Float.class); + private static final Object viewRangeWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 17 : 16, Float.class); private void getViewRange(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || viewRange != 1.0F) { @@ -157,7 +158,7 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getShadowRadius); } - private static final Object shadowRadiusWatcher = BountifulWrapper.impl.getDataWatcherObject(17, Float.class); + private static final Object shadowRadiusWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 18 : 17, Float.class); private void getShadowRadius(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || shadowRadius != 0.0F) { @@ -170,7 +171,7 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getShadowStrength); } - private static final Object shadowStrengthWatcher = BountifulWrapper.impl.getDataWatcherObject(18, Float.class); + private static final Object shadowStrengthWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 19 : 18, Float.class); private void getShadowStrength(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || shadowStrength != 1.0F) { @@ -183,7 +184,7 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getDisplayWidth); } - private static final Object displayWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(19, Float.class); + private static final Object displayWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 20 : 19, Float.class); private void getDisplayWidth(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || displayWidth != 0.0F) { @@ -196,7 +197,7 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getDisplayHeight); } - private static final Object displayHeightWatcher = BountifulWrapper.impl.getDataWatcherObject(20, Float.class); + private static final Object displayHeightWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 21 : 20, Float.class); private void getDisplayHeight(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || displayHeight != 0.0F) { @@ -209,7 +210,7 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getInterpolationDelay); } - private static final Object interpolationDelayWatcher = BountifulWrapper.impl.getDataWatcherObject(7, Integer.class); + private static final Object interpolationDelayWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 8 : 7, Integer.class); private void getInterpolationDelay(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || interpolationDelay != 0) { @@ -222,7 +223,7 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getBillboard); } - private static final Object billboardWatcher = BountifulWrapper.impl.getDataWatcherObject(14, Byte.class); + private static final Object billboardWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 15 : 14, Byte.class); private void getBillboard(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || billboard != Display.Billboard.FIXED) { @@ -235,7 +236,7 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getGlowColorOverride); } - private static final Object glowColorOverrideWatcher = BountifulWrapper.impl.getDataWatcherObject(21, Integer.class); + private static final Object glowColorOverrideWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 22 : 21, Integer.class); private void getGlowColorOverride(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || glowColorOverride != null) { @@ -248,7 +249,7 @@ public abstract class RDisplay extends REntity { sendPacket(updatePacketSink, this::getBrightness); } - private static final Object brightnessWatcher = BountifulWrapper.impl.getDataWatcherObject(15, Integer.class); + private static final Object brightnessWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 16 : 15, Integer.class); private void getBrightness(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || brightness != null) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 0c02a889..a27e6f5e 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -397,6 +397,10 @@ public class REntity { public static final Reflection.Field teleportEntity = Reflection.getField(teleportPacket, int.class, 0); public static final BountifulWrapper.PositionSetter teleportPosition = BountifulWrapper.impl.getPositionSetter(teleportPacket, Core.getVersion() == 8 ? 1 : 0); private Object getTeleportPacket(){ + if (Core.getVersion() >= 21) { + return PacketConstructor.impl.teleportPacket(entityId, x, y, z, pitch, yaw); + } + Object packet = Reflection.newInstance(teleportPacket); teleportEntity.set(packet, entityId); teleportPosition.set(packet, x, y, z, pitch, yaw); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java index 52cbfc31..45889637 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java @@ -20,6 +20,7 @@ package de.steamwar.entity; import de.steamwar.core.BountifulWrapper; +import de.steamwar.core.Core; import de.steamwar.core.ProtocolWrapper; import lombok.Getter; import org.bukkit.Location; @@ -60,14 +61,14 @@ public class RItemDisplay extends RDisplay { sendPacket(updatePacketSink, this::getItemStack); } - private static final Object itemStackWatcher = BountifulWrapper.impl.getDataWatcherObject(22, ProtocolWrapper.itemStack); + private static final Object itemStackWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 23 : 22, ProtocolWrapper.itemStack); private void getItemStack(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || !itemStack.equals(DEFAULT_ITEM_STACK)) { packetSink.accept(itemStackWatcher, asNMSCopy.invoke(null, itemStack)); } } - private static final Object itemDisplayTransformWatcher = BountifulWrapper.impl.getDataWatcherObject(23, Byte.class); + private static final Object itemDisplayTransformWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 24 : 23, Byte.class); public void setItemDisplayTransform(ItemDisplay.ItemDisplayTransform itemDisplayTransform) { this.itemDisplayTransform = itemDisplayTransform; sendPacket(updatePacketSink, this::getItemDisplayTransform); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java index 605b6770..38a10bd6 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java @@ -22,6 +22,7 @@ package de.steamwar.entity; import de.steamwar.Reflection; import de.steamwar.core.BountifulWrapper; import de.steamwar.core.ChatWrapper; +import de.steamwar.core.Core; import lombok.Getter; import org.bukkit.Location; import org.bukkit.entity.EntityType; @@ -74,7 +75,7 @@ public class RTextDisplay extends RDisplay { } private static final Class iChatBaseComponent = Reflection.getClass("net.minecraft.network.chat.Component"); - private static final Object textWatcher = BountifulWrapper.impl.getDataWatcherObject(22, iChatBaseComponent); + private static final Object textWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 23 : 22, iChatBaseComponent); private void getText(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || !text.isEmpty()) { packetSink.accept(textWatcher, ChatWrapper.impl.stringToChatComponent(text)); @@ -86,7 +87,7 @@ public class RTextDisplay extends RDisplay { sendPacket(updatePacketSink, this::getLineWidth); } - private static final Object lineWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(23, Integer.class); + private static final Object lineWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 24 : 23, Integer.class); private void getLineWidth(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || lineWidth != 200) { packetSink.accept(lineWidthWatcher, lineWidth); @@ -98,7 +99,7 @@ public class RTextDisplay extends RDisplay { sendPacket(updatePacketSink, this::getTextOpacity); } - private static final Object textOpacityWatcher = BountifulWrapper.impl.getDataWatcherObject(25, Byte.class); + private static final Object textOpacityWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 26 : 25, Byte.class); private void getTextOpacity(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || textOpacity != (byte) -1) { packetSink.accept(textOpacityWatcher, textOpacity); @@ -125,7 +126,7 @@ public class RTextDisplay extends RDisplay { sendPacket(updatePacketSink, this::getTextStatus); } - private static final Object textStatusWatcher = BountifulWrapper.impl.getDataWatcherObject(26, Byte.class); + private static final Object textStatusWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 27 : 26, Byte.class); private void getTextStatus(boolean ignoreDefault, BiConsumer packetSink) { byte status = 0;