Solved new ItemStack(..., Byte data) deprecated?

Discussion in 'Plugin Development' started by AmShaegar, Feb 23, 2013.

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

    AmShaegar

    Hey,

    I feel like this is a stupid question but before I mess up everything I would like to ask you: How to create colored wool and add it to the players inventory? The ItemStack contructor is deprecated and those two methods I tried did not work:

    Code:
    ItemStack flag = new ItemStack(Material.WOOL);
    flag.setData(new Wool(selectedTeam.getColor())); //getColor() : DyeColor
    player.getInventory().addItem(flag);
    Wool is not colored.

    Code:
    player.getInventory().addItem(new Wool(selectedTeam.getColor()).toItemStack());
    Wool is colored but disappears when placing it. No BlockPlace event is issued.

    Tried another one similar to the code to colorize armor. Wool is not colored.
    Code:
    ItemStack flag = new ItemStack(Material.WOOL);
    Wool wool = (Wool) flag.getData();
    wool.setColor(selectedTeam.getColor());
    flag.setData(wool);
    player.getInventory().addItem(flag);
    // Edit:
    Okay, I found the solution by myself. toItemStack() sets the amount to 0 as it can be seen here:
    Code:
    public ItemStack toItemStack() {
        return new ItemStack(type, 0, data);
    }
    I have to use toItemStack(1). Anyway, I am still interested why the above method does not work.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
Thread Status:
Not open for further replies.

Share This Page