use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project PaperDev by Kamillaova.
the class CraftItemStack method asNMSCopy.
public static net.minecraft.server.v1_12_R1.ItemStack asNMSCopy(ItemStack original) {
if (original instanceof CraftItemStack) {
CraftItemStack stack = (CraftItemStack) original;
return stack.handle == null ? net.minecraft.server.v1_12_R1.ItemStack.a : stack.handle.cloneItemStack();
}
if (original == null || original.getTypeId() <= 0) {
return net.minecraft.server.v1_12_R1.ItemStack.a;
}
Item item = CraftMagicNumbers.getItem(original.getType());
if (item == null) {
return net.minecraft.server.v1_12_R1.ItemStack.a;
}
net.minecraft.server.v1_12_R1.ItemStack stack = new net.minecraft.server.v1_12_R1.ItemStack(item, original.getAmount(), original.getDurability(), false);
if (original.hasItemMeta()) {
setItemMeta(stack, original.getItemMeta());
} else {
// Converted after setItemMeta
stack.convertStack();
}
return stack;
}
use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project PaperDev by Kamillaova.
the class ItemMetaTest method testBlockStateMeta.
@Test
public void testBlockStateMeta() {
for (Item item : (Iterable<Item>) Item.REGISTRY) {
Block block = null;
if (item instanceof ItemBlock) {
block = ((ItemBlock) item).getBlock();
} else if (item instanceof ItemReed) {
block = ((ItemReed) item).a;
}
if (block != null) {
if (block instanceof ITileEntity) {
ItemStack stack = CraftItemStack.asNewCraftStack(Item.getItemOf(block));
// Command blocks aren't unit testable atm
if (stack.getType() == Material.AIR || stack.getType() == Material.COMMAND || stack.getType() == Material.COMMAND_CHAIN || stack.getType() == Material.COMMAND_REPEATING) {
return;
}
ItemMeta meta = stack.getItemMeta();
assertTrue(stack + " has meta of type " + meta + " expected BlockStateMeta", meta instanceof BlockStateMeta);
BlockStateMeta blockState = (BlockStateMeta) meta;
assertNotNull(stack + " has null block state", blockState.getBlockState());
blockState.setBlockState(blockState.getBlockState());
}
}
}
}
use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project acidisland by tastybento.
the class NMSHandler method getSpawnEgg.
/**
* Get spawn egg
* @param type
* @param amount
* @return
*/
public ItemStack getSpawnEgg(EntityType type, int amount) {
// Bukkit.getLogger().info("DEBUG: setting spawn egg " + type.toString());
ItemStack item = new ItemStack(Material.MONSTER_EGG, amount);
net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tagCompound = stack.getTag();
if (tagCompound == null) {
tagCompound = new NBTTagCompound();
}
// Bukkit.getLogger().info("DEBUG: tag = " + tagCompound);
NBTTagCompound id = new NBTTagCompound();
if (!bToMConversion.containsKey(type)) {
id.setString("id", "minecraft:" + type.toString().toLowerCase());
} else {
id.setString("id", "minecraft:" + bToMConversion.get(type));
}
tagCompound.set("EntityTag", id);
stack.setTag(tagCompound);
// Bukkit.getLogger().info("DEBUG: after tag = " + tagCompound);
return CraftItemStack.asBukkitCopy(stack);
}
use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project acidisland by tastybento.
the class NMSHandler method setBook.
@Override
public ItemStack setBook(Tag item) {
ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK);
// Bukkit.getLogger().info(item.toString());
if (((CompoundTag) item).getValue().containsKey("tag")) {
Map<String, Tag> contents = (Map<String, Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
// BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
String author = "";
if (contents.containsKey("author")) {
author = ((StringTag) contents.get("author")).getValue();
}
// Bukkit.getLogger().info("Author: " + author);
// bookMeta.setAuthor(author);
String title = "";
if (contents.containsKey("title")) {
title = ((StringTag) contents.get("title")).getValue();
}
// Bukkit.getLogger().info("Title: " + title);
// bookMeta.setTitle(title);
List<String> lore = new ArrayList<String>();
if (contents.containsKey("display")) {
Map<String, Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
List<Tag> loreTag = ((ListTag) display.get("Lore")).getValue();
for (Tag s : loreTag) {
lore.add(((StringTag) s).getValue());
}
}
// Bukkit.getLogger().info("Lore: " + lore);
net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
// Pages
// Create the NMS Stack's NBT (item data)
NBTTagCompound tag = new NBTTagCompound();
// Set the book's title
tag.setString("title", title);
tag.setString("author", author);
if (contents.containsKey("pages")) {
NBTTagList pages = new NBTTagList();
List<Tag> pagesTag = ((ListTag) contents.get("pages")).getValue();
for (Tag s : pagesTag) {
pages.add(new NBTTagString(((StringTag) s).getValue()));
}
// Add the pages to the tag
tag.set("pages", pages);
}
// Apply the tag to the item
stack.setTag(tag);
chestItem = CraftItemStack.asCraftMirror(stack);
ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
bookMeta.setLore(lore);
chestItem.setItemMeta(bookMeta);
}
return chestItem;
}
use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project MyPet by xXKeyleXx.
the class IconMenuInventory method open.
@Override
public void open(IconMenu menu, HumanEntity player) {
size = menu.getSize();
minecraftInventory = new CustomInventory(size, menu.getTitle());
for (int slot = 0; slot < size; slot++) {
IconMenuItem menuItem = menu.getOption(slot);
if (menuItem != null) {
ItemStack item = createItemStack(menuItem);
minecraftInventory.setItem(slot, item);
}
}
player.openInventory(minecraftInventory.getBukkitInventory());
}
Aggregations