mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-22 10:22:29 +00:00
Add FakeItem implementation
This commit is contained in:
parent
b37ae0fa9d
commit
278b4462f3
@ -7,4 +7,6 @@ public interface FakeItem extends FakeEntity{
|
||||
|
||||
void sendData(ItemStack item, Iterable<Player> receivers);
|
||||
|
||||
void resetVelocity(Iterable<Player> receivers);
|
||||
|
||||
}
|
||||
|
@ -1,22 +1,46 @@
|
||||
package de.epiceric.shopchest.nms.v1_17_R1;
|
||||
|
||||
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_17_R1.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
|
||||
@ -26,11 +50,11 @@ public class FakeItemImpl extends FakeEntityImpl<ItemStack> implements FakeItem
|
||||
|
||||
@Override
|
||||
protected int getDataItemCount() {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSpecificData(List<SynchedEntityData.DataItem<?>> packedItems, ItemStack data) {
|
||||
|
||||
packedItems.add(new SynchedEntityData.DataItem<>(DATA_ITEM, CraftItemStack.asNMSCopy(data)));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user