mirror of
https://github.com/Flowsqy/ShopChest.git
synced 2024-11-25 00:55:12 +01:00
Adapt position packet to the new position packet architecture
This commit is contained in:
parent
94e548d2ee
commit
8da0491dc5
@ -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<String> implements FakeArmorStand {
|
||||
|
||||
private final static byte INVISIBLE_FLAG = 0b100000;
|
||||
@ -35,7 +36,8 @@ public class FakeArmorStandImpl extends FakeEntityImpl<String> 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<String> implements FakeAr
|
||||
protected void addSpecificData(List<SynchedEntityData.DataValue<?>> 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<Player> 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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user