use of net.minecraft.server.v1_10_R1.NBTTagList 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_9_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_10_R1.NBTTagList in project Ublisk by Derkades.
the class Sword method getItemStack.
@Override
public ItemStack getItemStack() {
Item item = new Item(this.getMaterial()).setName(this.getColoredName()).setLore(this.getLore());
NBTTagList modifiers = new NBTTagList();
NBTTagCompound damage = new NBTTagCompound();
damage.setString("AttributeName", "generic.attackDamage");
damage.setString("Name", "generic.attackDamage");
damage.setDouble("Amount", this.getDamage());
damage.setInt("Operation", 1);
damage.setInt("UUIDLeast", 652);
damage.setInt("UUIDMost", 12098);
modifiers.add(damage);
if (this.getMovementSpeed() != -1) {
NBTTagCompound speed = new NBTTagCompound();
speed.setString("AttributeName", "generic.movementSpeed");
speed.setString("Name", "generic.movementSpeed");
speed.setDouble("Amount", this.getMovementSpeed());
speed.setInt("Operation", 1);
speed.setInt("UUIDLeast", 652);
speed.setInt("UUIDMost", 12098);
modifiers.add(speed);
}
if (this.getAttackSpeed().getValue() != -1) {
NBTTagCompound attackSpeed = new NBTTagCompound();
attackSpeed.setString("AttributeName", "generic.attackSpeed");
attackSpeed.setString("Name", "generic.attackSpeed");
attackSpeed.setDouble("Amount", this.getAttackSpeed().getValue());
attackSpeed.setInt("Operation", 1);
attackSpeed.setInt("UUIDLeast", 652);
attackSpeed.setInt("UUIDMost", 12098);
modifiers.add(attackSpeed);
}
if (this.getKnockbackResistance() != -1) {
NBTTagCompound knockback = new NBTTagCompound();
knockback.setString("AttributeName", "generic.knockbackResistance");
knockback.setString("Name", "generic.knockbackResistance");
knockback.setDouble("Amount", this.getKnockbackResistance());
knockback.setInt("Operation", 1);
knockback.setInt("UUIDLeast", 652);
knockback.setInt("UUIDMost", 12098);
modifiers.add(knockback);
}
NBTTagCompound compound = item.getNBT();
compound.set("AttributeModifiers", modifiers);
compound.setInt("HideFlags", 7);
compound.setBoolean("Unbreakable", true);
item.setNBT(compound);
item.setDamage(this.getDamage());
return item.getItemStack();
}
Aggregations