Skip to content

Commit 8da0491

Browse files
committed
Adapt position packet to the new position packet architecture
1 parent 94e548d commit 8da0491

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

nms/v1_21_R2/src/main/java/de/epiceric/shopchest/nms/v1_21_R2/FakeArmorStandImpl.java

+18-22
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
package de.epiceric.shopchest.nms.v1_21_R2;
22

3+
import java.lang.reflect.Field;
4+
import java.util.List;
5+
import java.util.Optional;
6+
7+
import org.bukkit.Location;
8+
import org.bukkit.craftbukkit.v1_21_R2.util.CraftChatMessage;
9+
import org.bukkit.entity.Player;
10+
311
import de.epiceric.shopchest.nms.FakeArmorStand;
4-
import io.netty.buffer.Unpooled;
5-
import net.minecraft.network.FriendlyByteBuf;
612
import net.minecraft.network.chat.Component;
7-
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
13+
import net.minecraft.network.protocol.game.ClientboundEntityPositionSyncPacket;
814
import net.minecraft.network.syncher.EntityDataAccessor;
915
import net.minecraft.network.syncher.SynchedEntityData;
1016
import net.minecraft.world.entity.Entity;
1117
import net.minecraft.world.entity.EntityType;
18+
import net.minecraft.world.entity.PositionMoveRotation;
1219
import net.minecraft.world.entity.decoration.ArmorStand;
13-
import org.bukkit.Location;
14-
import org.bukkit.craftbukkit.v1_21_R2.util.CraftChatMessage;
15-
import org.bukkit.entity.Player;
16-
17-
import java.lang.reflect.Field;
18-
import java.util.List;
19-
import java.util.Optional;
20+
import net.minecraft.world.phys.Vec3;
2021

2122
public class FakeArmorStandImpl extends FakeEntityImpl<String> implements FakeArmorStand {
2223

@@ -35,7 +36,8 @@ public class FakeArmorStandImpl extends FakeEntityImpl<String> implements FakeAr
3536
final Field dataCustomNameField = Entity.class.getDeclaredField(ObfuscatedFieldNames.DATA_CUSTOM_NAME);
3637
dataCustomNameField.setAccessible(true);
3738
DATA_CUSTOM_NAME = forceCast(dataCustomNameField.get(null));
38-
final Field dataCustomNameVisibleField = Entity.class.getDeclaredField(ObfuscatedFieldNames.DATA_CUSTOM_NAME_VISIBLE);
39+
final Field dataCustomNameVisibleField = Entity.class
40+
.getDeclaredField(ObfuscatedFieldNames.DATA_CUSTOM_NAME_VISIBLE);
3941
dataCustomNameVisibleField.setAccessible(true);
4042
DATA_CUSTOM_NAME_VISIBLE = forceCast(dataCustomNameVisibleField.get(null));
4143
} catch (ReflectiveOperationException e) {
@@ -71,23 +73,17 @@ protected int getDataItemCount() {
7173
protected void addSpecificData(List<SynchedEntityData.DataValue<?>> packedItems, String name) {
7274
packedItems.add(SynchedEntityData.DataValue.create(DATA_SHARED_FLAGS_ID, INVISIBLE_FLAG));
7375
packedItems.add(SynchedEntityData.DataValue.create(DATA_CUSTOM_NAME, Optional.ofNullable(
74-
CraftChatMessage.fromStringOrNull(name)
75-
)));
76+
CraftChatMessage.fromStringOrNull(name))));
7677
packedItems.add(SynchedEntityData.DataValue.create(DATA_CUSTOM_NAME_VISIBLE, true));
7778
packedItems.add(SynchedEntityData.DataValue.create(ArmorStand.DATA_CLIENT_FLAGS, MARKER_FLAG));
7879
}
7980

8081
@Override
8182
public void setLocation(Location location, Iterable<Player> receivers) {
82-
final FriendlyByteBuf buffer = new FriendlyByteBuf(Unpooled.buffer());
83-
buffer.writeVarInt(entityId);
84-
buffer.writeDouble(location.getX());
85-
buffer.writeDouble(location.getY() + MARKER_ARMOR_STAND_OFFSET);
86-
buffer.writeDouble(location.getZ());
87-
buffer.writeByte(0);
88-
buffer.writeByte(0);
89-
buffer.writeBoolean(false);
90-
final ClientboundTeleportEntityPacket positionPacket = ClientboundTeleportEntityPacket.STREAM_CODEC.decode(buffer);
83+
final Vec3 pos = new Vec3(location.getX(), location.getY() + MARKER_ARMOR_STAND_OFFSET, location.getZ());
84+
final PositionMoveRotation positionMoveRotation = new PositionMoveRotation(pos, Vec3.ZERO, 0f, 0f);
85+
final ClientboundEntityPositionSyncPacket positionPacket = new ClientboundEntityPositionSyncPacket(entityId,
86+
positionMoveRotation, false);
9187
sendPacket(positionPacket, receivers);
9288
}
9389

0 commit comments

Comments
 (0)