use of net.minecraft.server.v1_8_R1.NBTTagCompound in project askyblock 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_8_R3.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_8_R1.NBTTagCompound in project askyblock 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_8_R2.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_8_R1.NBTTagCompound in project askyblock by tastybento.
the class NMSHandler method getSpawnEgg.
/**
* Get spawn egg
* @param type
* @param amount
* @return
*/
@SuppressWarnings("deprecation")
public ItemStack getSpawnEgg(EntityType type, int amount) {
ItemStack item = new ItemStack(Material.MONSTER_EGG, amount);
net.minecraft.server.v1_9_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tagCompound = stack.getTag();
if (tagCompound == null) {
tagCompound = new NBTTagCompound();
}
NBTTagCompound id = new NBTTagCompound();
id.setString("id", type.getName());
tagCompound.set("EntityTag", id);
stack.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(stack);
}
use of net.minecraft.server.v1_8_R1.NBTTagCompound in project askyblock 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_9_R2.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_8_R1.NBTTagCompound in project solinia3-core by mixxit.
the class SoliniaItemFactory method CreateItem.
public static ISoliniaItem CreateItem(ItemStack itemStack, boolean operatorCreated) throws SoliniaItemException, CoreStateInitException {
SoliniaItem item = new SoliniaItem();
item.setOperatorCreated(operatorCreated);
item.setId(StateManager.getInstance().getConfigurationManager().getNextItemId());
item.setBasename(itemStack.getType().name());
item.setDisplayname(itemStack.getType().name());
if (itemStack.getData() != null) {
try {
item.setColor(itemStack.getData().getData());
} catch (Exception e) {
e.printStackTrace();
}
}
if (itemStack.getType().name().equals("SKULL_ITEM")) {
net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tag = stack.hasTag() ? stack.getTag() : new NBTTagCompound();
tag.getCompound("SkullOwner").getString("Id");
String texturevalue = tag.getCompound("SkullOwner").getCompound("Properties").getList("textures", 10).get(0).getString("Value");
item.setTexturebase64(texturevalue);
}
StateManager.getInstance().getConfigurationManager().addItem(item);
System.out.println("New Item Added: " + item.getId() + " - " + item.getDisplayname());
return item;
}
Aggregations