Easy NBT Tags for Colored Armor and Player Heads

Discussion in 'Resources' started by william9518, Dec 16, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    william9518

    Hi! I heard you wanted to use colored armor ||/&& player heads! It is very easy. You must add CraftBukkit into your Java Build Path though.
    Colored Armor:
    Copy this method into your main plugin class:
    Code:
    public ItemStack setColor(ItemStack item, int color){
            CraftItemStack craftStack = null;
            net.minecraft.server.ItemStack itemStack = null;
            if (item instanceof CraftItemStack) {
            craftStack = (CraftItemStack) item;
            itemStack = craftStack.getHandle();
            }
            else if (item instanceof ItemStack) {
            craftStack = new CraftItemStack(item);
            itemStack = craftStack.getHandle();
            }
            NBTTagCompound tag = itemStack.tag;
            if (tag == null) {
            tag = new NBTTagCompound();
            tag.setCompound("display", new NBTTagCompound());
            itemStack.tag = tag;
            }
       
            tag = itemStack.tag.getCompound("display");
            tag.setInt("color", color);
            itemStack.tag.setCompound("display", tag);
            return craftStack;
        }
    And to color armor, you do something like this:
    Code:
    inventory.addItem(setColor(new ItemStack(Material.LEATHER_HELMET), 0xhexadecimal));
    Player Heads:
    Copy this into main class:
    Code:
    public ItemStack setOwner(ItemStack iitem, String owner){
            net.minecraft.server.ItemStack item = null;
            CraftItemStack stack = null;
            stack = new CraftItemStack(iitem);
            item = stack.getHandle();
            NBTTagCompound tags = item.tag;
            tags = item.tag = new NBTTagCompound();
            if(owner != null && !owner.equals("")) {
                tags.setString("SkullOwner", owner);
            }
            return stack;
        }
    And once again to use it do:
    Code:
    inventory.addItem(setOwner(new ItemStack(Material.SKULL_ITEM, 1, (short)3), nameOfHeadGiven));
    Thanks for viewing!
    william9518
     
  2. Offline

    desht

    Even easier now, that the Bukkit ItemMeta API has gone live. With the latest Bukkit/CraftBukkit builds:
    PHP:
    public ItemStack setOwner(ItemStack itemString owner) {
      
    SkullMeta meta = (SkullMetaitem.getItemMeta();
      
    meta.setOwner(owner);
      
    item.setItemMeta(meta);
      return 
    item;
    }
    And similarly for armour dyeing, book items, maps & potions.

    http://jd.bukkit.org/apidocs/org/bukkit/inventory/meta/ItemMeta.html
     
    hawkfalcon likes this.
  3. Offline

    AmoebaMan

    desht How long is it expected to take before firework star and firework metadatas are implemented? They took their sweet time doing it for these...
     
  4. Offline

    william9518

    Thx for the update
     
  5. Offline

    ZachBora

    So 1.4.6 is out... can't figure out how to create fireworks in code. I'm guessing it's something similar NBTTag?
     
  6. Offline

    Alvarez96

    If you find out, I would apreciate it if you messaged me :)
     
Thread Status:
Not open for further replies.

Share This Page