Solved Unique material ID

Discussion in 'Spigot Help' started by Bean900, Apr 17, 2017.

  1. Hello,
    I am looking for quite a while but can not find a solution.
    Is there a way to get a unique material ID in Spigot 1.11 and set it again later.
    I know I can set the material type. But ,for example, there are also several types of wood in one material type.
    It is important to me that the method to be used is not deprecated.
    Can you help me?

    Thanks
    Bean
     
  2. Press F3+H ingame than you can see the id in your inventory if you are hold your mouse on it.
     
  3. an how do i get this number in my Programmcode?
     
  4. You can use the data:
    "MaterialData material = new MaterialData(type, data);"

    For example (Birchwood):
    "MaterialData material = new MaterialData(Material.WOOD, (byte) 2);"
     
  5. Thanks,
    Found this too.
    Only problem is:
    The method getData() and new MaterialData(type, data) in the object MaterialData is deprecated.
    So if a method is deprecated there must be another way... Or am i wrong?
     
  6. You need to use it's state. Use b.getState().getData(). Should works fine, at least for me it worked :D
     
  7. Mh this method is only for Blocks and the method is deprecated too :(.
    I do not understand why spigot is deprecating methods and doesn't give a alternativ....
     
    #7 Bean900, Apr 18, 2017
    Last edited: Apr 18, 2017
  8. Well, i used it for getting the data of the block and it not deprecated.
    That method up it's for blocks, which i what i suppose you are trying to do, am i right?
     
  9. md_5

    Administrator Developer

    The idiomatic way to do this is with org.bukkit.material.Wood and org.bukkit.TreeSpecies for the data conversion which leaves no hardcoded "magic values" (but still uses one deprecated setData call).
    Read the Javadocs to understand why stuff is deprecated and why alternatives are sometimes unavailable (but in this case you have the above to remove the use of magic values, so the subsequent deprecated usage is irrlevant). What is being discouraged by the deprecation is hardcoding numbers like 2, when TreeSpecies.BIRCH is sufficient.
     
    • Like Like x 1
  10. For everyone who comes across this post. To set the DataValue use the constructor:
    ItemStack (Material type, int amount, short damage)

    For the value "damage" put the "Data" value