Search in sources :

Example 1 with IBlockDataHandle

use of com.bergerkiller.generated.net.minecraft.world.level.block.state.IBlockDataHandle in project BKCommonLib by bergerhealer.

the class MaterialDataToIBlockData method initBuilders.

// Only called after MC 1.13, before that everything was fine!
private static void initBuilders() {
    if (getLegacyMaterial("REDSTONE_COMPARATOR_OFF") != null) {
        iblockdataBuilders.put(getLegacyMaterial("REDSTONE_COMPARATOR_OFF"), (IBlockDataHandle iblockdata, org.bukkit.material.Comparator comparator) -> {
            iblockdata = iblockdata.set("powered", false);
            iblockdata = iblockdata.set("facing", comparator.getFacing());
            iblockdata = iblockdata.set("mode", comparator.isSubtractionMode() ? "subtract" : "compare");
            return iblockdata;
        });
    }
    if (getLegacyMaterial("REDSTONE_COMPARATOR_ON") != null) {
        iblockdataBuilders.put(getLegacyMaterial("REDSTONE_COMPARATOR_ON"), (IBlockDataHandle iblockdata, org.bukkit.material.Comparator comparator) -> {
            iblockdata = iblockdata.set("powered", true);
            iblockdata = iblockdata.set("facing", comparator.getFacing());
            iblockdata = iblockdata.set("mode", comparator.isSubtractionMode() ? "subtract" : "compare");
            return iblockdata;
        });
    }
    iblockdataBuilders.put(getLegacyMaterial("DOUBLE_STEP"), (IBlockDataHandle iblockdata, org.bukkit.material.Step step) -> iblockdata.set("type", "double"));
    iblockdataBuilders.put(getLegacyMaterial("MOB_SPAWNER"), (iblockdata, spawner) -> getBlockDataFromMaterialName("SPAWNER"));
    iblockdataBuilders.put(getLegacyMaterial("TORCH"), (IBlockDataHandle iblockdata, org.bukkit.material.Torch torch) -> {
        if (torch.getAttachedFace() == BlockFace.DOWN) {
            iblockdata = getBlockDataFromMaterialName("TORCH");
            return iblockdata;
        } else {
            iblockdata = getBlockDataFromMaterialName("WALL_TORCH");
            return iblockdata.set("facing", torch.getFacing());
        }
    });
    // Name remapping without special MaterialData
    storeLegacyRemap("MELON_BLOCK", "MELON");
    // Signs
    {
        IBlockDataBuilder<org.bukkit.material.Sign> builder = new IBlockDataBuilder<org.bukkit.material.Sign>() {

            final IBlockDataHandle wall_sign_data = getBlockDataFromMaterialName(CommonCapabilities.HAS_MATERIAL_SIGN_TYPES ? "OAK_WALL_SIGN" : "WALL_SIGN");

            final IBlockDataHandle sign_post_data = getBlockDataFromMaterialName(CommonCapabilities.HAS_MATERIAL_SIGN_TYPES ? "OAK_SIGN" : "SIGN");

            @Override
            public IBlockDataHandle create(IBlockDataHandle iblockdata, org.bukkit.material.Sign sign) {
                if (CommonLegacyMaterials.isLegacy(sign.getItemType())) {
                    iblockdata = sign.isWallSign() ? wall_sign_data : sign_post_data;
                }
                if (sign.isWallSign()) {
                    return iblockdata.set("facing", sign.getFacing());
                } else {
                    return iblockdata.set("rotation", (int) sign.getData());
                }
            }
        };
        iblockdataBuilders.put(getLegacyMaterial("WALL_SIGN"), builder);
        iblockdataBuilders.put(getLegacyMaterial("SIGN_POST"), builder);
    }
    // Chests
    {
        Material[] legacy_types = MaterialsByName.getAllByName("LEGACY_CHEST", "LEGACY_ENDER_CHEST", "LEGACY_TRAPPED_CHEST");
        String[] modern_names = new String[] { "CHEST", "ENDER_CHEST", "TRAPPED_CHEST" };
        for (int n = 0; n < legacy_types.length; n++) {
            final Material legacy_type = legacy_types[n];
            final IBlockDataHandle modern_data = getBlockDataFromMaterialName(modern_names[n]);
            iblockdataBuilders.put(legacy_type, (IBlockDataHandle iblockdata, org.bukkit.material.DirectionalContainer directional) -> modern_data.set("facing", directional.getFacing()));
        }
    }
}
Also used : IBlockDataHandle(com.bergerkiller.generated.net.minecraft.world.level.block.state.IBlockDataHandle) MaterialsByName.getLegacyMaterial(com.bergerkiller.bukkit.common.internal.legacy.MaterialsByName.getLegacyMaterial) Material(org.bukkit.Material)

