Question about ItemStack deprecated constructors.

Discussion in 'Plugin Development' started by alex123099, Oct 26, 2013.

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

    alex123099

    Hey all,
    In my plugin I am constructing an ItemStack by using the ID of a specific item, the amount of that item, the damage it has and the meta data.
    This is the constructor I'm using:

    ItemStack i = new ItemStack(id,amount,(short)16,metaData);

    I was wondering, why is this deprecated? And what are other alternatives for this constructor for me to construct and item stack with the meta data?

    Thanks in advance!
     
  2. Offline

    adam753

    IDs are deprecated. Mojang is removing (or already has removed?) block IDs in favour of String names or something like that, which means IDs are also being phased out of Bukkit. Your alternative is the Material enum (eg. Material.COBBLESTONE).

    Better explanation: http://forums.bukkit.org/threads/no-more-block-ids.176817/
     
  3. Offline

    drtshock

    You can use the constructor with Material. Minecraft deprecated item ids and is moving away from them. Best not to start using them now if you don't have to ;3
     
  4. Offline

    xTrollxDudex

    alex123099
    Why would you use an item id? No one really remembers them do they?
     
  5. Offline

    alex123099

    xTrollxDudex drtshock adam753
    I was using IDs as this was the only constructor that had the Byte data parameter. And I need this parameter for the meta data of items, for example wool:5. If item ids are going to be removed, how can I create an ItemStack with meta data? (like stonebrick:2 or wood:4)
     
  6. Offline

    adam753

  7. Offline

    RealDope

    Construct the ItemStack, then use item.getData().setData(byte);

    Or alternatively, if getData() returns a clone of the data (I can't remember), then you'll have to do:
    Code:JAVA
    1.  
    2. MaterialData data = item.getData();
    3. data.setData(byte);
    4. item.setData(data);
    5.  
     
  8. Offline

    NathanWolf

    I can understand deprecating material ids, but deprecating the data bytes is still a mystery to me. You end up just setting it as a byte anyway? Or is there a more proper way to do that part? Are there now enums for all the possible data values of all materials?
     
  9. Offline

    alex123099

    adam753
    I was coding with the 1.6.2 bukkit api and that constructor did not appear to me. But the data variable in this constructor is still causing it to be deprecated.
    I guess what RealDope is saying is the best alternative to what it used to be.
     
Thread Status:
Not open for further replies.

Share This Page