use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project SilkSpawners by timbru31.
the class NMSHandler method setNBTEntityID.
@Override
public ItemStack setNBTEntityID(final ItemStack item, final String entity) {
if (item == null || StringUtils.isBlank(entity)) {
Bukkit.getLogger().warning("[SilkSpawners] Skipping invalid spawner to set NBT data on.");
return null;
}
net.minecraft.server.v1_12_R1.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
NBTTagCompound tag = itemStack.getTag();
if (tag == null) {
tag = new NBTTagCompound();
itemStack.setTag(tag);
}
if (!tag.hasKey("SilkSpawners")) {
tag.set("SilkSpawners", new NBTTagCompound());
}
tag.getCompound("SilkSpawners").setString("entity", entity);
if (!tag.hasKey("BlockEntityTag")) {
tag.set("BlockEntityTag", new NBTTagCompound());
}
tag.getCompound("BlockEntityTag").setString("EntityId", entity);
if (!tag.hasKey("SpawnData")) {
tag.set("SpawnData", new NBTTagCompound());
}
tag.getCompound("SpawnData").setString("id", entity);
if (!tag.getCompound("BlockEntityTag").hasKey("SpawnData")) {
tag.getCompound("BlockEntityTag").set("SpawnData", new NBTTagCompound());
}
tag.getCompound("BlockEntityTag").getCompound("SpawnData").setString("id", entity);
if (!tag.getCompound("BlockEntityTag").hasKey("SpawnPotentials")) {
tag.getCompound("BlockEntityTag").set("SpawnPotentials", new NBTTagCompound());
}
if (!tag.hasKey("EntityTag")) {
tag.set("EntityTag", new NBTTagCompound());
}
String prefixedEntity;
if (!entity.startsWith("minecraft:")) {
prefixedEntity = "minecraft:" + entity;
} else {
prefixedEntity = entity;
}
tag.getCompound("EntityTag").setString("id", prefixedEntity);
return CraftItemStack.asCraftMirror(itemStack);
}
use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project WLib by WizardlyBump17.
the class PacketListener method entityMetadata.
@SuppressWarnings("unchecked")
@SneakyThrows
private void entityMetadata(World world, PacketContainer packet, PacketPlayOutEntityMetadata handle) {
final Entity entity = packet.getEntityModifier(world).read(0);
if (!(entity instanceof org.bukkit.entity.Item))
return;
final ItemStack itemStack = ((org.bukkit.entity.Item) entity).getItemStack().clone();
if (isInvalid(itemStack))
return;
final Field field = handle.getClass().getDeclaredField("b");
field.setAccessible(true);
List<DataWatcher.Item<?>> items = new ArrayList<>((List<DataWatcher.Item<?>>) field.get(handle));
final DataWatcher.Item<?> item;
int index;
if (items.size() == 7)
// new item
item = items.get(index = 6).d();
else
// item merge
item = items.get(index = 0).d();
final Field itemField = item.getClass().getDeclaredField("b");
itemField.setAccessible(true);
itemField.set(item, CraftItemStack.asNMSCopy(fixItem(itemStack)));
items.set(index, item);
field.set(handle, items);
}
use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project PaperDev by Kamillaova.
the class CraftInventoryPlayer method setItem.
@Override
public void setItem(int index, ItemStack item) {
super.setItem(index, item);
if (this.getHolder() == null)
return;
EntityPlayer player = ((CraftPlayer) this.getHolder()).getHandle();
if (player.playerConnection == null)
return;
// subtracting that value from 8.
if (index < PlayerInventory.getHotbarSize()) {
index += 36;
} else if (index > 39) {
// Off hand
index += 5;
} else if (index > 35) {
index = 8 - (index - 36);
}
player.playerConnection.sendPacket(new PacketPlayOutSetSlot(player.defaultContainer.windowId, index, CraftItemStack.asNMSCopy(item)));
}
use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project PaperDev by Kamillaova.
the class CraftItemStack method getEnchantments.
static Map<Enchantment, Integer> getEnchantments(net.minecraft.server.v1_12_R1.ItemStack item) {
NBTTagList list = (item != null && item.hasEnchantments()) ? item.getEnchantments() : null;
if (list == null || list.size() == 0) {
return ImmutableMap.of();
}
ImmutableMap.Builder<Enchantment, Integer> result = ImmutableMap.builder();
for (int i = 0; i < list.size(); i++) {
int id = 0xffff & ((NBTTagCompound) list.get(i)).getShort(ENCHANTMENTS_ID.NBT);
int level = 0xffff & ((NBTTagCompound) list.get(i)).getShort(ENCHANTMENTS_LVL.NBT);
result.put(Enchantment.getById(id), level);
}
return result.build();
}
use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project PaperDev by Kamillaova.
the class CraftItemFrame method update.
private void update() {
EntityItemFrame old = this.getHandle();
WorldServer world = ((CraftWorld) getWorld()).getHandle();
BlockPosition position = old.getBlockPosition();
EnumDirection direction = old.getDirection();
ItemStack item = old.getItem() != null ? old.getItem().cloneItemStack() : null;
old.die();
EntityItemFrame frame = new EntityItemFrame(world, position, direction);
frame.setItem(item);
world.addEntity(frame);
this.entity = frame;
}
Aggregations