Example 2 with IBlockDataHandle

use of com.bergerkiller.generated.net.minecraft.world.level.block.state.IBlockDataHandle in project BKCommonLib by bergerhealer.

the class MaterialDataToIBlockData method getIBlockData.

/**
 * Converts MaterialData to the best appropriate IBlockData value
 *
 * @param materialdata
 * @return IBlockData
 */
public static IBlockDataHandle getIBlockData(MaterialData materialdata) {
    if (materialdata == null) {
        throw new IllegalArgumentException("MaterialData == null");
    }
    if (materialdata.getItemType() == null) {
        throw new IllegalArgumentException("MaterialData getItemType() == null");
    }
    Material legacyType = IBlockDataToMaterialData.toLegacy(materialdata.getItemType());
    IBlockDataBuilder<MaterialData> builder = CommonUtil.unsafeCast(iblockdataBuilders.get(legacyType));
    try {
        IBlockDataHandle blockData = IBlockDataHandle.createHandle(craftBukkitgetIBlockData.invoke(null, materialdata));
        if (builder != null) {
            // Convert using createData to fix up a couple issues with MaterialData Class typing
            materialdata = IBlockDataToMaterialData.createMaterialData(materialdata.getItemType(), legacyType, materialdata.getData());
            blockData = builder.create(blockData, materialdata);
        }
        return blockData;
    } catch (Throwable t) {
        Logging.LOGGER_REGISTRY.log(Level.SEVERE, "Failed to retrieve IBlockData for " + materialdata, t);
        return BlockHandle.T.getBlockData.invoke(BlocksHandle.AIR);
    }
}
Also used : IBlockDataHandle(com.bergerkiller.generated.net.minecraft.world.level.block.state.IBlockDataHandle) MaterialsByName.getLegacyMaterial(com.bergerkiller.bukkit.common.internal.legacy.MaterialsByName.getLegacyMaterial) Material(org.bukkit.Material) MaterialData(org.bukkit.material.MaterialData)

Example 3 with IBlockDataHandle

use of com.bergerkiller.generated.net.minecraft.world.level.block.state.IBlockDataHandle in project BKCommonLib by bergerhealer.

the class BlockDataImpl method setState.

@Override
public BlockData setState(String key, Object value) {
    IBlockDataHandle updated_data = this.data.set(key, value);
    BlockData data = BY_BLOCK_DATA.get(updated_data.getRaw());
    if (data != null) {
        return data;
    } else {
        return BY_BLOCK_DATA.create(updated_data);
    }
}
Also used : IBlockDataHandle(com.bergerkiller.generated.net.minecraft.world.level.block.state.IBlockDataHandle) MaterialDataToIBlockData(com.bergerkiller.bukkit.common.internal.legacy.MaterialDataToIBlockData)

Example 4 with IBlockDataHandle

use of com.bergerkiller.generated.net.minecraft.world.level.block.state.IBlockDataHandle in project BKCommonLib by bergerhealer.

the class BlockDataImpl method setState.

