1.8.8 getId() and getData deprecated

Discussion in 'Spigot Plugin Development' started by PabloX11, Mar 22, 2020.

    • Optimistic Optimistic x 1
  1. Compare the type.
     
  2. Wthat?
     
  3. Compare ItemStack#getType() with the right Material.
     
  4. I'm not understanding you, write it
     
    • Optimistic Optimistic x 1
  5. If you want someone to write the code for you, you should take a look at the Service and Recruitment section.
     
    • Agree Agree x 1
  6. I don't want anyone to write the code for me, I write it myself ...
     
  7. The ItemStack has a method called getType. It returns an Material object representing the material. You can compare it with the equals-operator with another Material object.
     
  8. He's saying to do this:
    Code (Text):

    ... event.getBlock().getType() == Material.AZURE_BLUET ...
     
    getId() and getData() are deprecated because they use raw magic numbers that you'd have to look up. Luckily, you can just compare the Material object returned by getType() to see what it is, in this case 38:3 is an azure bluet.
     
  9. I already tried those, but I would like to enter the id of the block, there are items that I want to add that do not leave me that way...
     
  10. Material.AZURE_BLUET wouldn't exist in 1.8.8 they'd all be classified under either RED_ROSE or YELLOW_FLOWER, if you'd try to compare for example item.getType() of Stone Bricks to a Material of Cracked Stone Bricks it would return true because the type is indeed correct but it's ignoring it's data value of cracked stone bricks being like 98:2 (it's just checking that 98 == 98 basically ignoring any :number after it), this is how it works at least in 1.12.2 so I assume the same is said for a version lower.

    to OP: There's no non-deprecated way to get the sub id / data value of an item/block, you'll just have to deal with that. I think you could compare itemStacks to get everything about the item you're comparing though (that won't work for blocks though) and get if everything excluding the amount is the same as the item you're comparing it too if you use like ItemStack#isSimilar(itemStack).
     
  11. Choco

    Moderator

    There was Bukkit's attempt at a wrapper for magic data values, MaterialData. It wasn't entirely complete but a lot of blocks and items were covered by this. For instance, the different types of wood. Though we now live in modern times and in versions that aren't almost 6 years old, we have Material constants for all blocks.
     
    • Like Like x 1
  12. http://prntscr.com/rkmclp

    is that I need to put the id 31: 1, and if I put the TALLGRASS it tells me that there is no such block
     

    Attached Files:

  13. well that's because like I said in 1.12.2 and lower (I think 1.13 is when it began to have their own block names for each and every sub id version of a block) they aren't called by their minecraft names so Material.TALL_GRASS wouldn't exist and what you would need to do is:
    Code (Text):
    event.getBlock().getType() == Material.GRASS && event.getBlock().getData() == 1
    at least I think #getData() is the proper one.
     
  14. http://prntscr.com/rkmgt4
    again to the same as before...
     
  15.  
  16. Choco

    Moderator

    getData() will always be deprecated. It was deprecated because they're meaningless and arbitrary values that had no good alternative. Having constant numbers in your code to denote a state is seriously discouraged and is the reason it was deprecated. Unless you have an alternative with MaterialData, you will never get around that deprecation. Suppress it and move on or update to a modern version
     
  17. If you use a 6 year old version, you obviously have to use deprecated methods. That is like using a 20-year-old car and asking why it is not the fastest or why it has a deprecated engine.
     
    • Funny Funny x 1
  18. Choco

    Moderator

    These methods were deprecated in the 1.8 API already anyways (was done way before this time as well) for the reasons I mentioned above. Magic values. This version just had an incomplete alternative.
     
    • Informative Informative x 3
  19. you need to check if the item/block is null and is air...