Solved Dyed Leather Armor

Discussion in 'Plugin Development' started by Higgsboson728, Oct 21, 2015.

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

    Higgsboson728

    Hello, I was wondering how I can spawn a mob with dyed armor. Thanks!
     
  2. Offline

    teej107

    What have you tried so far?
     
  3. Offline

    Higgsboson728

    Code:

    Code:
    Player p = (Player) sender;
                    Location loc = p.getLocation();
                    LivingEntity e = (LivingEntity) p.getWorld().spawnEntity(loc, EntityType.ZOMBIE);
                    if (e.getType() == EntityType.ZOMBIE) {
                        e.getEquipment().setItemInHand(new ItemStack(Material.IRON_SWORD));
                        e.getEquipment().setBoots(new ItemStack(Material.LEATHER_BOOTS));
                    }
    Note that I want Leather boots to be dyed. @teej107
     
  4. Offline

    teej107

    tkuiyeager1 likes this.
  5. Offline

    Higgsboson728

    @teej107 So do I need to add .setColor() after my ItemStack(Material.LEATHER_BOOTS) or am I still missing something?

    or

    ItemStack.getItemMeta();
     
    Last edited: Oct 21, 2015
  6. Offline

    tkuiyeager1

  7. Offline

    Higgsboson728

    Last edited: Oct 21, 2015
  8. Offline

    teej107

  9. Offline

    Higgsboson728

    How should I "cast" it?
     
  10. Offline

    Scimiguy

  11. Offline

    Higgsboson728

    Thanks for the link.

    @Scimiguy
    @teej107
    @tkuiyeager1
    @timtower

    So how do you give the colored armor to a mob? Do you create new variables for each armor part? (boots, chestplate, etc)

    like this

    Code:
    Player p = (Player) sender;
                    Location loc = p.getLocation();
                    LivingEntity e = (LivingEntity) p.getWorld().spawnEntity(loc, EntityType.ZOMBIE);
                    if (e.getType() == EntityType.ZOMBIE) {
                        ItemStack boots = new ItemStack(Material.LEATHER_BOOTS);
                        LeatherArmorMeta meta = (LeatherArmorMeta) boots.getItemMeta();
                        meta.setColor(Color.BLUE);
                          boots.setItemMeta(meta);
                        ItemStack leggings = new ItemStack(Material.LEATHER_LEGGINGS);
                        LeatherArmorMeta meta1 = (LeatherArmorMeta) leggings.getItemMeta();
                        meta1.setColor(Color.BLUE);
                          leggings.setItemMeta(meta1);
                    e.getEquipment().setItemInHand(new ItemStack(Material.IRON_SWORD));
                    e.getEquipment().setBoots((ItemStack) meta);
                    }
     
    Last edited: Oct 22, 2015
  12. Offline

    Higgsboson728

  13. Offline

    Scimiguy

    @Higgsboson728
    Yeah just create one LeatherArmorMeta, and one ItemStack for each part of armor. You can re-use the Meta for each piece since you're only changing the colour.
     
    Higgsboson728 likes this.
  14. Offline

    Higgsboson728

    Thanks. I got it now. :)
     
  15. Offline

    Scimiguy

  16. Offline

    Higgsboson728

Thread Status:
Not open for further replies.

Share This Page