How can I correctly set a Dye into an ItemStack?

Discussion in 'Plugin Development' started by joserobjr, Jul 13, 2014.

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

    joserobjr

    I'm trying to apply a Dye color into an existing ItemStack, how can I do this without using deprecated methods and creating an new stack?

    I tried the following code but it's resulting in a normal ink sack.
    ps: I'm creating an stack in the first line only as example.
    Code:
    final ItemStack stack = new ItemStack(Material.INK_SACK);
    Dye dye = new Dye();
    dye.setColor(DyeColor.LIME);
    stack.setData(dye);
    edit: Added final to stack variable to show that it cannot be replaced by a new stack.
     
  2. Offline

    THEREDBARON24

    You can set the color of an ink sac? I dont believe that is possible.
     
  3. Offline

    TheMcScavenger

     
  4. Offline

    joserobjr

    But using data vaules is risky, they may change in future versions, that's why all data related methods are deprecated. There should be a way to do this without using deprecated methods or creating a new stack.

    I edited my sample code to show that I can't create a new ItemStack where i'm trying to apply the dye.
     
  5. Offline

    Gater12

  6. Offline

    joserobjr

    Gater12 But it creates a new stack...
    I think it's an issue with Bukkit API, if I'm setting the data of an ItemStack using a MaterialData object the ItemStack should also update the damage value, because of that we have to create a new stack every-time we want to change a color or use deprecated methods to set the data using a magic byte value.
     
  7. Offline

    Gater12

    joserobjr
    Isn't this what you want? An ItemStack object?
     
Thread Status:
Not open for further replies.

Share This Page