Solved Adding an item to a players inventory with 'data' (Like 233:3/brown wood etc)

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

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

    joehot2000

    Hi, i currently have a very nice shop plugin i am using on my server, with emeralds as currency etc.

    But how do i add an item to a player's inventory with 'data'? Like, brown wood, or the enchanted golden apples?

    I have found nowhere that shows me how to do this.

    Thanks in advance!
     
  2. new ItemStack(material, amount, data) to create such item, then add it to the player's inventory.
     
  3. Offline

    joehot2000

    There is a data? i was just using new itemstack without the 'data' bit! What exactly do i put in the data? is it just an integer?

    Oh. and in that case i have another question, how do i get all characters before or after a certain character (like : )?
     
  4. Yes, a number, a short actually, you need to cast.

    You can also use setDurability(), example with casting:
    Code:
    item.setDurability((short)3);
    However, if you want to use more user-friendly API for data values for certain stuff you can use their designated classes that extend MaterialData... e.g. Wool, Torch, Lever, etc, just create a new instance of that, set some stuff in it then get its data value and set it to your item/block.

    Code:
    ItemStack item = new ItemStack(Material.WOOL); 
    Wool wool = new Wool();
    wool.setColor(DyeColor.BROWN);
    item.setDurability(wool.getData());
    But I belive the official way to do that is to use item.getData() which gives you a MaterialData object and cast that to the required object, not sure.
     
  5. Offline

    joehot2000

    **Removes message**

    Done it!

    Thanks for all your help!! :):cool:
     
  6. Data/damage/durability are the same value.

    In weapons and tools it defines how damaged they are, in other items it defines their color, type, etc. and in blocks it usually defines type, color or position/alignment within the block space, e.g. defines which way a torch is attached to.

    You can find all of them in the MC wiki: http://www.minecraftwiki.net/wiki/Data_value
     
  7. Offline

    joehot2000

    Ooh! Thanks for the info! :)
     
Thread Status:
Not open for further replies.

Share This Page