public AttributeUtil(ItemStack stack) { // Create a CraftItemStack (under the hood) this.nmsStack = CraftItemStack.asNMSCopy(stack); if (this.nmsStack == null) { return; } // if (nmsStack == null) { // CivLog.error("Couldn't make NMS copyyy of:"+stack); // this.nmsStack = CraftItemStack.asNMSCopy(ItemManager.createItemStack(CivData.WOOL, 1)); // if (this.nmsStack == null) { // return; // } // } // Load NBT if (nmsStack.getTag() == null) { parent = new NBTTagCompound(); nmsStack.setTag(parent); } else { parent = nmsStack.getTag(); } // Load attribute list if (parent.hasKey("AttributeModifiers")) { attributes = parent.getList("AttributeModifiers", NBTStaticHelper.TAG_COMPOUND); } else { /* No attributes on this item detected. */ attributes = new NBTTagList(); parent.set("AttributeModifiers", attributes); } }
public void setName(String name) { if (nmsStack == null) { return; } if (nmsStack.getTag() == null) { nmsStack.setTag(new NBTTagCompound()); } NBTTagCompound displayCompound = nmsStack.getTag().getCompound("display"); if (displayCompound == null) { displayCompound = new NBTTagCompound(); } displayCompound.set("Name", new NBTTagString(ChatColor.RESET + name)); nmsStack.getTag().set("display", displayCompound); }
public void setCivCraftProperty(String key, String value) { if (nmsStack == null) { return; } if (nmsStack.getTag() == null) { nmsStack.setTag(new NBTTagCompound()); } NBTTagCompound civcraftCompound = nmsStack.getTag().getCompound("civcraft"); if (civcraftCompound == null) { civcraftCompound = new NBTTagCompound(); } civcraftCompound.set(key, new NBTTagString(value)); nmsStack.getTag().set("civcraft", civcraftCompound); }
public void setShiny() { if (nmsStack == null) { return; } if (nmsStack.getTag() == null) { nmsStack.setTag(new NBTTagCompound()); } NBTTagCompound enchCompound = nmsStack.getTag().getCompound("ench"); if (enchCompound == null) { enchCompound = new NBTTagCompound(); } enchCompound.setShort("id", (short) 62); // Enchant id 62 = Lure enchCompound.setShort("lvl", (short) 1); nmsStack.getTag().set("ench", enchCompound); this.setHideFlag(1); }
public void addLore(String str) { if (nmsStack == null) { return; } if (nmsStack.getTag() == null) { nmsStack.setTag(new NBTTagCompound()); } // this.lore.add(str); NBTTagCompound displayCompound = nmsStack.getTag().getCompound("display"); if (displayCompound == null) { displayCompound = new NBTTagCompound(); } NBTTagList loreList = displayCompound.getList("Lore", NBTStaticHelper.TAG_STRING); if (loreList == null) { loreList = new NBTTagList(); } loreList.add(new NBTTagString(str)); displayCompound.set("Lore", loreList); nmsStack.getTag().set("display", displayCompound); }