diff --git a/nms/all/pom.xml b/nms/all/pom.xml index ef1306fd..96e63446 100644 --- a/nms/all/pom.xml +++ b/nms/all/pom.xml @@ -17,7 +17,6 @@ target/${project.build.finalName}-${nms-classifier}.jar - @@ -80,6 +79,10 @@ de.epiceric shopchest-nms-v1_21_R2 + + de.epiceric + shopchest-nms-v1_21_R3 + diff --git a/nms/pom.xml b/nms/pom.xml index 78d92364..568a64aa 100644 --- a/nms/pom.xml +++ b/nms/pom.xml @@ -29,6 +29,7 @@ v1_20_R4 v1_21_R1 v1_21_R2 + v1_21_R3 all @@ -132,6 +133,12 @@ 1.0.0 provided + + de.epiceric + shopchest-nms-v1_21_R3 + 1.0.0 + provided + diff --git a/nms/v1_21_R3/pom.xml b/nms/v1_21_R3/pom.xml new file mode 100644 index 00000000..4fc624fe --- /dev/null +++ b/nms/v1_21_R3/pom.xml @@ -0,0 +1,41 @@ + + + + shopchest-nms + de.epiceric + 1.0.1 + + 4.0.0 + + shopchest-nms-v1_21_R3 + 1.0.0 + + + 1.21.4-R0.1-SNAPSHOT + + + + + org.spigotmc + spigot + remapped-mojang + + + de.epiceric + shopchest-nms-interface + provided + + + + + + + net.md-5 + specialsource-maven-plugin + + + + + diff --git a/nms/v1_21_R3/src/main/java/de/epiceric/shopchest/nms/v1_21_R3/FakeArmorStandImpl.java b/nms/v1_21_R3/src/main/java/de/epiceric/shopchest/nms/v1_21_R3/FakeArmorStandImpl.java new file mode 100644 index 00000000..ff62d679 --- /dev/null +++ b/nms/v1_21_R3/src/main/java/de/epiceric/shopchest/nms/v1_21_R3/FakeArmorStandImpl.java @@ -0,0 +1,90 @@ +package de.epiceric.shopchest.nms.v1_21_R3; + +import java.lang.reflect.Field; +import java.util.List; +import java.util.Optional; + +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_21_R3.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; + private final static byte MARKER_FLAG = 0b10000; + private final static EntityDataAccessor DATA_SHARED_FLAGS_ID; + private final static EntityDataAccessor> DATA_CUSTOM_NAME; + private final static EntityDataAccessor DATA_CUSTOM_NAME_VISIBLE; + private final static float MARKER_ARMOR_STAND_OFFSET = 1.975f; + + static { + try { + final Field dataSharedFlagsId = Entity.class.getDeclaredField(ObfuscatedFieldNames.DATA_SHARED_FLAGS_ID); + dataSharedFlagsId.setAccessible(true); + DATA_SHARED_FLAGS_ID = forceCast(dataSharedFlagsId.get(null)); + 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); + dataCustomNameVisibleField.setAccessible(true); + DATA_CUSTOM_NAME_VISIBLE = forceCast(dataCustomNameVisibleField.get(null)); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + } + + public FakeArmorStandImpl() { + super(); + } + + @Override + public void sendData(String name, Iterable receivers) { + sendData(receivers, name); + } + + @Override + protected EntityType getEntityType() { + return EntityType.ARMOR_STAND; + } + + @Override + protected float getSpawnOffSet() { + return MARKER_ARMOR_STAND_OFFSET; + } + + @Override + protected int getDataItemCount() { + return 4; + } + + @Override + 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)))); + 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 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); + } + +} diff --git a/nms/v1_21_R3/src/main/java/de/epiceric/shopchest/nms/v1_21_R3/FakeEntityImpl.java b/nms/v1_21_R3/src/main/java/de/epiceric/shopchest/nms/v1_21_R3/FakeEntityImpl.java new file mode 100644 index 00000000..f76cdefa --- /dev/null +++ b/nms/v1_21_R3/src/main/java/de/epiceric/shopchest/nms/v1_21_R3/FakeEntityImpl.java @@ -0,0 +1,115 @@ +package de.epiceric.shopchest.nms.v1_21_R3; + +import de.epiceric.shopchest.nms.FakeEntity; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; +import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket; +import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; +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.phys.Vec3; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_21_R3.entity.CraftPlayer; +import org.bukkit.entity.Player; + +import java.lang.reflect.Field; +import java.util.LinkedList; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicInteger; + +public abstract class FakeEntityImpl implements FakeEntity { + + private final static AtomicInteger ENTITY_COUNTER; + private final static EntityDataAccessor DATA_NO_GRAVITY; + private final static EntityDataAccessor DATA_SILENT; + + static { + try { + final Field entityCounterField = Entity.class.getDeclaredField(ObfuscatedFieldNames.ENTITY_COUNTER); + entityCounterField.setAccessible(true); + ENTITY_COUNTER = (AtomicInteger) entityCounterField.get(null); + final Field dataNoGravityField = Entity.class.getDeclaredField(ObfuscatedFieldNames.DATA_NO_GRAVITY); + dataNoGravityField.setAccessible(true); + DATA_NO_GRAVITY = forceCast(dataNoGravityField.get(null)); + final Field dataSilentField = Entity.class.getDeclaredField(ObfuscatedFieldNames.DATA_SILENT); + dataSilentField.setAccessible(true); + DATA_SILENT = forceCast(dataSilentField.get(null)); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + } + + protected final int entityId; + + public FakeEntityImpl() { + entityId = ENTITY_COUNTER.incrementAndGet(); + } + + @SuppressWarnings("unchecked") + protected static T forceCast(Object o) { + return (T) o; + } + + @Override + public int getEntityId() { + return entityId; + } + + protected void sendPacket(Packet packet, Iterable receivers) { + for (Player receiver : receivers) { + ((CraftPlayer) receiver).getHandle().connection.send(packet); + } + } + + @Override + public void spawn(UUID uuid, Location location, Iterable receivers) { + final ClientboundAddEntityPacket spawnPacket = new ClientboundAddEntityPacket( + entityId, + uuid, + location.getX(), + location.getY() + getSpawnOffSet(), + location.getZ(), + 0f, + 0f, + getEntityType(), + 0, + Vec3.ZERO, + 0d + ); + sendPacket(spawnPacket, receivers); + } + + @Override + public void remove(Iterable receivers) { + final ClientboundRemoveEntitiesPacket removePacket = new ClientboundRemoveEntitiesPacket(entityId); + sendPacket(removePacket, receivers); + } + + protected void sendData(Iterable receivers, T data) { + // Create packet + final List> packedItems = new LinkedList<>(); + final ClientboundSetEntityDataPacket dataPacket = new ClientboundSetEntityDataPacket(entityId, packedItems); + + // Setup data + packedItems.add(SynchedEntityData.DataValue.create(DATA_NO_GRAVITY, true)); + packedItems.add(SynchedEntityData.DataValue.create(DATA_SILENT, true)); + addSpecificData(packedItems, data); + + // Send packet + sendPacket(dataPacket, receivers); + } + + protected abstract EntityType getEntityType(); + + protected float getSpawnOffSet() { + return 0f; + } + + protected abstract int getDataItemCount(); + + protected abstract void addSpecificData(List> packedItems, T data); + +} diff --git a/nms/v1_21_R3/src/main/java/de/epiceric/shopchest/nms/v1_21_R3/FakeItemImpl.java b/nms/v1_21_R3/src/main/java/de/epiceric/shopchest/nms/v1_21_R3/FakeItemImpl.java new file mode 100644 index 00000000..8d6aeec0 --- /dev/null +++ b/nms/v1_21_R3/src/main/java/de/epiceric/shopchest/nms/v1_21_R3/FakeItemImpl.java @@ -0,0 +1,60 @@ +package de.epiceric.shopchest.nms.v1_21_R3; + +import de.epiceric.shopchest.nms.FakeItem; +import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.phys.Vec3; +import org.bukkit.craftbukkit.v1_21_R3.inventory.CraftItemStack; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.lang.reflect.Field; +import java.util.List; + +public class FakeItemImpl extends FakeEntityImpl implements FakeItem { + + private final static EntityDataAccessor DATA_ITEM; + + static { + try { + final Field dataItemField = ItemEntity.class.getDeclaredField(ObfuscatedFieldNames.DATA_ITEM); + dataItemField.setAccessible(true); + DATA_ITEM = forceCast(dataItemField.get(null)); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + } + + public FakeItemImpl() { + super(); + } + + @Override + public void sendData(ItemStack item, Iterable receivers) { + sendData(receivers, item); + } + + @Override + public void resetVelocity(Iterable receivers) { + final ClientboundSetEntityMotionPacket velocityPacket = new ClientboundSetEntityMotionPacket(entityId, Vec3.ZERO); + sendPacket(velocityPacket, receivers); + } + + @Override + protected EntityType getEntityType() { + return EntityType.ITEM; + } + + @Override + protected int getDataItemCount() { + return 1; + } + + @Override + protected void addSpecificData(List> packedItems, ItemStack data) { + packedItems.add(SynchedEntityData.DataValue.create(DATA_ITEM, CraftItemStack.asNMSCopy(data))); + } +} diff --git a/nms/v1_21_R3/src/main/java/de/epiceric/shopchest/nms/v1_21_R3/ObfuscatedFieldNames.java b/nms/v1_21_R3/src/main/java/de/epiceric/shopchest/nms/v1_21_R3/ObfuscatedFieldNames.java new file mode 100644 index 00000000..67977f2a --- /dev/null +++ b/nms/v1_21_R3/src/main/java/de/epiceric/shopchest/nms/v1_21_R3/ObfuscatedFieldNames.java @@ -0,0 +1,15 @@ +package de.epiceric.shopchest.nms.v1_21_R3; + +public class ObfuscatedFieldNames { + + // Entity + public static final String ENTITY_COUNTER = "c"; + public static final String DATA_NO_GRAVITY = "aR"; + public static final String DATA_SILENT = "aQ"; + public static final String DATA_SHARED_FLAGS_ID = "am"; + public static final String DATA_CUSTOM_NAME = "aO"; + public static final String DATA_CUSTOM_NAME_VISIBLE = "aP"; + // ItemEntity + public static final String DATA_ITEM = "c"; + +} diff --git a/nms/v1_21_R3/src/main/java/de/epiceric/shopchest/nms/v1_21_R3/PlatformImpl.java b/nms/v1_21_R3/src/main/java/de/epiceric/shopchest/nms/v1_21_R3/PlatformImpl.java new file mode 100644 index 00000000..8d6cfc78 --- /dev/null +++ b/nms/v1_21_R3/src/main/java/de/epiceric/shopchest/nms/v1_21_R3/PlatformImpl.java @@ -0,0 +1,19 @@ +package de.epiceric.shopchest.nms.v1_21_R3; + +import de.epiceric.shopchest.nms.FakeArmorStand; +import de.epiceric.shopchest.nms.FakeItem; +import de.epiceric.shopchest.nms.Platform; + +public class PlatformImpl implements Platform { + + @Override + public FakeArmorStand createFakeArmorStand() { + return new FakeArmorStandImpl(); + } + + @Override + public FakeItem createFakeItem() { + return new FakeItemImpl(); + } + +} diff --git a/plugin/src/main/java/de/epiceric/shopchest/nms/PlatformLoader.java b/plugin/src/main/java/de/epiceric/shopchest/nms/PlatformLoader.java index f9935b1e..af76f5ef 100644 --- a/plugin/src/main/java/de/epiceric/shopchest/nms/PlatformLoader.java +++ b/plugin/src/main/java/de/epiceric/shopchest/nms/PlatformLoader.java @@ -118,6 +118,8 @@ private Platform getSpecificPlatform(String mappingsVersion) { return new de.epiceric.shopchest.nms.v1_21_R1.PlatformImpl(); case "61a218cda78417b6039da56e08194083": // 1.21.3 (v1_21_R2) return new de.epiceric.shopchest.nms.v1_21_R2.PlatformImpl(); + case "60ac387ca8007aa018e6aeb394a6988c": // 1.21.4 (v1_21_R3) + return new de.epiceric.shopchest.nms.v1_21_R3.PlatformImpl(); default: return null; }