New way of getting material by id/name?

Discussion in 'Plugin Development' started by boynedmaster, Jun 20, 2014.

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

    boynedmaster

    Material.getMaterial is deprecated, and I read it's because Minecraft is switching from IDs to modname:item (like WOOL:5).
    So how do I do this?
     
  2. Offline

    mythbusterma

    Depends what you're using it for, you can use Block#getType() which returns a Material, which can then be compared to other Material enums, or you can use Material.WOOL as an argument for an ItemStack constructor, to create an item stack of it.
     
  3. Offline

    DragonGCBroZ

    Want the Id? then still use Material.getTypeId();
     
  4. Offline

    boynedmaster

    neither of you have any idea what im saying do you
     
  5. boynedmaster Deprecated isn't the same as doesn't work. So you can still get it by the id, but you're better off by using the name. Relevant methods can be found in the JavaDocs.
     
  6. Offline

    TechNotes

    boynedmaster

    Don't get all huffy, we're just trying to help. Do you want to know how to get a colored wool (a wool w/ metadata) in an ItemStack?
     
  7. Offline

    boynedmaster

    whats the method to get item by the name??????????????????????????????????????????????????????????
     
  8. Offline

    mythbusterma

    Considering how little you said, and how poorly you explained it, no.

    Maybe if you explained what you're trying to do, we could help.

    Perhaps the Material.getMaterial(String) method is what you're looking for?
     
  9. Offline

    boynedmaster

    ok
    lets say i wanted to get the wool by its name WOOL:5
    what would i do to get that
     
  10. Offline

    mythbusterma

    You could try:

    Code:java
    1. String mat = "WOOL:5";
    2. String[] data = mat.split(":");
    3.  
    4. Material material = Material.getMaterial(data[0]);
    5. try{
    6. Byte dataValue = Byte.parseByte(data[1]);
    7. } catch (Exception e) {
    8. e.printStackTrace();
    9. }
    10.  
    11. ItemStack is = new ItemStack(material, <amount>, 0,dataValue);
    12.  


    Make sense?
     
  11. Offline

    boynedmaster

    eh
    i guess
     
Thread Status:
Not open for further replies.

Share This Page