Resource 1.8 to 1.13 Itemstack/material version support

Discussion in 'Spigot Plugin Development' started by Hex_27, Jul 19, 2018.

  1. Sorry, I’m currently unable to handle this resource’s maintenance as of now. As such, I recommend using another resource maintained by another dev at

    Tested mostly in 1.13. Sometimes tested in 1.12. Designed for 1.8-1.13. (20/12/2018) ^
    Using the class:

    Code (Text):
    Code (Text):
    It will give Material.GOLDEN_CHESTPLATE in 1.13 to Material.GOLD_CHESTPLATE in 1.12 depending on which one exists in the current server version.

    Code (Text):
    new ItemStack(Material.WOOL,1,(byte)4);
    Code (Text):
    This gives An itemstack of material YELLOW_WOOL in 1.13, but an itemstack of material WOOL and data 4 in 1.12

    Points to note:
    This is a big, hardcoded solution for 1.8 to 1.13 material/item support. Note that the hardcoding was not scripted, and done to the semi-best of my own knowledge (I'm not sure of the Skulls, Wall banners, Spawn eggs, 1.13 Wood (not planks) and filled flower pots)

    Materials that don't exist in 1.12 will return as either stone, or a close alternative (eg, XMaterial.BRAIN_CORAL.parseMaterial() will give Material.STONE in 1.12)

    Some 1.12 items don't translate well into 1.13 (Like Potato and Potato_item in 1.12 translate into the same thing in 1.13, and there's currently no way to get the specific kind in 1.12 through this resource.)

    I may improve this resource over time on my own, but if you find some problems with it, do let me know in the discussion, and I'll try to fix it up when I have the time. Due to a lack of time, I may fail to integrate larger solutions any time soon (Like supporting block data, fixing up shortcomings like potato item smoothly etc).

    Older XMaterial classes: (9/12/2018)

    Old obsolete code kept here for archiving purposes.
    Using the class:

    Code (Text):
    Code (Text):
    It will give Material.GOLD_CHESTPLATE in 1.12 to Material.GOLDEN_CHESTPLATE in 1.13

    To try and get a 1.13 material:
    Code (Text):
    Tries to get the material (from 1.13) called RED_WOOL, if it doesn't exist, return XMaterial.WOOL.parse();

    It's a pretty flimsy fix for part of 1.13's problems, and it was made pretty quickly (So some of the stuff are a little weird. I've added comments to the ones I'm unsure of (//UNKNOWN or //UNSURE)
    Generated the enum with a script, and manually fixed all the red underlines. By default, returns white or oak for stuff like Material.WOOL, Material.WOOD, Material.LOG

    Before using it, test it yourself. As mentioned above, some of the linked materials may not make sense.
    Enjoy the lazy fix

    EDIT: If someone found a better way, please reply.

    #1 Hex_27, Jul 19, 2018
    Last edited: Jun 16, 2019
    • Useful x 30
    • Like x 11
    • Winner x 6
    • Agree x 1
    • Optimistic x 1
    • Creative x 1
  2. This seems nice, but is there a way to convert item id and damage value to the new material in 1.13 (see this issue)?
  3. Am working on one lol. But I don't have a concrete solution yet

    EDIT: Probably gonna hardcode it too tbh.
  4. After thinking about what Choco said, and some general observations, I want to recode the resource to fit the context of 1.13 to 1.12 instead of 1.12 to 1.13 (since 1.13 names are better). Anyone that wants to use it as it is is free to.
  5. Updated this code to support material names and itemstack name changes.

    I considered Choco's viewpoint and now, XMaterial enum names are built off 1.13 items instead of 1.12 items. As a result, XMaterial is also capable of building 1.12 items with damage values (coloured, damaged anvils, plants) relatively well. My other resource thread (XItemStack) was edited to point here

    hard coding for 4 hours fried my head. Though I really could've scripted some part of it.

    (I'm also gonna have lots of fun literally adding stuff every major update. Sigh.)
    #5 Hex_27, Jul 21, 2018
    Last edited: Jul 21, 2018
  6. Just make two constructors and call other one with default of 0 for data.

    I don't know the exact handling for HashMap but I doubt what you are doing is any faster than just looping the array of values and checking each time you call the method.
  7. The script used to generate the initial list of materials for me to manually parse took about 5 seconds, so I worried. I can remove the hashmap for the search soon when I can get on a laptop.
  8. Updated the class according to @Borlea 's suggestions
  9. Nice resource! I'm going to use it!
  10. Updated.
    Includes a fromString to convert from 1.12 items (Format of Material:ID, eg "INK_SACK:4" for XMaterial.LAPIS_LAZULI
    #10 Hex_27, Jul 27, 2018
    Last edited: Jul 27, 2018
  11. Can you call on a name from 1.12 to get 1.13?
  12. XMaterial.fromString

    You can also use XMaterial.requestMaterial
    • Friendly Friendly x 1
  13. XMaterial.fromString should work that way already. It tries to find a 1.13 material from the name, and if it fails, it will try to find a 1.12 material. The string parsed into the fromString can be expressed in the form:
    • Like Like x 1
    • Agree Agree x 1
  14. I've got to give you a huge 'thank you' for creating this. It's quite a time consuming thing to implement this, but this will help me improving my 1.13 support. Thanks @Hex_27!

    EDIT: Uhm, how about POTATO_ITEM? You've put POTATO but I think you need POTATO_ITEM?
    #15 MrWouter, Aug 12, 2018
    Last edited: Aug 12, 2018
    • Like Like x 1
  15. Changed 1.12 name for Melon from MELON to MELON_BLOCK
    Changed 1.12 name for Mushroom Stew to MUSHROOM_SOUP
    Changed 1.12 name for Potato to POTATO_ITEM
    Changed 1.12 name for carrot to CARROT_ITEM

    These changes weren't tested yet. Check for yourselves before using.
    For those who find issues, it would be appreciated if you're able to find the replacement item that works.
    • Like Like x 1
  16. xD Alright. I confirmed that melon is working now.
  17. 1.8 to 1.13 sounds?
  18. Since I don't directly need sound support, I may not be making it in the near future