Solved Dying leather armour?

Discussion in 'Plugin Development' started by joehot2000, Mar 11, 2013.

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

    joehot2000

    Ok, i have got a nice zombie, he has some nice leather armour.

    Entity spawnedNinja = ent.getWorld().spawnEntity(ent.getLocation(), EntityType.ZOMBIE);
    Zombie ninja = (Zombie) spawnedNinja;
    ninja.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY,2147483647, 2));
    ninja.getEquipment().setHelmet(new....... etc etc etc.

    But, now he has his nice ol' leather armour, how do i dye it?
     
  2. Offline

    Deleted user


    Use this method I made :)

    Code:java
    1.  
    2. public ItemStack colorLeatherArmor(Material material, Color color) {
    3. ItemStack item = new ItemStack(material);
    4. LeatherArmorMeta meta = (LeatherArmorMeta) item.getItemMeta();
    5. meta.setColor(color);
    6. item.setItemMeta(meta);
    7.  
    8. return item;
    9. }
    10.  


    Use it like so:

    Code:
    ItemStack boots = colorLeatherArmor(Material.LEATHER_BOOTS, Color.BLUE);
    
     
  3. Offline

    joehot2000

    Thanks! this works, My new ninja mob will be on endcraft soon :D!


    ninja.getEquipment().setChestplate(new ItemStack(299, 1));
    ItemStack item = ninja.getEquipment().getChestplate();
    LeatherArmorMeta meta = (LeatherArmorMeta) item.getItemMeta();
    meta.setColor(Color.BLACK);
    item.setItemMeta(meta);

    Thats my code now, and it isnt working,

    Whats wrong?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  4. Offline

    macguy8

    You're setting the chest plate, getting it back, and changing it in your code. You're never re-applying it to the zombie. You'll want to create the ItemStack, dye it, and then set it, where as now you're applying it, creating it, and dying it, but you aren't re-setting it
     
  5. macguy8
    ItemStack is mutable so it should work like that...

    joehot2000
    Why don't you just use the method Eballer48 wrote for you ? It's alot easier to use.
     
  6. Offline

    joehot2000

    I am not understanding how it works, i mean, yes, i have got this nice "new itemstack" which is boots, but then how do i apply that to...

    Ohh.....

    must have been tired last night.

    Thanks.
    Oh, whoops!

    Didnt realise that!

    Thanks!
     
Thread Status:
Not open for further replies.

Share This Page