Solved Howto Give Dyed Leather Armour?

Discussion in 'Plugin Development' started by iZanax, Oct 28, 2012.

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

    iZanax

    Since 1.4, it is possible to Dye Leather Armour,
    But there is no specific ID for the coloured one.
    It has still the same ID as regular Leather Armour,
    So how is possible to give someone Coloured Leather Armour?
     
  2. Offline

    LucasEmanuel

    You probably have to set their data to a specific color. But im unsure if the latest dev builds support colored armor right now.
     
  3. Offline

    iZanax

    new ItemStack(Material.LEATHER_CHESTPLATE, 1, (short) 14)

    I tried this, but only changes the durability.
    So yea if there are other options, it would be nice.
    I thought it was not depending on Version of Bukkit.
     
  4. Offline

    Remi1115

    The Wiki says something about RGB coloring. I'm really hoping we can set our own RGB values for the Leather armour, and make colors that you can't make with the Crafting bench. And like other people said it will probably be data value(s) (just like Wool colors).
     
  5. Offline

    andf54

    Block/ItemStack data is a byte and there are a LOT of different leather colours. Durability can't be used for obvious reasons.
    I think it will be a different value
     
  6. Offline

    stirante

    It's in NBT. As always It's not tested, but better than nothing :p
    Code:java
    1.  
    2. public ItemStack setColor(ItemStack item, int color){
    3. CraftItemStack craftStack = null;
    4. net.minecraft.server.ItemStack itemStack = null;
    5. if (item instanceof CraftItemStack) {
    6. craftStack = (CraftItemStack) item;
    7. itemStack = craftStack.getHandle();
    8. }
    9. else if (item instanceof ItemStack) {
    10. craftStack = new CraftItemStack(item);
    11. itemStack = craftStack.getHandle();
    12. }
    13. NBTTagCompound tag = itemStack.tag;
    14. if (tag == null) {
    15. tag = new NBTTagCompound();
    16. tag.setCompound("display", new NBTTagCompound());
    17. itemStack.tag = tag;
    18. }
    19.  
    20. tag = itemStack.tag.getCompound("display");
    21. tag.setInt("color", color);
    22. itemStack.tag.setCompound("display", tag);
    23. return craftStack;
    24. }


    So now you wil use it like that:
    Code:java
    1. player.setItemInHand(setColor(player.getItemInHand(), 0xFFFFFF))
     
  7. Offline

    iZanax

    I will test it soon, thanks!
     
  8. Offline

    stirante

    It can't be data value, becouse there is 16777215 combinations of colours. If bukkit supports 1.4, it also supports custom colors
     
  9. Offline

    william9518

    Can't import NBTTag or CraftItemStack. Also item is not defined.
     
  10. Offline

    stirante

    You have to add craftbukkit instead of bukkit to project
     
  11. Offline

    william9518

    Uhh.......... where can I download and can I add both??
     
  12. Offline

    stirante

    You can add both. Craftbukkit is file you run your server with.
     
  13. Offline

    william9518

    okay. What is "item" here? item instanceof ItemStack

    nvm! thx

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

    NerdsWBNerds

    Not working as of latest RB, any idea how to make it work?
     
  15. Offline

    stirante

    You don't have to use this code anymore. Use new ItemMeta API.
     
  16. Offline

    iZanax

    Do u got an example for the Colour? stirante

    ItemStack.getItemMeta();
    doesn't give an option to colour it.

    Thanks!
     
  17. Offline

    stirante

    You have to cast it to LeatherArmorMeta.
     
  18. Offline

    fireblast709

    iZanax
    Code:java
    1. ItemStack lhelmet = new ItemStack(Material.LEATHER_HELMET, 1);
    2. LeatherArmorMeta lam = (LeatherArmorMeta)lhelmet.getItemMeta();
    3. lam.setColor(Color.fromRGB(red, green, blue));
    4. lhelmet.setItemMeta(lam);


    NerdsWBNerds CraftItemStack's getHandle() method was removed in exchange for ItemMeta support

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
    SirGregg and zzienzz like this.
  19. Offline

    slipcor

    Just was pointed here, and saw an error :D

    That will definately not return the correct color. Just use Color.fromRGB(red, green, blue) rather than thinking about what the correct << shift value would be... (16 and 8?)
     
  20. Offline

    fireblast709

    Yea my bad. I got told about that after the post, a while ago
     
  21. Offline

    slipcor

    a while ago :D we're talking about a week here :)
     
  22. Offline

    fireblast709

    meh screw time ;3
     
  23. Offline

    _DaBeagle_

    another easy one (i think its part of essentials) is /give [player] [leather item] 1 0 color:[red,green,blue] so for a completely red hat, /give [player] 298 1 0 color:255,0,0
     
  24. Offline

    roughtoast

    Iv figured it out,and heres a list of different color codes, And a break down of the command to hopefully help people understand the command some more :).
    /give [player] 298 1 0 color:255,0,0
    color ,0 <-red syntax,0<-green syntax,0<-blue syntax
    Heres some of the colours im sure you guys are looking for
    Defualt synatax colors
    Red /give [player] 298 1 0 color:255,0,0
    Green /give [player] 298 1 0 color:0,255,0
    blue /give [player] 298 1 0 color:0,0,255

    Default colour codes for minecraft
    Black (&0) 0 0 0
    Dark Blue (&1) 0 0 170
    dark green (&2) 0 170 0
    dark aqua (&3) 0 170 170
    dark red (&4) 170 0 0
    purple &5 170 0 170
    gold (&6) 255 170 0
    gray(&7) 170 170 170
    Dark Gray (8) 85 85 85
    Blue (&9) 85 85 255
    Green (&a) 85 255 85
    Aqua(&b) 85 255 255
    Red (&c) 255 85 85
    Light Purple (&d) 255 85 255
    Yellow (&e)255 255 85
    White &f 255 255 255

    Dyed colours
    Purple Dye-150,50,200
    Cyan Dye-85,130,165
    Light Grey-dye 160,160,160
    Grey Dye-80,80,80
    Pink Dye-250,120,165
    Lime Green dye-127,255,0
    Light Blue dye-125,150,210
    Magenta Dye -175,75,215
    Orange-175,105,33
    Bonemeal-255,255,255
    Cactus Green-113,130,45
    Dandelion Yellow-220,220,45
    Rose Red-150,50,50
    Ink Sac-25,25,25
    Cocoa Beans-100,75,48
    Lapis Lazui-70,70,240 <-little bit off the original gave up after 42 tries
    Please bear in mind that not all colors are spot on,But they are extreamly close.
    this took 2 hours to do just figuring them all out to save all of you guys alot of time and effort
    So please do come and check my server out have some fun and even get some ideas if you like.
    BUT NO ADVERTISING
    Server IP:glsurvival.in
    Break down of the command
    /give [player] 298 1 0 color:255,0,0 - discovered by _DaBeagle_

    /give [player] 298 1 0 color:255,0,0
    /give-gives a player a certain item
    /give [player] -playername goes here ect /give roughtoast
    /give [player] 298 <- item id of leather cap
    /give [player] 298 1 <-amount of caps given to a player for the one command
    /give [player] 298 1 0<-damage put on the cap

    /give [player] 298 1 0 color:0 <- red

    /give [player] 298 1 0 color:0,0<-green

    /give [player] 298 1 0 color:255,0,0,0<-blue
     
Thread Status:
Not open for further replies.

Share This Page