@Override
public BlockData setState(BlockState<?> state, Object value) {
    IBlockDataHandle updated_data = this.data.set(state.getBackingHandle(), value);
    BlockData data = BY_BLOCK_DATA.get(updated_data.getRaw());
    if (data != null) {
        return data;
    } else {
        return BY_BLOCK_DATA.create(updated_data);
    }
}
Also used : IBlockDataHandle(com.bergerkiller.generated.net.minecraft.world.level.block.state.IBlockDataHandle) MaterialDataToIBlockData(com.bergerkiller.bukkit.common.internal.legacy.MaterialDataToIBlockData)

Example 5 with IBlockDataHandle

use of com.bergerkiller.generated.net.minecraft.world.level.block.state.IBlockDataHandle in project BKCommonLib by bergerhealer.

the class IBlockDataToMaterialData method initMaterialDataMap.

// Only called on MC >= 1.13
private static void initMaterialDataMap() {
    {
        MaterialData materialdata = new MaterialData(MaterialsByName.getMaterial("LEGACY_DOUBLE_STEP"));
        for (byte data = 0; data < 8; data++) {
            materialdata.setData(data);
            IBlockDataHandle iblockdata = MaterialDataToIBlockData.getIBlockData(materialdata);
            storeMaterialData(iblockdata.set("waterlogged", true), materialdata);
            storeMaterialData(iblockdata.set("waterlogged", false), materialdata);
        }
    }
    storeMaterialDataGen("LEGACY_REDSTONE_COMPARATOR_OFF", 0, 7);
    storeMaterialDataGen("LEGACY_REDSTONE_COMPARATOR_ON", 0, 7);
    storeMaterialDataGen("LEGACY_PORTAL", 1, 2);
    // Store 5 unique kinds of wood types for some materials that don't exist on MC 1.12.2, and thus have no legacy type
    // A littly hacky, because MaterialData should only use legacy materials, but in this instance it can work
    // Buttons
    {
        new CustomMaterialDataBuilder<org.bukkit.material.Button>() {

            @Override
            public org.bukkit.material.Button create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
                return new org.bukkit.material.Button(material_type, legacy_data_value);
            }

            @Override
            public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.Button button) {
                iblockdata = iblockdata.set("powered", button.isPowered());
                BlockFace facing = button.getFacing();
                if (!FaceUtil.isVertical(facing)) {
                    return Arrays.asList(iblockdata.set("face", "WALL").set("facing", facing));
                }
                iblockdata = iblockdata.set("face", (facing == BlockFace.UP) ? "FLOOR" : "CEILING");
                return Arrays.asList(iblockdata.set("facing", BlockFace.NORTH), iblockdata.set("facing", BlockFace.EAST), iblockdata.set("facing", BlockFace.SOUTH), iblockdata.set("facing", BlockFace.WEST));
            }
        }.setTypes("JUNGLE_BUTTON", "SPRUCE_BUTTON", "ACACIA_BUTTON", "BIRCH_BUTTON", "DARK_OAK_BUTTON", "OAK_BUTTON", "STONE_BUTTON").addTypesIf(Common.evaluateMCVersion(">=", "1.16"), "CRIMSON_BUTTON", "WARPED_BUTTON", "POLISHED_BLACKSTONE_BUTTON").addTypesIf(Common.evaluateMCVersion(">=", "1.17"), "POLISHED_BLACKSTONE_BUTTON").setDataValues(0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13).build();
    }
    // Levers
    {
        new CustomMaterialDataBuilder<org.bukkit.material.Lever>() {

            @Override
            public org.bukkit.material.Lever create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
                return new org.bukkit.material.Lever(material_type, legacy_data_value);
            }

            @Override
            public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.Lever button) {
                iblockdata = iblockdata.set("powered", button.isPowered());
                BlockFace attached = button.getAttachedFace();
                if (attached == BlockFace.UP) {
                    // Attached to the ceiling
                    // Facing controls what direction the lever points
                    // However, legacy only supports ambiguous {north/south} and {east/west}
                    BlockFace facing = ((button.getData() & 0x7) == 0x7) ? BlockFace.NORTH : BlockFace.EAST;
                    iblockdata = iblockdata.set("face", "ceiling");
                    return Arrays.asList(iblockdata.set("facing", facing), iblockdata.set("facing", facing.getOppositeFace()));
                } else if (attached == BlockFace.DOWN) {
                    // Attached to the floor
                    // Facing controls what direction the lever points
                    // However, legacy only supports ambiguous {north/south} and {east/west}
                    BlockFace facing = ((button.getData() & 0x7) == 5) ? BlockFace.NORTH : BlockFace.EAST;
                    iblockdata = iblockdata.set("face", "floor");
                    return Arrays.asList(iblockdata.set("facing", facing), iblockdata.set("facing", facing.getOppositeFace()));
                } else {
                    // Attached to a wall, facing = orientation on block
                    iblockdata = iblockdata.set("face", "wall");
                    iblockdata = iblockdata.set("facing", button.getFacing());
                    return Collections.singletonList(iblockdata);
                }
            }
        }.setTypes("LEVER").setDataValues(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).build();
    }
    // Pressureplates
    {
        new CustomMaterialDataBuilder<org.bukkit.material.PressurePlate>() {

            @Override
            public org.bukkit.material.PressurePlate create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
                return new org.bukkit.material.PressurePlate(material_type, legacy_data_value);
            }

            @Override
            public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.PressurePlate plate) {
                return Arrays.asList(iblockdata.set("powered", plate.isPressed()));
            }
        }.setTypes("JUNGLE_PRESSURE_PLATE", "SPRUCE_PRESSURE_PLATE", "ACACIA_PRESSURE_PLATE", "BIRCH_PRESSURE_PLATE", "DARK_OAK_PRESSURE_PLATE").addTypesIf(Common.evaluateMCVersion(">=", "1.16"), "CRIMSON_PRESSURE_PLATE", "WARPED_PRESSURE_PLATE", "POLISHED_BLACKSTONE_PRESSURE_PLATE").addTypesIf(Common.evaluateMCVersion(">=", "1.17"), "POLISHED_BLACKSTONE_PRESSURE_PLATE").setDataValues(0, 1).build();
    }
    // Burning and not burning furnace (now both the same material, was separate legacy materials)
    for (boolean burning : new boolean[] { true, false }) {
        new CustomMaterialDataBuilder<org.bukkit.material.Furnace>() {

            @Override
            public Material toLegacy(Material m) {
                return CommonLegacyMaterials.getLegacyMaterial(burning ? "BURNING_FURNACE" : "FURNACE");
            }

            @Override
            public org.bukkit.material.Furnace create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
                return new org.bukkit.material.Furnace(toLegacy(material_type), legacy_data_value);
            }

            @Override
            public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.Furnace furnace) {
                return Collections.singletonList(iblockdata.set("facing", furnace.getFacing()).set("lit", burning));
            }
        }.setTypes("FURNACE").setDataValues(2, 3, 4, 5).build();
    }
    // Wall torch
    {
        new CustomMaterialDataBuilder<org.bukkit.material.Torch>() {

            @Override
            public org.bukkit.material.Torch create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
                return new org.bukkit.material.Torch(legacy_data_type, legacy_data_value);
            }

            @Override
            public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.Torch torch) {
                return Collections.singletonList(iblockdata.set("facing", torch.getFacing()));
            }
        }.setTypes("WALL_TORCH").setDataValues(1, 2, 3, 4).build();
    }
    // Wall redstone torch
    for (boolean lit : new boolean[] { true, false }) {
        new CustomMaterialDataBuilder<org.bukkit.material.RedstoneTorch>() {

            @Override
            public Material toLegacy(Material m) {
                return CommonLegacyMaterials.getLegacyMaterial(lit ? "REDSTONE_TORCH_ON" : "REDSTONE_TORCH_OFF");
            }

            @Override
            public org.bukkit.material.RedstoneTorch create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
                return new org.bukkit.material.RedstoneTorch(toLegacy(material_type), legacy_data_value);
            }

            @Override
            public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.RedstoneTorch torch) {
                return Collections.singletonList(iblockdata.set("facing", torch.getFacing()).set("lit", lit));
            }
        }.setTypes("REDSTONE_WALL_TORCH").setDataValues(1, 2, 3, 4).build();
    }
    // Redstone Wire has north/east/south/west metadata too, which also have to be registered
    // Format: minecraft:redstone_wire[east=side,north=none,power=12,south=none,west=none]
    {
        new CustomMaterialDataBuilder<org.bukkit.material.RedstoneWire>() {

            @Override
            public org.bukkit.material.RedstoneWire create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
                return new org.bukkit.material.RedstoneWire(material_type, legacy_data_value);
            }

            @Override
            public List<IBlockDataHandle> createStates(IBlockDataHandle wire_data, org.bukkit.material.RedstoneWire wire) {
                final String[] SIDE_VALUES = { "up", "side", "none" };
                ArrayList<IBlockDataHandle> variants = new ArrayList<IBlockDataHandle>(3 * 3 * 3 * 3);
                wire_data = wire_data.set("power", wire.getData());
                for (String side_north : SIDE_VALUES) {
                    wire_data = wire_data.set("north", side_north);
                    for (String side_east : SIDE_VALUES) {
                        wire_data = wire_data.set("east", side_east);
                        for (String side_south : SIDE_VALUES) {
                            wire_data = wire_data.set("south", side_south);
                            for (String side_west : SIDE_VALUES) {
                                wire_data = wire_data.set("west", side_west);
                                variants.add(wire_data);
                            }
                        }
                    }
                }
                return variants;
            }

            @Override
            public Material fromLegacy(Material legacyMaterial) {
                return CommonLegacyMaterials.getMaterial("REDSTONE_WIRE");
            }
        }.setTypes("LEGACY_REDSTONE_WIRE").setDataValues(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).build();
    }
    // Chests
    {
        Material[] legacy_types = CommonLegacyMaterials.getAllByName("LEGACY_CHEST", "LEGACY_ENDER_CHEST", "LEGACY_TRAPPED_CHEST");
        Material[] modern_types = CommonLegacyMaterials.getAllByName("CHEST", "ENDER_CHEST", "TRAPPED_CHEST");
        for (int n = 0; n < legacy_types.length; n++) {
            final Material legacy_type = legacy_types[n];
            final Material modern_type = modern_types[n];
            final boolean isEnderChest = (n == 1);
            new CustomMaterialDataBuilder<org.bukkit.material.DirectionalContainer>() {

                @Override
                public org.bukkit.material.DirectionalContainer create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
                    if (isEnderChest) {
                        org.bukkit.material.EnderChest chest = new org.bukkit.material.EnderChest();
                        chest.setData(legacy_data_value);
                        return chest;
                    } else {
                        return new org.bukkit.material.Chest(material_type, legacy_data_value);
                    }
                }

                @Override
                public List<IBlockDataHandle> createStates(IBlockDataHandle chest_data, org.bukkit.material.DirectionalContainer chest) {
                    chest_data = chest_data.set("facing", chest.getFacing());
                    return Arrays.asList(chest_data.set("waterlogged", true).set("type", "SINGLE"), chest_data.set("waterlogged", true).set("type", "LEFT"), chest_data.set("waterlogged", true).set("type", "RIGHT"), chest_data.set("waterlogged", false).set("type", "SINGLE"), chest_data.set("waterlogged", false).set("type", "LEFT"), chest_data.set("waterlogged", false).set("type", "RIGHT"));
                }

                @Override
                public Material fromLegacy(Material legacyMaterial) {
                    return modern_type;
                }

                @Override
                public Material toLegacy(Material material) {
                    return legacy_type;
                }
            }.setTypes(legacy_type, modern_type).setDataValues(2, 3, 4, 5).build();
        }
    }
    // Ladder can also be waterlogged since MC 1.15
    {
        new CustomMaterialDataBuilder<org.bukkit.material.Ladder>() {

            @Override
            public org.bukkit.material.Ladder create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
                return new org.bukkit.material.Ladder(legacy_data_type, legacy_data_value);
            }

            @Override
            public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.Ladder ladder) {
                IBlockDataHandle base = iblockdata.set("facing", ladder.getFacing());
                return Arrays.asList(base.set("waterlogged", false), base.set("waterlogged", true));
            }
        }.setTypes("LADDER").setDataValues(2, 3, 4, 5).build();
    }
    if (CommonCapabilities.HAS_MATERIAL_SIGN_TYPES) {
        // LEGACY_WALL_SIGN is broken on 1.14
        {
            new CustomMaterialDataBuilder<org.bukkit.material.Sign>() {

                @Override
                public org.bukkit.material.Sign create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
                    return new CommonSignDataFix(material_type, legacy_data_value, true);
                }

                @Override
                public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.Sign sign) {
                    IBlockDataHandle base = iblockdata.set("facing", sign.getFacing());
                    return Arrays.asList(base.set("waterlogged", false), base.set("waterlogged", true));
                }

                @Override
                public Material fromLegacy(Material legacyMaterial) {
                    return CommonLegacyMaterials.getMaterial("OAK_WALL_SIGN");
                }

                @Override
                public Material toLegacy(Material material) {
                    return CommonLegacyMaterials.getLegacyMaterial("WALL_SIGN");
                }
            }.setTypes("ACACIA_WALL_SIGN", "BIRCH_WALL_SIGN", "DARK_OAK_WALL_SIGN", "JUNGLE_WALL_SIGN", "OAK_WALL_SIGN", "SPRUCE_WALL_SIGN", "LEGACY_WALL_SIGN").addTypesIf(CommonBootstrap.evaluateMCVersion(">=", "1.16"), "CRIMSON_WALL_SIGN", "WARPED_WALL_SIGN").setDataValues(2, 3, 4, 5).build();
        }
        // Register new SIGN_POST types as well
        {
            new CustomMaterialDataBuilder<org.bukkit.material.Sign>() {

                @Override
                public org.bukkit.material.Sign create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
                    return new CommonSignDataFix(material_type, legacy_data_value, false);
                }

                @Override
                public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.Sign sign) {
                    IBlockDataHandle base = iblockdata.set("rotation", sign.getData());
                    return Arrays.asList(base.set("waterlogged", false), base.set("waterlogged", true));
                }

                @Override
                public Material fromLegacy(Material legacyMaterial) {
                    return CommonLegacyMaterials.getMaterial("OAK_SIGN");
                }

                @Override
                public Material toLegacy(Material material) {
                    return CommonLegacyMaterials.getLegacyMaterial("SIGN_POST");
                }
            }.setTypes("ACACIA_SIGN", "BIRCH_SIGN", "DARK_OAK_SIGN", "JUNGLE_SIGN", "OAK_SIGN", "SPRUCE_SIGN", "LEGACY_SIGN_POST").addTypesIf(CommonBootstrap.evaluateMCVersion(">=", "1.16"), "CRIMSON_SIGN", "WARPED_SIGN").setDataValues(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).build();
        }
    } else {
        // Fix LEGACY_WALL_SIGN
        {
            new CustomMaterialDataBuilder<org.bukkit.material.Sign>() {

                @Override
                public org.bukkit.material.Sign create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
                    return new CommonSignDataFix(material_type, legacy_data_value, true);
                }

                @Override
                public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.Sign sign) {
                    IBlockDataHandle base = iblockdata.set("facing", sign.getFacing());
                    return Arrays.asList(base.set("waterlogged", false), base.set("waterlogged", true));
                }
            }.setTypes("WALL_SIGN", "LEGACY_WALL_SIGN").setDataValues(2, 3, 4, 5).build();
        }
        // Fix LEGACY_SIGN_POST
        {
            new CustomMaterialDataBuilder<org.bukkit.material.Sign>() {

                @Override
                public org.bukkit.material.Sign create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
                    return new CommonSignDataFix(material_type, legacy_data_value, false);
                }

                @Override
                public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.Sign sign) {
                    IBlockDataHandle base = iblockdata.set("rotation", sign.getData());
                    return Arrays.asList(base.set("waterlogged", false), base.set("waterlogged", true));
                }
            }.setTypes("SIGN", "LEGACY_SIGN_POST").setDataValues(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).build();
        }
    }
    // Minecraft 1.16 added a Target block, for which we have added a custom material class to support it
    if (Common.evaluateMCVersion(">=", "1.16")) {
        new CustomMaterialDataBuilder<CommonTargetDataFix>() {

            @Override
            public CommonTargetDataFix create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
                return new CommonTargetDataFix(material_type, legacy_data_value);
            }

            @Override
            public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, CommonTargetDataFix target) {
                return Collections.singletonList(iblockdata.set("power", Integer.valueOf(target.getData())));
            }
        }.setTypes("TARGET").setDataValues(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).build();
    }
    // Rails can be waterlogged since 1.17
    if (Common.evaluateMCVersion(">=", "1.17")) {
        // Standard rail - which supports curves
        new RailMaterialDataBuilder<org.bukkit.material.Rails>("RAIL") {

            @Override
            public org.bukkit.material.Rails create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
                return new org.bukkit.material.Rails(legacy_data_type, legacy_data_value);
            }
        }.build();
        // Special types of rail that do not support curves
        new RailMaterialDataBuilder<org.bukkit.material.DetectorRail>("DETECTOR_RAIL") {

            @Override
            public org.bukkit.material.DetectorRail create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
                return new org.bukkit.material.DetectorRail(legacy_data_type, legacy_data_value);
            }

            @Override
            protected IBlockDataHandle apply(IBlockDataHandle iblockdata, org.bukkit.material.DetectorRail rails) {
                return iblockdata.set("powered", rails.isPressed());
            }
        }.build();
        new RailMaterialDataBuilder<org.bukkit.material.PoweredRail>("POWERED_RAIL") {

            @Override
            public org.bukkit.material.PoweredRail create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
                return new org.bukkit.material.PoweredRail(legacy_data_type, legacy_data_value);
            }

            @Override
            protected IBlockDataHandle apply(IBlockDataHandle iblockdata, org.bukkit.material.PoweredRail rails) {
                return iblockdata.set("powered", rails.isPowered());
            }
        }.build();
        new RailMaterialDataBuilder<org.bukkit.material.PoweredRail>("ACTIVATOR_RAIL") {

            @Override
            public org.bukkit.material.PoweredRail create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
                return new org.bukkit.material.PoweredRail(legacy_data_type, legacy_data_value);
            }

            @Override
            protected IBlockDataHandle apply(IBlockDataHandle iblockdata, org.bukkit.material.PoweredRail rails) {
                return iblockdata.set("powered", rails.isPowered());
            }
        }.build();
    }
}
Also used : BlockFace(org.bukkit.block.BlockFace) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IBlockDataHandle(com.bergerkiller.generated.net.minecraft.world.level.block.state.IBlockDataHandle) Material(org.bukkit.Material) MaterialData(org.bukkit.material.MaterialData)

Aggregations

IBlockDataHandle (com.bergerkiller.generated.net.minecraft.world.level.block.state.IBlockDataHandle)6 Material (org.bukkit.Material)3 MaterialDataToIBlockData (com.bergerkiller.bukkit.common.internal.legacy.MaterialDataToIBlockData)2 MaterialsByName.getLegacyMaterial (com.bergerkiller.bukkit.common.internal.legacy.MaterialsByName.getLegacyMaterial)2 MaterialData (org.bukkit.material.MaterialData)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BlockFace (org.bukkit.block.BlockFace)1