From 2e27e82c68acb38a2083525d8ec010ef9a291fb1 Mon Sep 17 00:00:00 2001 From: smeths Date: Tue, 21 Mar 2023 12:42:34 +0000 Subject: [PATCH] 1.19.4 support somewhat.. --- .../shopchest/nms/v1_19_R3/FakeItemImpl.java | 60 +++++++++++++++++++ .../shopchest/nms/v1_19_R3/PlatformImpl.java | 25 ++++++++ .../nms/v1_19_R3/TextComponentHelperImpl.java | 15 +++++ 3 files changed, 100 insertions(+) create mode 100644 nms/v1_19_R3/src/main/java/de/epiceric/shopchest/nms/v1_19_R3/FakeItemImpl.java create mode 100644 nms/v1_19_R3/src/main/java/de/epiceric/shopchest/nms/v1_19_R3/PlatformImpl.java create mode 100644 nms/v1_19_R3/src/main/java/de/epiceric/shopchest/nms/v1_19_R3/TextComponentHelperImpl.java diff --git a/nms/v1_19_R3/src/main/java/de/epiceric/shopchest/nms/v1_19_R3/FakeItemImpl.java b/nms/v1_19_R3/src/main/java/de/epiceric/shopchest/nms/v1_19_R3/FakeItemImpl.java new file mode 100644 index 0000000..9af318a --- /dev/null +++ b/nms/v1_19_R3/src/main/java/de/epiceric/shopchest/nms/v1_19_R3/FakeItemImpl.java @@ -0,0 +1,60 @@ +package de.epiceric.shopchest.nms.v1_19_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_19_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("c"); // 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_19_R3/src/main/java/de/epiceric/shopchest/nms/v1_19_R3/PlatformImpl.java b/nms/v1_19_R3/src/main/java/de/epiceric/shopchest/nms/v1_19_R3/PlatformImpl.java new file mode 100644 index 0000000..e97288a --- /dev/null +++ b/nms/v1_19_R3/src/main/java/de/epiceric/shopchest/nms/v1_19_R3/PlatformImpl.java @@ -0,0 +1,25 @@ +package de.epiceric.shopchest.nms.v1_19_R3; + +import de.epiceric.shopchest.nms.FakeArmorStand; +import de.epiceric.shopchest.nms.FakeItem; +import de.epiceric.shopchest.nms.Platform; +import de.epiceric.shopchest.nms.TextComponentHelper; + +public class PlatformImpl implements Platform { + + @Override + public FakeArmorStand createFakeArmorStand() { + return new FakeArmorStandImpl(); + } + + @Override + public FakeItem createFakeItem() { + return new FakeItemImpl(); + } + + @Override + public TextComponentHelper getTextComponentHelper() { + return new TextComponentHelperImpl(); + } + +} diff --git a/nms/v1_19_R3/src/main/java/de/epiceric/shopchest/nms/v1_19_R3/TextComponentHelperImpl.java b/nms/v1_19_R3/src/main/java/de/epiceric/shopchest/nms/v1_19_R3/TextComponentHelperImpl.java new file mode 100644 index 0000000..c443b7d --- /dev/null +++ b/nms/v1_19_R3/src/main/java/de/epiceric/shopchest/nms/v1_19_R3/TextComponentHelperImpl.java @@ -0,0 +1,15 @@ +package de.epiceric.shopchest.nms.v1_19_R3; + +import de.epiceric.shopchest.nms.TextComponentHelper; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; +import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack; +import org.bukkit.inventory.ItemStack; + +public class TextComponentHelperImpl implements TextComponentHelper { + @Override + public String getNbt(ItemStack itemStack) { + final Tag tag = CraftItemStack.asNMSCopy(itemStack).save(new CompoundTag()).get("tag"); + return tag == null ? null : tag.getAsString(); + } +}