How do I check if a material is equal to another material with 1.13?

Discussion in 'Spigot Plugin Development' started by forseth11, Aug 4, 2018.

  1. In 1.13 data values have been done with and now they each have their own material.

    How can I compare two materials that would be equal in an other minecraft version, but not in 1.13.

    For example, I want to check if BROWN_WOOL is equal to RED_WOOL which I want to be true.
    Example 2: I want JUNGLE_STAIRS to equal OAK_STAIRS. I also want LEGACY_STAIRS to equal the same.

    What method should I use, or will I have to create my own?
     
  2. Choco

    Moderator

    1. Legacy materials should not be used, especially if you're compiling against the 1.13 API. If that's the API you're compiling against, legacy materials won't be of much use to you anyways because your plugin will error in any previous versions given that you're using the new 1.13 api-version flag in the plugin.yml
    2. See the Tag interface and its constants. For your two examples, Tag.STAIRS and Tag.WOOL. To check whether a material is a part of that tag, it's as easy as calling #isTagged(Material)
    Code (Java):
    if (Tag.STAIRS.isTagged(Material.OAK_STAIRS)) {
        // True
    }
    if (Tag.STAIRS.isTagged(Material.ACACIA_STARS)) {
        // True
    }
     
    • Informative Informative x 1
  3. 1. The alternative is way too much work, and I have already created a way to make it work in different versions on my plugin updates. That is not the issue. I support using the new kind of materials with my config, but for backwards compatibility, I want to allow both.

    2. Thank you!
     
  4. You might wanna check out Hex_27's 1.8 to 1.13 materials class.
     
  5. Link please?
     
    • Like Like x 1