From 8da0491dc5749c6581e6a5e3f79803459cd50777 Mon Sep 17 00:00:00 2001 From: Flowsqy <47575244+Flowsqy@users.noreply.github.com> Date: Mon, 28 Oct 2024 22:50:40 +0100 Subject: [PATCH] Adapt position packet to the new position packet architecture --- .../nms/v1_21_R2/FakeArmorStandImpl.java | 48 +++++++++---------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/nms/v1_21_R2/src/main/java/de/epiceric/shopchest/nms/v1_21_R2/FakeArmorStandImpl.java b/nms/v1_21_R2/src/main/java/de/epiceric/shopchest/nms/v1_21_R2/FakeArmorStandImpl.java index e21f162..49c9a06 100644 --- a/nms/v1_21_R2/src/main/java/de/epiceric/shopchest/nms/v1_21_R2/FakeArmorStandImpl.java +++ b/nms/v1_21_R2/src/main/java/de/epiceric/shopchest/nms/v1_21_R2/FakeArmorStandImpl.java @@ -1,23 +1,24 @@ package de.epiceric.shopchest.nms.v1_21_R2; -import de.epiceric.shopchest.nms.FakeArmorStand; -import io.netty.buffer.Unpooled; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.Component; -import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; -import net.minecraft.network.syncher.EntityDataAccessor; -import net.minecraft.network.syncher.SynchedEntityData; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.decoration.ArmorStand; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_21_R2.util.CraftChatMessage; -import org.bukkit.entity.Player; - import java.lang.reflect.Field; import java.util.List; import java.util.Optional; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_21_R2.util.CraftChatMessage; +import org.bukkit.entity.Player; + +import de.epiceric.shopchest.nms.FakeArmorStand; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundEntityPositionSyncPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.PositionMoveRotation; +import net.minecraft.world.entity.decoration.ArmorStand; +import net.minecraft.world.phys.Vec3; + public class FakeArmorStandImpl extends FakeEntityImpl implements FakeArmorStand { private final static byte INVISIBLE_FLAG = 0b100000; @@ -35,7 +36,8 @@ public class FakeArmorStandImpl extends FakeEntityImpl implements FakeAr final Field dataCustomNameField = Entity.class.getDeclaredField(ObfuscatedFieldNames.DATA_CUSTOM_NAME); dataCustomNameField.setAccessible(true); DATA_CUSTOM_NAME = forceCast(dataCustomNameField.get(null)); - final Field dataCustomNameVisibleField = Entity.class.getDeclaredField(ObfuscatedFieldNames.DATA_CUSTOM_NAME_VISIBLE); + final Field dataCustomNameVisibleField = Entity.class + .getDeclaredField(ObfuscatedFieldNames.DATA_CUSTOM_NAME_VISIBLE); dataCustomNameVisibleField.setAccessible(true); DATA_CUSTOM_NAME_VISIBLE = forceCast(dataCustomNameVisibleField.get(null)); } catch (ReflectiveOperationException e) { @@ -71,23 +73,17 @@ public class FakeArmorStandImpl extends FakeEntityImpl implements FakeAr protected void addSpecificData(List> packedItems, String name) { packedItems.add(SynchedEntityData.DataValue.create(DATA_SHARED_FLAGS_ID, INVISIBLE_FLAG)); packedItems.add(SynchedEntityData.DataValue.create(DATA_CUSTOM_NAME, Optional.ofNullable( - CraftChatMessage.fromStringOrNull(name) - ))); + CraftChatMessage.fromStringOrNull(name)))); packedItems.add(SynchedEntityData.DataValue.create(DATA_CUSTOM_NAME_VISIBLE, true)); packedItems.add(SynchedEntityData.DataValue.create(ArmorStand.DATA_CLIENT_FLAGS, MARKER_FLAG)); } @Override public void setLocation(Location location, Iterable receivers) { - final FriendlyByteBuf buffer = new FriendlyByteBuf(Unpooled.buffer()); - buffer.writeVarInt(entityId); - buffer.writeDouble(location.getX()); - buffer.writeDouble(location.getY() + MARKER_ARMOR_STAND_OFFSET); - buffer.writeDouble(location.getZ()); - buffer.writeByte(0); - buffer.writeByte(0); - buffer.writeBoolean(false); - final ClientboundTeleportEntityPacket positionPacket = ClientboundTeleportEntityPacket.STREAM_CODEC.decode(buffer); + final Vec3 pos = new Vec3(location.getX(), location.getY() + MARKER_ARMOR_STAND_OFFSET, location.getZ()); + final PositionMoveRotation positionMoveRotation = new PositionMoveRotation(pos, Vec3.ZERO, 0f, 0f); + final ClientboundEntityPositionSyncPacket positionPacket = new ClientboundEntityPositionSyncPacket(entityId, + positionMoveRotation, false); sendPacket(positionPacket, receivers); }