Loading Schematics into a world in 1.14

Discussion in 'Plugin Development' started by QuickScythe, Dec 5, 2019.

  1. Offline


    So I've created a Schematic class that contains a byte array for block ids, I'm sure you've seen this before, it's really generic JNBT biz

    short width = (Short) getChildTag(tagCollection, "Width", ShortTag.class).getValue();
    short height = (Short) getChildTag(tagCollection, "Height", ShortTag.class).getValue();
    short length = (Short) getChildTag(tagCollection, "Length", ShortTag.class).getValue();
    byte[] blocks = (byte[]) getChildTag(tagCollection, "Blocks", ByteArrayTag.class).getValue();
    byte[] data = (byte[]) getChildTag(tagCollection, "Data", ByteArrayTag.class).getValue();
    List entities = (List) getChildTag(tagCollection, "Entities", ListTag.class).getValue();
    List tileentities = (List) getChildTag(tagCollection, "TileEntities", ListTag.class).getValue();
    And that works great and all, but as you all know Minecraft doesn't use numerical IDs for blocks anymore. How can I convert the block ID and it's numerical data into Minecraft's new Material system?

    UPDATE: I've been working on it and I found someone said this cute line of code works
    Bukkit.getUnsafe().fromLegacy(new MaterialData(material, byte));
    So I threw that into a loop, and threw the loop into a method and ended up with something like this
    public static org.bukkit.Material findMaterial(int id, byte data) {
        try {
            for (Material i : EnumSet.allOf(Material.class))
                if (i.getId() == id)
                    return Bukkit.getUnsafe().fromLegacy(new MaterialData(i, data));
        } catch (NullPointerException ex) {
        return Material.AIR;
    I guess I forgot i.getId() wouldn't work anymore because Minecraft took out the numerical IDs but I ran it and got the cute little error:
    java.lang.IllegalArgumentException: Cannot get ID of Modern Material
    Obviously the error points to i.getId() :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Dec 5, 2019
  2. Offline


Share This Page