mirror of
https://github.com/Flowsqy/ShopChest.git
synced 2024-12-01 01:53:22 +01:00
1.19.4 support somewhat..
This commit is contained in:
parent
fe33108bc4
commit
2e27e82c68
@ -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<ItemStack> implements FakeItem {
|
||||
|
||||
private final static EntityDataAccessor<net.minecraft.world.item.ItemStack> 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<Player> receivers) {
|
||||
sendData(receivers, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetVelocity(Iterable<Player> 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<SynchedEntityData.DataValue<?>> packedItems, ItemStack data) {
|
||||
packedItems.add(SynchedEntityData.DataValue.create(DATA_ITEM, CraftItemStack.asNMSCopy(data)));
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user