Search in sources :

Example 41 with BlockState

use of org.spongepowered.api.block.BlockState in project LanternServer by LanternPowered.

the class BlockRegistryModule method registerDefaults.

@Override
public void registerDefaults() {
    // @formatter:off
    // /////////////////
    // /    Air      ///
    // /////////////////
    register(0, builder().properties(PropertyProviderCollections.DEFAULT_GAS).translation("tile.air.name").build("minecraft", "air"));
    // /////////////////
    // /    Stone    ///
    // /////////////////
    register(1, simpleBuilder().trait(LanternEnumTraits.STONE_TYPE).defaultState(state -> state.withTrait(LanternEnumTraits.STONE_TYPE, LanternStoneType.STONE).get()).itemType(builder -> builder.keysProvider(collection -> collection.register(Keys.STONE_TYPE, LanternStoneType.STONE))).properties(builder -> builder.add(hardness(1.5)).add(blastResistance(30.0))).translation(TranslationProvider.of(LanternEnumTraits.STONE_TYPE)).build("minecraft", "stone"), blockState -> (byte) blockState.getTraitValue(LanternEnumTraits.STONE_TYPE).get().getInternalId());
    // /////////////////
    // /    Grass    ///
    // /////////////////
    register(2, simpleBuilder().trait(LanternBooleanTraits.SNOWY).extendedStateProvider(new SnowyExtendedBlockStateProvider()).defaultState(state -> state.withTrait(LanternBooleanTraits.SNOWY, false).get()).itemType().properties(builder -> builder.add(hardness(0.6)).add(blastResistance(3.0))).translation("tile.grass.name").build("minecraft", "grass"));
    // /////////////////
    // /    Dirt     ///
    // /////////////////
    register(3, simpleBuilder().traits(LanternEnumTraits.DIRT_TYPE, LanternBooleanTraits.SNOWY).defaultState(state -> state.withTrait(LanternEnumTraits.DIRT_TYPE, LanternDirtType.DIRT).get().withTrait(LanternBooleanTraits.SNOWY, false).get()).extendedStateProvider(new SnowyExtendedBlockStateProvider()).itemType(builder -> builder.keysProvider(collection -> collection.register(Keys.DIRT_TYPE, LanternDirtType.DIRT))).properties(builder -> builder.add(hardness(0.5)).add(blastResistance(2.5))).translation(TranslationProvider.of(LanternEnumTraits.DIRT_TYPE)).build("minecraft", "dirt"), blockState -> (byte) blockState.getTraitValue(LanternEnumTraits.DIRT_TYPE).get().getInternalId());
    // /////////////////
    // / Cobblestone ///
    // /////////////////
    register(4, simpleBuilder().itemType().properties(builder -> builder.add(hardness(2.0)).add(blastResistance(3.0))).translation("tile.stonebrick.name").build("minecraft", "cobblestone"));
    // /////////////////
    // /    Planks   ///
    // /////////////////
    register(5, simpleBuilder().trait(LanternEnumTraits.TREE_TYPE).defaultState(state -> state.withTrait(LanternEnumTraits.TREE_TYPE, LanternTreeType.OAK).get()).itemType(builder -> builder.keysProvider(collection -> collection.register(Keys.TREE_TYPE, LanternTreeType.OAK))).properties(builder -> builder.add(hardness(2.0)).add(blastResistance(5.0)).add(flammableInfo(5, 20))).translation(TranslationProvider.of(LanternEnumTraits.TREE_TYPE, type -> tr("tile.planks." + type.getTranslationKeyBase() + ".name"))).build("minecraft", "planks"), blockState -> (byte) blockState.getTraitValue(LanternEnumTraits.TREE_TYPE).get().getInternalId());
    // //////////////////
    // /    Sapling   ///
    // //////////////////
    register(6, simpleBuilder().traits(LanternEnumTraits.TREE_TYPE, LanternIntegerTraits.SAPLING_GROWTH_STAGE).defaultState(state -> state.withTrait(LanternEnumTraits.TREE_TYPE, LanternTreeType.OAK).get().withTrait(LanternIntegerTraits.SAPLING_GROWTH_STAGE, 0).get()).itemType(builder -> builder.keysProvider(collection -> collection.register(Keys.TREE_TYPE, LanternTreeType.OAK))).properties(builder -> builder.add(PASSABLE).add(INSTANT_BROKEN)).translation(TranslationProvider.of(LanternEnumTraits.TREE_TYPE, type -> tr("tile.sapling." + type.getTranslationKeyBase() + ".name"))).build("minecraft", "sapling"), blockState -> {
        final int type = blockState.getTraitValue(LanternEnumTraits.TREE_TYPE).get().getInternalId();
        final int stage = blockState.getTraitValue(LanternIntegerTraits.SAPLING_GROWTH_STAGE).get();
        return (byte) (stage << 3 | type);
    });
    // //////////////////
    // /    Bedrock   ///
    // //////////////////
    register(7, simpleBuilder().itemType().properties(builder -> builder.add(PropertyProviderCollections.UNBREAKABLE)).translation("tile.bedrock.name").build("minecraft", "bedrock"));
    // //////////////////
    // /     Sand     ///
    // //////////////////
    register(12, simpleBuilder().trait(LanternEnumTraits.SAND_TYPE).defaultState(state -> state.withTrait(LanternEnumTraits.SAND_TYPE, LanternSandType.NORMAL).get()).itemType(builder -> builder.keysProvider(collection -> collection.register(Keys.SAND_TYPE, LanternSandType.NORMAL))).properties(builder -> builder.add(hardness(0.5)).add(blastResistance(2.5))).translation(TranslationProvider.of(LanternEnumTraits.SAND_TYPE)).build("minecraft", "sand"), blockState -> (byte) blockState.getTraitValue(LanternEnumTraits.SAND_TYPE).get().getInternalId());
    // TODO: Sand physics behavior
    // //////////////////
    // /    Gravel    ///
    // //////////////////
    register(13, simpleBuilder().itemType().properties(builder -> builder.add(hardness(0.6)).add(blastResistance(3.0))).translation("tile.gravel.name").build("minecraft", "gravel"));
    // TODO: Gravel physics behavior
    // //////////////////
    // /   Gold Ore   ///
    // //////////////////
    register(14, simpleBuilder().itemType().properties(builder -> builder.add(hardness(3.0)).add(blastResistance(15.0))).translation("tile.oreGold.name").build("minecraft", "gold_ore"));
    // //////////////////
    // /   Iron Ore   ///
    // //////////////////
    register(15, simpleBuilder().itemType().properties(builder -> builder.add(hardness(3.0)).add(blastResistance(15.0))).translation("tile.oreIron.name").build("minecraft", "iron_ore"));
    // //////////////////
    // /   Coal Ore   ///
    // //////////////////
    register(16, simpleBuilder().itemType().properties(builder -> builder.add(hardness(3.0)).add(blastResistance(15.0))).translation("tile.oreCoal.name").build("minecraft", "coal_ore"));
    // //////////////////
    // /    Log 1     ///
    // //////////////////
    register(17, logBuilder(LanternEnumTraits.LOG1_TYPE, LanternTreeType.OAK).build("minecraft", "log"), blockState -> logData(blockState, blockState.getTraitValue(LanternEnumTraits.LOG1_TYPE).get().getInternalId()));
    // //////////////////
    // /   Leaves 1   ///
    // //////////////////
    register(18, leavesBuilder(LanternEnumTraits.LEAVES1_TYPE, LanternTreeType.OAK).build("minecraft", "leaves"), blockState -> leavesData(blockState, blockState.getTraitValue(LanternEnumTraits.LEAVES1_TYPE).get().getInternalId()));
    // //////////////////
    // /    Sponge    ///
    // //////////////////
    register(19, simpleBuilder().trait(LanternBooleanTraits.IS_WET).defaultState(state -> state.withTrait(LanternBooleanTraits.IS_WET, false).get()).itemType(builder -> builder.keysProvider(collection -> collection.register(Keys.IS_WET, false))).properties(builder -> builder.add(hardness(0.6)).add(blastResistance(3.0))).translation(new SpongeTranslationProvider()).build("minecraft", "sponge"), blockState -> (byte) (blockState.getTraitValue(LanternBooleanTraits.IS_WET).get() ? 1 : 0));
    // //////////////////
    // /    Glass     ///
    // //////////////////
    register(20, simpleBuilder().itemType().properties(builder -> builder.add(hardness(0.3)).add(blastResistance(1.5))).translation("tile.glass.name").build("minecraft", "glass"));
    // //////////////////
    // /   Lapis Ore  ///
    // //////////////////
    register(21, simpleBuilder().itemType().properties(builder -> builder.add(hardness(3.0)).add(blastResistance(15.0))).translation("tile.oreLapis.name").build("minecraft", "lapis_ore"));
    // //////////////////
    // /  Lapis Block ///
    // //////////////////
    register(22, simpleBuilder().itemType().properties(builder -> builder.add(hardness(3.0)).add(blastResistance(15.0))).translation("tile.blockLapis.name").build("minecraft", "lapis_block"));
    // //////////////////
    // /   Dispenser  ///
    // //////////////////
    register(23, simpleBuilder().traits(LanternEnumTraits.FACING, LanternBooleanTraits.TRIGGERED).defaultState(state -> state.withTrait(LanternEnumTraits.FACING, Direction.NORTH).get().withTrait(LanternBooleanTraits.TRIGGERED, false).get()).itemType().properties(builder -> builder.add(hardness(3.5)).add(blastResistance(17.5))).translation("tile.dispenser.name").behaviors(pipeline -> pipeline.add(new RotationPlacementBehavior())).build("minecraft", "dispenser"), blockState -> {
        int data = directionData(blockState.getTraitValue(LanternEnumTraits.FACING).get());
        if (blockState.getTraitValue(LanternBooleanTraits.TRIGGERED).get()) {
            data |= 0x8;
        }
        return (byte) data;
    });
    // //////////////////
    // /   Sandstone  ///
    // //////////////////
    register(24, simpleBuilder().trait(LanternEnumTraits.SANDSTONE_TYPE).defaultState(state -> state.withTrait(LanternEnumTraits.SANDSTONE_TYPE, LanternSandstoneType.DEFAULT).get()).itemType(builder -> builder.keysProvider(collection -> collection.register(Keys.SANDSTONE_TYPE, LanternSandstoneType.DEFAULT))).properties(builder -> builder.add(hardness(0.8)).add(blastResistance(4.0))).translation(TranslationProvider.of(LanternEnumTraits.SANDSTONE_TYPE)).build("minecraft", "sandstone"), blockState -> (byte) blockState.getTraitValue(LanternEnumTraits.SANDSTONE_TYPE).get().getInternalId());
    // //////////////////
    // /   Noteblock  ///
    // //////////////////
    register(25, simpleBuilder().itemType().properties(builder -> builder.add(hardness(0.8)).add(blastResistance(4.0))).translation("tile.musicBlock.name").tileEntityType(() -> TileEntityTypes.NOTE).behaviors(pipeline -> pipeline.add(new NoteBlockInteractionBehavior())).build("minecraft", "noteblock"));
    // //////////////////
    // /     Bed      ///
    // //////////////////
    register(26, simpleBuilder().traits(LanternEnumTraits.HORIZONTAL_FACING, LanternEnumTraits.BED_PART, LanternBooleanTraits.OCCUPIED).defaultState(state -> state.withTrait(LanternEnumTraits.HORIZONTAL_FACING, Direction.NORTH).get().withTrait(LanternEnumTraits.BED_PART, LanternBedPart.FOOT).get().withTrait(LanternBooleanTraits.OCCUPIED, false).get()).properties(builder -> builder.add(hardness(0.2)).add(blastResistance(1.0))).translation("tile.bed.name").build("minecraft", "bed"), blockState -> {
        final Direction facing = blockState.getTraitValue(LanternEnumTraits.HORIZONTAL_FACING).get();
        int type = facing == Direction.SOUTH ? 0 : facing == Direction.WEST ? 1 : facing == Direction.NORTH ? 2 : facing == Direction.EAST ? 3 : -1;
        checkArgument(type != -1);
        if (blockState.getTraitValue(LanternBooleanTraits.OCCUPIED).get()) {
            type |= 0x4;
        }
        if (blockState.getTraitValue(LanternEnumTraits.BED_PART).get() == LanternBedPart.HEAD) {
            type |= 0x8;
        }
        return (byte) type;
    });
    // ////////////////////
    // /   Golden Rail  ///
    // ////////////////////
    register(27, simpleBuilder().traits(LanternEnumTraits.STRAIGHT_RAIL_DIRECTION, LanternBooleanTraits.POWERED).defaultState(state -> state.withTrait(LanternEnumTraits.STRAIGHT_RAIL_DIRECTION, LanternRailDirection.NORTH_SOUTH).get().withTrait(LanternBooleanTraits.POWERED, false).get()).itemType().boundingBox(BoundingBoxes::rail).properties(builder -> builder.add(PASSABLE).add(hardness(0.7)).add(blastResistance(3.5))).translation("tile.goldenRail.name").build("minecraft", "golden_rail"), blockState -> {
        int type = blockState.getTraitValue(LanternEnumTraits.STRAIGHT_RAIL_DIRECTION).get().getInternalId();
        if (blockState.getTraitValue(LanternBooleanTraits.POWERED).get()) {
            type |= 0x8;
        }
        return (byte) type;
    });
    // //////////////////////
    // /   Detector Rail  ///
    // //////////////////////
    register(28, simpleBuilder().traits(LanternEnumTraits.STRAIGHT_RAIL_DIRECTION, LanternBooleanTraits.POWERED).defaultState(state -> state.withTrait(LanternEnumTraits.STRAIGHT_RAIL_DIRECTION, LanternRailDirection.NORTH_SOUTH).get().withTrait(LanternBooleanTraits.POWERED, false).get()).itemType().boundingBox(BoundingBoxes::rail).properties(builder -> builder.add(PASSABLE).add(hardness(0.7)).add(blastResistance(3.5))).translation("tile.detectorRail.name").build("minecraft", "detector_rail"), blockState -> {
        int type = blockState.getTraitValue(LanternEnumTraits.STRAIGHT_RAIL_DIRECTION).get().getInternalId();
        if (blockState.getTraitValue(LanternBooleanTraits.POWERED).get()) {
            type |= 0x8;
        }
        return (byte) type;
    });
    // TODO: 29
    // /////////////
    // /   Web   ///
    // /////////////
    register(30, simpleBuilder().itemType().properties(builder -> builder.add(PASSABLE).add(hardness(4.0)).add(blastResistance(20.0))).translation("tile.web.name").build("minecraft", "web"));
    // ////////////////////
    // /   Tall Grass   ///
    // ////////////////////
    register(31, simpleBuilder().traits(LanternEnumTraits.SHRUB_TYPE).defaultState(state -> state.withTrait(LanternEnumTraits.SHRUB_TYPE, LanternShrubType.DEAD_BUSH).get()).itemType(builder -> builder.keysProvider(collection -> collection.register(Keys.SHRUB_TYPE, LanternShrubType.DEAD_BUSH))).boundingBox(BoundingBoxes.bush()).properties(builder -> builder.add(INSTANT_BROKEN).add(PASSABLE).add(replaceable(true))).translation("tile.tallgrass.name").build("minecraft", "tallgrass"), blockState -> (byte) blockState.getTraitValue(LanternEnumTraits.SHRUB_TYPE).get().getInternalId());
    // ///////////////////
    // /   Dead Bush   ///
    // ///////////////////
    register(32, simpleBuilder().properties(builder -> builder.add(INSTANT_BROKEN).add(PASSABLE).add(replaceable(true))).boundingBox(BoundingBoxes.bush()).itemType().translation("tile.deadbush.name").build("minecraft", "deadbush"));
    // TODO: 33
    // TODO: 34
    // /////////////////
    // /     Wool    ///
    // /////////////////
    register(35, dyedBuilder("tile.wool.%s.name").properties(builder -> builder.add(hardness(0.8)).add(blastResistance(4.0))).build("minecraft", "wool"), this::dyedData);
    // TODO: 36
    // ///////////////////////
    // /   Yellow Flower   ///
    // ///////////////////////
    register(37, simpleBuilder().traits(LanternEnumTraits.YELLOW_FLOWER_TYPE).defaultState(state -> state.withTrait(LanternEnumTraits.YELLOW_FLOWER_TYPE, LanternPlantType.DANDELION).get()).itemType(builder -> builder.keysProvider(collection -> collection.register(Keys.PLANT_TYPE, LanternPlantType.DANDELION))).boundingBox(BoundingBoxes.bush()).properties(builder -> builder.add(INSTANT_BROKEN).add(PASSABLE)).translation(TranslationProvider.of(LanternEnumTraits.YELLOW_FLOWER_TYPE)).build("minecraft", "yellow_flower"), blockState -> (byte) blockState.getTraitValue(LanternEnumTraits.YELLOW_FLOWER_TYPE).get().getInternalId());
    // ////////////////////
    // /   Red Flower   ///
    // ////////////////////
    register(38, simpleBuilder().traits(LanternEnumTraits.RED_FLOWER_TYPE).defaultState(state -> state.withTrait(LanternEnumTraits.RED_FLOWER_TYPE, LanternPlantType.POPPY).get()).itemType(builder -> builder.keysProvider(collection -> collection.register(Keys.PLANT_TYPE, LanternPlantType.POPPY))).boundingBox(BoundingBoxes.bush()).properties(builder -> builder.add(INSTANT_BROKEN).add(PASSABLE)).translation(TranslationProvider.of(LanternEnumTraits.RED_FLOWER_TYPE)).build("minecraft", "red_flower"), blockState -> (byte) blockState.getTraitValue(LanternEnumTraits.RED_FLOWER_TYPE).get().getInternalId());
    // ////////////////////////
    // /   Brown Mushroom   ///
    // ////////////////////////
    register(39, simpleBuilder().boundingBox(BoundingBoxes.bush()).properties(builder -> builder.add(INSTANT_BROKEN).add(PASSABLE).add(lightEmission(1))).translation("tile.mushroom.name").build("minecraft", "brown_mushroom"));
    // //////////////////////
    // /   Red Mushroom   ///
    // //////////////////////
    register(40, simpleBuilder().boundingBox(BoundingBoxes.bush()).properties(builder -> builder.add(INSTANT_BROKEN).add(PASSABLE)).translation("tile.mushroom.name").build("minecraft", "red_mushroom"));
    // ////////////////////
    // /   Gold Block   ///
    // ////////////////////
    register(41, simpleBuilder().itemType().properties(builder -> builder.add(hardness(3.0)).add(blastResistance(10.0))).translation("tile.blockGold.name").build("minecraft", "gold_block"));
    // ////////////////////
    // /   Iron Block   ///
    // ////////////////////
    register(42, simpleBuilder().itemType().properties(builder -> builder.add(hardness(5.0)).add(blastResistance(10.0))).translation("tile.blockIron.name").build("minecraft", "iron_block"));
    // /////////////////////////
    // / Double Stone Slab 1 ///
    // /////////////////////////
    register(43, doubleStoneSlab(LanternEnumTraits.STONE_SLAB1_TYPE, LanternSlabType.STONE).translation("tile.stoneSlab.name").build("minecraft", "double_stone_slab"), blockState -> doubleStoneSlabData(blockState, blockState.getTraitValue(LanternEnumTraits.STONE_SLAB1_TYPE).get().getInternalId()));
    // //////////////////////
    // /   Stone Slab 1   ///
    // //////////////////////
    register(44, stoneSlab(LanternEnumTraits.STONE_SLAB1_TYPE, LanternSlabType.STONE, () -> BlockTypes.STONE_SLAB, () -> BlockTypes.DOUBLE_STONE_SLAB).translation("tile.stoneSlab.name").boundingBox(BoundingBoxes::slab).build("minecraft", "stone_slab"), blockState -> stoneSlabData(blockState, blockState.getTraitValue(LanternEnumTraits.STONE_SLAB1_TYPE).get().getInternalId()));
    // /////////////////////
    // /   Brick Block   ///
    // /////////////////////
    register(45, simpleBuilder().itemType().properties(builder -> builder.add(hardness(2.0)).add(blastResistance(10.0))).translation("tile.brick.name").build("minecraft", "brick_block"));
    // /////////////
    // /   TNT   ///
    // /////////////
    register(46, simpleBuilder().trait(LanternBooleanTraits.EXPLODE).defaultState(state -> state.withTrait(LanternBooleanTraits.EXPLODE, false).get()).itemType().properties(builder -> builder.add(INSTANT_BROKEN)).translation("tile.tnt.name").build("minecraft", "tnt"), blockState -> (byte) (blockState.getTraitValue(LanternBooleanTraits.EXPLODE).get() ? 1 : 0));
    // ///////////////////
    // /   Bookshelf   ///
    // ///////////////////
    register(47, simpleBuilder().itemType().properties(builder -> builder.add(hardness(1.5)).add(blastResistance(7.5))).translation("tile.bookshelf.name").build("minecraft", "bookshelf"));
    // ///////////////////////////
    // /   Mossy Cobblestone   ///
    // ///////////////////////////
    register(48, simpleBuilder().itemType().properties(builder -> builder.add(hardness(2.0)).add(blastResistance(10.0))).translation("tile.stoneMoss.name").build("minecraft", "mossy_cobblestone"));
    // //////////////////
    // /   Obsidian   ///
    // //////////////////
    register(49, simpleBuilder().itemType().properties(builder -> builder.add(hardness(50.0)).add(blastResistance(2000.0))).translation("tile.obsidian.name").build("minecraft", "obsidian"));
    // ///////////////
    // /   Torch   ///
    // ///////////////
    register(50, builder().trait(LanternEnumTraits.TORCH_FACING).defaultState(state -> state.withTrait(LanternEnumTraits.TORCH_FACING, Direction.UP).get()).itemType().properties(builder -> builder.add(INSTANT_BROKEN)).translation("tile.torch.name").boundingBox(BoundingBoxes::torch).behaviors(pipeline -> pipeline.add(new BlockSnapshotProviderPlaceBehavior()).add(new TorchPlacementBehavior()).add(new SimpleBreakBehavior())).build("minecraft", "torch"), blockState -> {
        final Direction direction = blockState.getTraitValue(LanternEnumTraits.TORCH_FACING).get();
        switch(direction) {
            case EAST:
                return (byte) 1;
            case WEST:
                return (byte) 2;
            case SOUTH:
                return (byte) 3;
            case NORTH:
                return (byte) 4;
            case UP:
                return (byte) 5;
            default:
                throw new IllegalArgumentException();
        }
    });
    // ////////////
    // /  Fire  ///
    // ////////////
    register(51, simpleBuilder().properties(builder -> builder.add(PropertyProviderCollections.PASSABLE).add(PropertyProviderCollections.INSTANT_BROKEN).add(lightEmission(15))).boundingBox(BoundingBoxes.NULL).translation("tile.fire.name").build("minecraft", "fire"));
    // ///////////////////
    // /  Mob Spawner  ///
    // ///////////////////
    register(52, simpleBuilder().properties(builder -> builder.add(hardness(5.0)).add(blastResistance(25.0))).translation("tile.mobSpawner.name").build("minecraft", "mob_spawner"));
    // TODO: Oak Stairs
    // //////////////////
    // /     Chest    ///
    // //////////////////
    register(54, chestBuilder().translation("tile.chest.name").build("minecraft", "chest"), this::chestData);
    // /////////////////////////
    // /     Redstone Wire   ///
    // /////////////////////////
    register(55, simpleBuilder().traits(LanternIntegerTraits.POWER).boundingBox(BoundingBoxes.NULL).defaultState(state -> state.withTrait(LanternIntegerTraits.POWER, 0).get()).translation("tile.redstoneDust.name").build("minecraft", "redstone_wire"), state -> state.get(Keys.POWER).get().byteValue());
    // /////////////////////
    // /   Diamond Ore   ///
    // /////////////////////
    register(56, simpleBuilder().itemType().properties(builder -> builder.add(hardness(3.0)).add(blastResistance(5.0))).translation("tile.oreDiamond.name").build("minecraft", "diamond_ore"));
    // ///////////////////////
    // /   Diamond Block   ///
    // ///////////////////////
    register(57, simpleBuilder().itemType().properties(builder -> builder.add(hardness(5.0)).add(blastResistance(10.0))).translation("tile.blockDiamond.name").build("minecraft", "diamond_block"));
    // ////////////////////////
    // /   Crafting Table   ///
    // ////////////////////////
    register(58, simpleBuilder().itemType().properties(builder -> builder.add(hardness(2.5)).add(blastResistance(12.5))).translation("tile.workbench.name").behaviors(pipeline -> pipeline.add(new CraftingTableInteractionBehavior())).build("minecraft", "crafting_table"));
    // TODO: Wheat
    // //////////////////
    // /   Farmland   ///
    // //////////////////
    register(60, simpleBuilder().boundingBox(BoundingBoxes.farmland()).trait(LanternIntegerTraits.MOISTURE).properties(builder -> builder.add(hardness(0.6)).add(blastResistance(3.0))).defaultState(state -> state.withTrait(LanternIntegerTraits.MOISTURE, 0).get()).translation("tile.farmland.name").build("minecraft", "farmland"), state -> state.getTraitValue(LanternIntegerTraits.MOISTURE).get().byteValue());
    // //////////////////
    // /    Furnace   ///
    // //////////////////
    register(61, furnaceBuilder().itemType().translation("tile.furnace.name").build("minecraft", "furnace"), this::directionData);
    // //////////////////
    // /  Lit Furnace ///
    // //////////////////
    register(62, furnaceBuilder().properties(builder -> builder.add(lightEmission(13))).translation("tile.furnace.name").build("minecraft", "lit_furnace"), this::directionData);
    // //////////////////////////
    // / Stone Pressure Plate ///
    // //////////////////////////
    register(70, pressurePlateBuilder().translation("tile.pressurePlateStone.name").build("minecraft", "stone_pressure_plate"), this::pressurePlateData);
    // ///////////////////////////
    // / Wooden Pressure Plate ///
    // ///////////////////////////
    register(72, pressurePlateBuilder().translation("tile.pressurePlateWood.name").build("minecraft", "wooden_pressure_plate"), this::pressurePlateData);
    // //////////////////
    // /    Jukebox   ///
    // //////////////////
    register(84, simpleBuilder().itemType().traits(LanternBooleanTraits.HAS_RECORD).defaultState(state -> state.withTrait(LanternBooleanTraits.HAS_RECORD, false).get()).properties(builder -> builder.add(hardness(2.0)).add(blastResistance(10.0))).tileEntityType(() -> TileEntityTypes.JUKEBOX).translation("tile.jukebox.name").behaviors(pipeline -> pipeline.add(new JukeboxInteractionBehavior())).build("minecraft", "jukebox"), state -> (byte) (state.getTraitValue(LanternBooleanTraits.HAS_RECORD).get() ? 1 : 0));
    // //////////////////
    // /    Pumpkin   ///
    // //////////////////
    register(86, pumpkinBuilder().itemType(builder -> builder.properties(properties -> properties.add(equipmentType(EquipmentTypes.HEADWEAR)))).translation("tile.pumpkin.name").build("minecraft", "pumpkin"), this::horizontalDirectionData);
    // ////////////////////
    // /   Netherrack   ///
    // ////////////////////
    register(87, simpleBuilder().itemType().properties(builder -> builder.add(hardness(0.4)).add(blastResistance(2.0))).translation("tile.hellrock.name").build("minecraft", "netherrack"));
    // //////////////////
    // /  Lit Pumpkin ///
    // //////////////////
    register(91, pumpkinBuilder().properties(builder -> builder.add(lightEmission(15))).translation("tile.litpumpkin.name").build("minecraft", "lit_pumpkin"), this::horizontalDirectionData);
    // ///////////////////
    // / Stained Glass ///
    // ///////////////////
    register(95, dyedBuilder("tile.stainedGlass.%s.name").properties(builder -> builder.add(hardness(0.3)).add(blastResistance(1.5))).build("minecraft", "stained_glass"), this::dyedData);
    // /////////////////
    // /  Iron Bars  ///
    // /////////////////
    register(101, simpleBuilder().itemType().properties(builder -> builder.add(hardness(5.0)).add(blastResistance(10.0))).translation("tile.fenceIron.name").build("minecraft", "iron_bars"));
    // ///////////////////
    // /   End Stone   ///
    // ///////////////////
    register(121, simpleBuilder().itemType().properties(builder -> builder.add(hardness(3.0)).add(blastResistance(15.0))).translation("tile.whiteStone.name").build("minecraft", "end_stone"));
    // ////////////////////////
    // / Double Wooden Slab ///
    // ////////////////////////
    register(125, simpleBuilder().traits(LanternEnumTraits.TREE_TYPE).defaultState(state -> state.withTrait(LanternEnumTraits.TREE_TYPE, LanternTreeType.OAK).get()).translation(TranslationProvider.of(LanternEnumTraits.TREE_TYPE, type -> tr("tile.woodSlab." + type.getTranslationKeyBase() + ".name"))).itemType(builder -> builder.keysProvider(collection -> collection.register(Keys.TREE_TYPE, LanternTreeType.OAK))).properties(builder -> builder.add(hardness(2.0)).add(blastResistance(5.0))).build("minecraft", "double_wooden_slab"), blockState -> (byte) blockState.getTraitValue(LanternEnumTraits.TREE_TYPE).get().getInternalId());
    // ////////////////////////
    // /     Wooden Slab    ///
    // ////////////////////////
    register(126, simpleBuilder().traits(LanternEnumTraits.PORTION_TYPE, LanternEnumTraits.TREE_TYPE).defaultState(state -> state.withTrait(LanternEnumTraits.PORTION_TYPE, LanternPortionType.BOTTOM).get().withTrait(LanternEnumTraits.TREE_TYPE, LanternTreeType.OAK).get()).translation(TranslationProvider.of(LanternEnumTraits.TREE_TYPE, type -> tr("tile.woodSlab." + type.getTranslationKeyBase() + ".name"))).itemType(builder -> builder.behaviors(pipeline -> pipeline.add(new SlabItemInteractionBehavior<>(LanternEnumTraits.TREE_TYPE, () -> BlockTypes.WOODEN_SLAB, () -> BlockTypes.DOUBLE_WOODEN_SLAB))).keysProvider(collection -> collection.register(Keys.TREE_TYPE, LanternTreeType.OAK))).boundingBox(BoundingBoxes::slab).properties(builder -> builder.add(hardness(2.0)).add(blastResistance(5.0))).build("minecraft", "wooden_slab"), blockState -> {
        final int type = blockState.getTraitValue(LanternEnumTraits.TREE_TYPE).get().getInternalId();
        final int portion = (byte) blockState.getTraitValue(LanternEnumTraits.PORTION_TYPE).get().getInternalId();
        return (byte) (portion << 3 | type);
    });
    // ///////////////////
    // /  Ender Chest  ///
    // ///////////////////
    register(130, simpleBuilder().trait(LanternEnumTraits.HORIZONTAL_FACING).defaultState(state -> state.withTrait(LanternEnumTraits.HORIZONTAL_FACING, Direction.NORTH).get()).itemType().tileEntityType(() -> TileEntityTypes.ENDER_CHEST).properties(builder -> builder.add(hardness(22.5)).add(blastResistance(3000.0)).add(lightEmission(7))).translation("tile.enderChest.name").boundingBox(BoundingBoxes.chest()).behaviors(pipeline -> pipeline.add(new HorizontalRotationPlacementBehavior()).add(new EnderChestInteractionBehavior())).build("minecraft", "ender_chest"), this::chestData);
    // ///////////////////
    // / Trapped Chest ///
    // ///////////////////
    register(146, chestBuilder().translation("tile.chestTrap.name").build("minecraft", "trapped_chest"), this::chestData);
    // /////////////////////////////////////
    // / Weighted Pressure Plate (Light) ///
    // /////////////////////////////////////
    register(147, weightedPressurePlateBuilder().translation("tile.weightedPlate_light.name").build("minecraft", "light_weighted_pressure_plate"), this::weightedPressurePlateData);
    // /////////////////////////////////////
    // / Weighted Pressure Plate (Heavy) ///
    // /////////////////////////////////////
    register(148, weightedPressurePlateBuilder().translation("tile.weightedPlate_heavy.name").build("minecraft", "heavy_weighted_pressure_plate"), this::weightedPressurePlateData);
    // /////////////////////
    // / Redstone Block  ///
    // /////////////////////
    register(152, simpleBuilder().itemType().properties(builder -> builder.add(hardness(5.0)).add(blastResistance(30.0))).translation("tile.blockRedstone.name").build("minecraft", "redstone_block"));
    // //////////////////
    // /  Quartz Ore  ///
    // //////////////////
    register(153, simpleBuilder().itemType().properties(builder -> builder.add(hardness(3.0)).add(blastResistance(15.0))).translation("tile.netherquartz.name").build("minecraft", "quartz_ore"));
    // //////////////////
    // /     Hopper   ///
    // //////////////////
    register(154, simpleBuilder().traits(LanternEnumTraits.HOPPER_FACING, LanternBooleanTraits.ENABLED).defaultState(state -> state.withTrait(LanternEnumTraits.HOPPER_FACING, Direction.DOWN).get().withTrait(LanternBooleanTraits.ENABLED, false).get()).itemType().properties(builder -> builder.add(hardness(3.0)).add(blastResistance(8.0))).translation("tile.hopper.name").behaviors(pipeline -> pipeline.add(new HopperPlacementBehavior())).build("minecraft", "hopper"), blockState -> {
        int data = directionData(blockState.getTraitValue(LanternEnumTraits.HOPPER_FACING).get());
        if (!blockState.getTraitValue(LanternBooleanTraits.ENABLED).get()) {
            data |= 0x8;
        }
        return (byte) data;
    });
    // ////////////////////
    // /  Quartz Block  ///
    // ////////////////////
    register(155, simpleBuilder().trait(LanternEnumTraits.QUARTZ_TYPE).defaultState(state -> state.withTrait(LanternEnumTraits.QUARTZ_TYPE, LanternQuartzType.DEFAULT).get()).itemType(builder -> builder.keysProvider(collection -> collection.register(Keys.QUARTZ_TYPE, LanternQuartzType.DEFAULT))).properties(builder -> builder.add(hardness(0.8)).add(blastResistance(2.4))).translation(TranslationProvider.of(LanternEnumTraits.QUARTZ_TYPE)).behaviors(pipeline -> pipeline.add(new QuartzLinesRotationPlacementBehavior())).build("minecraft", "quartz_block"), blockState -> (byte) blockState.getTraitValue(LanternEnumTraits.QUARTZ_TYPE).get().getInternalId());
    // //////////////////
    // /    Dropper   ///
    // //////////////////
    register(158, simpleBuilder().traits(LanternEnumTraits.FACING, LanternBooleanTraits.TRIGGERED).defaultState(state -> state.withTrait(LanternEnumTraits.FACING, Direction.NORTH).get().withTrait(LanternBooleanTraits.TRIGGERED, false).get()).itemType().properties(builder -> builder.add(hardness(3.5)).add(blastResistance(17.5))).translation("tile.dropper.name").behaviors(pipeline -> pipeline.add(new RotationPlacementBehavior())).build("minecraft", "dropper"), blockState -> {
        int data = directionData(blockState.getTraitValue(LanternEnumTraits.FACING).get());
        if (blockState.getTraitValue(LanternBooleanTraits.TRIGGERED).get()) {
            data |= 0x8;
        }
        return (byte) data;
    });
    // ////////////////////////////
    // / Stained Hardended Clay ///
    // ////////////////////////////
    register(159, dyedBuilder("tile.clayHardenedStained.%s.name").properties(builder -> builder.add(hardness(1.25)).add(blastResistance(7.0))).build("minecraft", "stained_hardened_clay"), this::dyedData);
    // ////////////////////////
    // / Stained Glass Pane ///
    // ////////////////////////
    register(160, dyedBuilder("tile.thinStainedGlass.%s.name").properties(builder -> builder.add(hardness(0.3)).add(blastResistance(1.5))).build("minecraft", "stained_glass_pane"), this::dyedData);
    // //////////////////
    // /   Leaves 2   ///
    // //////////////////
    register(161, leavesBuilder(LanternEnumTraits.LEAVES2_TYPE, LanternTreeType.ACACIA).build("minecraft", "leaves2"), blockState -> leavesData(blockState, blockState.getTraitValue(LanternEnumTraits.LEAVES2_TYPE).get().getInternalId() - 4));
    // //////////////////
    // /    Log 2     ///
    // //////////////////
    register(162, logBuilder(LanternEnumTraits.LOG2_TYPE, LanternTreeType.ACACIA).build("minecraft", "log2"), blockState -> logData(blockState, blockState.getTraitValue(LanternEnumTraits.LOG2_TYPE).get().getInternalId() - 4));
    // //////////////////
    // /   Barrier    ///
    // //////////////////
    register(166, simpleBuilder().itemType().properties(builder -> builder.add(PropertyProviderCollections.UNBREAKABLE)).translation("tile.barrier.name").build("minecraft", "barrier"));
    // ///////////////////
    // /     Carpet    ///
    // ///////////////////
    register(171, dyedBuilder("tile.carpet.%s.name").properties(builder -> builder.add(hardness(0.1)).add(blastResistance(0.5))).boundingBox(BoundingBoxes.carpet()).build("minecraft", "carpet"), this::dyedData);
    // ///////////////////
    // / Red Sandstone ///
    // ///////////////////
    register(179, simpleBuilder().trait(LanternEnumTraits.SANDSTONE_TYPE).defaultState(state -> state.withTrait(LanternEnumTraits.SANDSTONE_TYPE, LanternSandstoneType.DEFAULT).get()).itemType(builder -> builder.keysProvider(collection -> collection.register(Keys.SANDSTONE_TYPE, LanternSandstoneType.DEFAULT))).properties(builder -> builder.add(hardness(0.8)).add(blastResistance(4.0))).translation(TranslationProvider.of(LanternEnumTraits.SANDSTONE_TYPE)).build("minecraft", "red_sandstone"), blockState -> (byte) blockState.getTraitValue(LanternEnumTraits.SANDSTONE_TYPE).get().getInternalId());
    // /////////////////////////
    // / Double Stone Slab 2 ///
    // /////////////////////////
    register(181, doubleStoneSlab(LanternEnumTraits.STONE_SLAB2_TYPE, LanternSlabType.RED_SAND).translation("tile.stoneSlab2.name").build("minecraft", "double_stone_slab2"), blockState -> doubleStoneSlabData(blockState, blockState.getTraitValue(LanternEnumTraits.STONE_SLAB2_TYPE).get().getInternalId() - 8));
    // //////////////////////
    // /   Stone Slab 2   ///
    // //////////////////////
    register(182, stoneSlab(LanternEnumTraits.STONE_SLAB2_TYPE, LanternSlabType.RED_SAND, () -> BlockTypes.STONE_SLAB2, () -> BlockTypes.DOUBLE_STONE_SLAB2).translation("tile.stoneSlab2.name").boundingBox(BoundingBoxes::slab).build("minecraft", "stone_slab2"), blockState -> stoneSlabData(blockState, blockState.getTraitValue(LanternEnumTraits.STONE_SLAB2_TYPE).get().getInternalId() - 8));
    // /////////////////
    // /   End Rod   ///
    // /////////////////
    register(198, simpleBuilder().itemType().properties(builder -> builder.add(hardness(0.0)).add(blastResistance(0.0)).add(lightEmission(14))).translation("tile.endRod.name").build("minecraft", "end_rod"));
    // /////////////////////////
    // /  White Shulker Box  ///
    // /////////////////////////
    register(219, shulkerBox().translation("tile.shulkerBoxWhite.name").build("minecraft", "white_shulker_box"), this::shulkerBoxData);
    // /////////////////////////
    // /  Orange Shulker Box ///
    // /////////////////////////
    register(220, shulkerBox().translation("tile.shulkerBoxOrange.name").build("minecraft", "orange_shulker_box"), this::shulkerBoxData);
    // //////////////////////////
    // /  Magenta Shulker Box ///
    // //////////////////////////
    register(221, shulkerBox().translation("tile.shulkerBoxMagenta.name").build("minecraft", "magenta_shulker_box"), this::shulkerBoxData);
    // /////////////////////////////
    // /  Light Blue Shulker Box ///
    // /////////////////////////////
    register(222, shulkerBox().translation("tile.shulkerBoxLightBlue.name").build("minecraft", "light_blue_shulker_box"), this::shulkerBoxData);
    // /////////////////////////
    // /  Yellow Shulker Box ///
    // /////////////////////////
    register(223, shulkerBox().translation("tile.shulkerBoxYellow.name").build("minecraft", "yellow_shulker_box"), this::shulkerBoxData);
    // ///////////////////////
    // /  Lime Shulker Box ///
    // ///////////////////////
    register(224, shulkerBox().translation("tile.shulkerBoxLime.name").build("minecraft", "lime_shulker_box"), this::shulkerBoxData);
    // ///////////////////////
    // /  Pink Shulker Box ///
    // ///////////////////////
    register(225, shulkerBox().translation("tile.shulkerBoxPink.name").build("minecraft", "pink_shulker_box"), this::shulkerBoxData);
    // ///////////////////////
    // /  Gray Shulker Box ///
    // ///////////////////////
    register(226, shulkerBox().translation("tile.shulkerBoxGray.name").build("minecraft", "gray_shulker_box"), this::shulkerBoxData);
    // ///////////////////////
    // /  Gray Shulker Box ///
    // ///////////////////////
    register(227, shulkerBox().translation("tile.shulkerBoxSilver.name").build("minecraft", "silver_shulker_box"), this::shulkerBoxData);
    // ///////////////////////
    // /  Cyan Shulker Box ///
    // ///////////////////////
    register(228, shulkerBox().translation("tile.shulkerBoxCyan.name").build("minecraft", "cyan_shulker_box"), this::shulkerBoxData);
    // /////////////////////////
    // /  Purple Shulker Box ///
    // /////////////////////////
    register(229, shulkerBox().translation("tile.shulkerBoxPurple.name").build("minecraft", "purple_shulker_box"), this::shulkerBoxData);
    // ///////////////////////
    // /  Blue Shulker Box ///
    // ///////////////////////
    register(230, shulkerBox().translation("tile.shulkerBoxBlue.name").build("minecraft", "blue_shulker_box"), this::shulkerBoxData);
    // ////////////////////////
    // /  Brown Shulker Box ///
    // ////////////////////////
    register(231, shulkerBox().translation("tile.shulkerBoxBrown.name").build("minecraft", "brown_shulker_box"), this::shulkerBoxData);
    // ////////////////////////
    // /  Green Shulker Box ///
    // ////////////////////////
    register(232, shulkerBox().translation("tile.shulkerBoxGreen.name").build("minecraft", "green_shulker_box"), this::shulkerBoxData);
    // //////////////////////
    // /  Red Shulker Box ///
    // //////////////////////
    register(233, shulkerBox().translation("tile.shulkerBoxRed.name").build("minecraft", "red_shulker_box"), this::shulkerBoxData);
    // ////////////////////////
    // /  Black Shulker Box ///
    // ////////////////////////
    register(234, shulkerBox().translation("tile.shulkerBoxBlack.name").build("minecraft", "black_shulker_box"), this::shulkerBoxData);
// @formatter:on
}
Also used : BlockTypeBuilder(org.lanternpowered.server.block.BlockTypeBuilder) LanternBlockType(org.lanternpowered.server.block.LanternBlockType) LanternDirtType(org.lanternpowered.server.data.type.LanternDirtType) JukeboxInteractionBehavior(org.lanternpowered.server.block.behavior.vanilla.JukeboxInteractionBehavior) SnowyExtendedBlockStateProvider(org.lanternpowered.server.block.extended.SnowyExtendedBlockStateProvider) LanternBooleanTraits(org.lanternpowered.server.block.trait.LanternBooleanTraits) BoundingBoxes(org.lanternpowered.server.block.aabb.BoundingBoxes) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ChestPlacementBehavior(org.lanternpowered.server.block.behavior.vanilla.ChestPlacementBehavior) LanternTreeType(org.lanternpowered.server.data.type.LanternTreeType) RegistrationDependency(org.spongepowered.api.registry.util.RegistrationDependency) LanternStoneType(org.lanternpowered.server.data.type.LanternStoneType) KeyRegistryModule(org.lanternpowered.server.game.registry.type.data.KeyRegistryModule) PropertyProviders.replaceable(org.lanternpowered.server.block.provider.property.PropertyProviders.replaceable) ChestInteractionBehavior(org.lanternpowered.server.block.behavior.vanilla.ChestInteractionBehavior) NoteBlockInteractionBehavior(org.lanternpowered.server.block.behavior.vanilla.NoteBlockInteractionBehavior) ShulkerBoxInteractionBehavior(org.lanternpowered.server.block.behavior.vanilla.ShulkerBoxInteractionBehavior) Object2ShortOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ShortOpenHashMap) LanternIntegerTraits(org.lanternpowered.server.block.trait.LanternIntegerTraits) Short2ObjectOpenHashMap(it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap) LanternQuartzType(org.lanternpowered.server.data.type.LanternQuartzType) LanternDyeColor(org.lanternpowered.server.data.type.LanternDyeColor) BlockTypes(org.spongepowered.api.block.BlockTypes) INSTANT_BROKEN(org.lanternpowered.server.block.provider.property.PropertyProviderCollections.INSTANT_BROKEN) LanternPlantType(org.lanternpowered.server.data.type.LanternPlantType) HopperPlacementBehavior(org.lanternpowered.server.block.behavior.vanilla.HopperPlacementBehavior) SimpleBlockDropsProviderBehavior(org.lanternpowered.server.block.behavior.simple.SimpleBlockDropsProviderBehavior) Preconditions.checkState(com.google.common.base.Preconditions.checkState) SimpleBreakBehavior(org.lanternpowered.server.block.behavior.simple.SimpleBreakBehavior) LanternPortionType(org.lanternpowered.server.data.type.LanternPortionType) EquipmentTypeRegistryModule(org.lanternpowered.server.game.registry.type.item.inventory.equipment.EquipmentTypeRegistryModule) BlockState(org.spongepowered.api.block.BlockState) SlabType(org.spongepowered.api.data.type.SlabType) Direction(org.spongepowered.api.util.Direction) SimplePlacementBehavior(org.lanternpowered.server.block.behavior.simple.SimplePlacementBehavior) QuartzLinesRotationPlacementBehavior(org.lanternpowered.server.block.behavior.vanilla.QuartzLinesRotationPlacementBehavior) Lantern(org.lanternpowered.server.game.Lantern) BlockSnapshotProviderPlaceBehavior(org.lanternpowered.server.block.behavior.simple.BlockSnapshotProviderPlaceBehavior) RotationPlacementBehavior(org.lanternpowered.server.block.behavior.vanilla.RotationPlacementBehavior) InstrumentTypeRegistryModule(org.lanternpowered.server.game.registry.type.data.InstrumentTypeRegistryModule) BlockType(org.spongepowered.api.block.BlockType) Object2ShortMap(it.unimi.dsi.fastutil.objects.Object2ShortMap) Optional(java.util.Optional) CraftingTableInteractionBehavior(org.lanternpowered.server.block.behavior.vanilla.CraftingTableInteractionBehavior) LanternSlabType(org.lanternpowered.server.data.type.LanternSlabType) LanternBedPart(org.lanternpowered.server.data.type.LanternBedPart) InventorySnapshot(org.lanternpowered.server.inventory.InventorySnapshot) BlockTypeBuilderImpl(org.lanternpowered.server.block.BlockTypeBuilderImpl) LanternKeys(org.lanternpowered.server.data.key.LanternKeys) Keys(org.spongepowered.api.data.key.Keys) EnderChestInteractionBehavior(org.lanternpowered.server.block.behavior.vanilla.EnderChestInteractionBehavior) OppositeFaceDirectionalPlacementBehavior(org.lanternpowered.server.block.behavior.vanilla.OppositeFaceDirectionalPlacementBehavior) LanternRailDirection(org.lanternpowered.server.data.type.LanternRailDirection) EnumTrait(org.spongepowered.api.block.trait.EnumTrait) Byte2ObjectOpenHashMap(it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap) TranslationProvider(org.lanternpowered.server.block.TranslationProvider) Supplier(java.util.function.Supplier) ItemRegistryModule(org.lanternpowered.server.game.registry.type.item.ItemRegistryModule) TreeType(org.spongepowered.api.data.type.TreeType) PropertyProviders.equipmentType(org.lanternpowered.server.item.PropertyProviders.equipmentType) PropertyProviders.lightEmission(org.lanternpowered.server.block.provider.property.PropertyProviders.lightEmission) HorizontalRotationPlacementBehavior(org.lanternpowered.server.block.behavior.vanilla.HorizontalRotationPlacementBehavior) TorchPlacementBehavior(org.lanternpowered.server.block.behavior.vanilla.TorchPlacementBehavior) Byte2ObjectMap(it.unimi.dsi.fastutil.bytes.Byte2ObjectMap) TranslationHelper.tr(org.lanternpowered.server.text.translation.TranslationHelper.tr) LogAxisRotationPlacementBehavior(org.lanternpowered.server.block.behavior.vanilla.LogAxisRotationPlacementBehavior) PASSABLE(org.lanternpowered.server.block.provider.property.PropertyProviderCollections.PASSABLE) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) PropertyProviders.hardness(org.lanternpowered.server.block.provider.property.PropertyProviders.hardness) PropertyProviderCollections(org.lanternpowered.server.block.provider.property.PropertyProviderCollections) LanternSandType(org.lanternpowered.server.data.type.LanternSandType) LanternShrubType(org.lanternpowered.server.data.type.LanternShrubType) LanternBlockState(org.lanternpowered.server.block.state.LanternBlockState) SpongeTranslationProvider(org.lanternpowered.server.block.translation.SpongeTranslationProvider) LanternSandstoneType(org.lanternpowered.server.data.type.LanternSandstoneType) SlabItemInteractionBehavior(org.lanternpowered.server.item.behavior.vanilla.SlabItemInteractionBehavior) PropertyProviders.blastResistance(org.lanternpowered.server.block.provider.property.PropertyProviders.blastResistance) Short2ObjectMap(it.unimi.dsi.fastutil.shorts.Short2ObjectMap) TileEntityTypes(org.spongepowered.api.block.tileentity.TileEntityTypes) PropertyProviders.flammableInfo(org.lanternpowered.server.block.provider.property.PropertyProviders.flammableInfo) EquipmentTypes(org.spongepowered.api.item.inventory.equipment.EquipmentTypes) LanternEnumTraits(org.lanternpowered.server.block.trait.LanternEnumTraits) AdditionalPluginCatalogRegistryModule(org.lanternpowered.server.game.registry.AdditionalPluginCatalogRegistryModule) OpenableContainerInteractionBehavior(org.lanternpowered.server.block.behavior.vanilla.OpenableContainerInteractionBehavior) BlockSnapshotProviderPlaceBehavior(org.lanternpowered.server.block.behavior.simple.BlockSnapshotProviderPlaceBehavior) SimpleBreakBehavior(org.lanternpowered.server.block.behavior.simple.SimpleBreakBehavior) EnderChestInteractionBehavior(org.lanternpowered.server.block.behavior.vanilla.EnderChestInteractionBehavior) QuartzLinesRotationPlacementBehavior(org.lanternpowered.server.block.behavior.vanilla.QuartzLinesRotationPlacementBehavior) RotationPlacementBehavior(org.lanternpowered.server.block.behavior.vanilla.RotationPlacementBehavior) HorizontalRotationPlacementBehavior(org.lanternpowered.server.block.behavior.vanilla.HorizontalRotationPlacementBehavior) LogAxisRotationPlacementBehavior(org.lanternpowered.server.block.behavior.vanilla.LogAxisRotationPlacementBehavior) CraftingTableInteractionBehavior(org.lanternpowered.server.block.behavior.vanilla.CraftingTableInteractionBehavior) SpongeTranslationProvider(org.lanternpowered.server.block.translation.SpongeTranslationProvider) TorchPlacementBehavior(org.lanternpowered.server.block.behavior.vanilla.TorchPlacementBehavior) HorizontalRotationPlacementBehavior(org.lanternpowered.server.block.behavior.vanilla.HorizontalRotationPlacementBehavior) NoteBlockInteractionBehavior(org.lanternpowered.server.block.behavior.vanilla.NoteBlockInteractionBehavior) HopperPlacementBehavior(org.lanternpowered.server.block.behavior.vanilla.HopperPlacementBehavior) Direction(org.spongepowered.api.util.Direction) LanternRailDirection(org.lanternpowered.server.data.type.LanternRailDirection) SlabItemInteractionBehavior(org.lanternpowered.server.item.behavior.vanilla.SlabItemInteractionBehavior) QuartzLinesRotationPlacementBehavior(org.lanternpowered.server.block.behavior.vanilla.QuartzLinesRotationPlacementBehavior) BoundingBoxes(org.lanternpowered.server.block.aabb.BoundingBoxes) JukeboxInteractionBehavior(org.lanternpowered.server.block.behavior.vanilla.JukeboxInteractionBehavior) SnowyExtendedBlockStateProvider(org.lanternpowered.server.block.extended.SnowyExtendedBlockStateProvider)

Example 42 with BlockState

use of org.spongepowered.api.block.BlockState in project LanternServer by LanternPowered.

the class LanternFurnace method pulse.

@Override
public void pulse() {
    super.pulse();
    if (this.lastTick == -1) {
        this.lastTick = LanternGame.currentTimeTicks();
        return;
    }
    final long ticks = LanternGame.currentTimeTicks();
    long elapsed = ticks - this.lastTick;
    // This shouldn't happen
    if (elapsed == 0) {
        return;
    }
    this.lastTick = ticks;
    while (elapsed > 0) {
        int maxCookTime = 0;
        Optional<SmeltingResult> smeltingResult = Optional.empty();
        Optional<SmeltingRecipe> smeltingRecipe = Optional.empty();
        ItemStack itemStack = this.inventory.getInputSlot().getRawItemStack();
        final ItemStackSnapshot inputSlotItemSnapshot = itemStack == null ? null : itemStack.createSnapshot();
        if (inputSlotItemSnapshot != null) {
            // Check if the item can be smelted, this means finding a compatible
            // recipe and the output has to be empty.
            smeltingRecipe = Lantern.getRegistry().getSmeltingRecipeRegistry().findMatchingRecipe(inputSlotItemSnapshot);
            if (smeltingRecipe.isPresent()) {
                final int quantity = ((ISmeltingRecipe) smeltingRecipe.get()).getIngredient().getQuantity(inputSlotItemSnapshot);
                if (inputSlotItemSnapshot.getQuantity() >= quantity) {
                    smeltingResult = smeltingRecipe.get().getResult(inputSlotItemSnapshot);
                    // Check if the item can be smelted
                    if (smeltingResult.isPresent()) {
                        // Check if the result could be added to the output
                        final PeekedOfferTransactionResult peekResult = this.inventory.getOutputSlot().peekOffer(smeltingResult.get().getResult().createStack());
                        if (peekResult.isSuccess()) {
                            maxCookTime = ((ISmeltingRecipe) smeltingRecipe.get()).getSmeltTime(inputSlotItemSnapshot).orElse(200);
                        }
                    }
                }
            }
        }
        // The ticks that are elapsed in this loop, limit
        // this to one cooking cycle, this can only happen
        // if actually a item is being cooked
        long elapsed1 = elapsed;
        int elapsedCookTime = get(Keys.PASSED_COOK_TIME).get();
        int remainingCookTime = maxCookTime - elapsedCookTime;
        if (maxCookTime > 0 && elapsed1 > remainingCookTime) {
            elapsed1 = remainingCookTime;
        }
        elapsed -= elapsed1;
        // Burn items until the furnace is burning properly
        int maxBurnTime = get(Keys.MAX_BURN_TIME).get();
        int elapsedBurnTime = get(Keys.PASSED_BURN_TIME).get();
        int remainingBurnTime = maxBurnTime - elapsedBurnTime;
        long elapsed2 = elapsed1;
        while (elapsed2 >= remainingBurnTime) {
            elapsed2 -= remainingBurnTime;
            // Reset the max burn time
            maxBurnTime = 0;
            // Only burn a new item if the target item can be smelted
            itemStack = this.inventory.getFuelSlot().getRawItemStack();
            if (itemStack != null && maxCookTime > 0) {
                // Check for the next fuel item
                final ItemStackSnapshot itemStackSnapshot = itemStack.createSnapshot();
                final Optional<IFuel> result = Lantern.getRegistry().getFuelRegistry().findMatching(itemStackSnapshot);
                if (result.isPresent()) {
                    final OptionalInt optBurnTime = result.get().getBurnTime(itemStackSnapshot);
                    // We have a next matching burn item, check if we can poll one and then continue burning
                    if (optBurnTime.isPresent() && this.inventory.getFuelSlot().poll(1).isPresent()) {
                        maxBurnTime = optBurnTime.getAsInt();
                        remainingBurnTime = maxBurnTime;
                        elapsedBurnTime = 0;
                        // Put the rest item in the slot, if the slot is empty
                        if (this.inventory.getFuelSlot().size() == 0) {
                            final IIngredient ingredient = result.get().getIngredient();
                            final Optional<ItemStack> remainingItem = ingredient.getRemainingItem(itemStackSnapshot);
                            remainingItem.ifPresent(this.inventory.getFuelSlot()::setForced);
                        }
                    }
                }
            }
            if (maxBurnTime == 0) {
                break;
            }
        }
        elapsedBurnTime = maxBurnTime == 0 ? 0 : (int) (elapsedBurnTime + elapsed2);
        remainingBurnTime = maxBurnTime - elapsedBurnTime;
        offer(Keys.MAX_BURN_TIME, maxBurnTime);
        offer(Keys.PASSED_BURN_TIME, elapsedBurnTime);
        if (maxCookTime > 0) {
            // The furnace is still burning
            if (remainingBurnTime > 0) {
                // The item is smelted
                if (elapsed1 >= remainingCookTime) {
                    offer(Keys.MAX_COOK_TIME, 0);
                    offer(Keys.PASSED_COOK_TIME, 0);
                    final int quantity = ((ISmeltingRecipe) smeltingRecipe.get()).getIngredient().getQuantity(inputSlotItemSnapshot);
                    this.inventory.getOutputSlot().offer(smeltingResult.get().getResult().createStack());
                    this.inventory.getInputSlot().poll(quantity);
                    // Put the rest item in the slot
                    if (this.inventory.getInputSlot().size() == 0) {
                        final IIngredient ingredient = ((ISmeltingRecipe) smeltingRecipe.get()).getIngredient();
                        final Optional<ItemStack> remainingItem = ingredient.getRemainingItem(inputSlotItemSnapshot);
                        remainingItem.ifPresent(this.inventory.getInputSlot()::set);
                    }
                } else {
                    // Keep on smelting
                    offer(Keys.MAX_COOK_TIME, maxCookTime);
                    offer(Keys.PASSED_COOK_TIME, (int) (elapsedCookTime + elapsed1));
                    break;
                }
            } else if (elapsedCookTime > 0) {
                // Undo smelting progress
                final long time = elapsedCookTime - elapsed1 * 2;
                offer(Keys.MAX_COOK_TIME, time <= 0 ? 0 : maxCookTime);
                offer(Keys.PASSED_COOK_TIME, (int) (time <= 0 ? 0 : time));
                break;
            }
        } else {
            offer(Keys.MAX_COOK_TIME, 0);
            offer(Keys.PASSED_COOK_TIME, 0);
        }
    }
    BlockState blockState = getLocation().getBlock();
    final boolean burning = get(Keys.PASSED_BURN_TIME).get() < get(Keys.MAX_BURN_TIME).get();
    final boolean blockBurning = blockState.getType() == BlockTypes.LIT_FURNACE;
    if (burning != blockBurning) {
        blockState = (burning ? BlockTypes.LIT_FURNACE : BlockTypes.FURNACE).getDefaultState().withTrait(LanternEnumTraits.HORIZONTAL_FACING, blockState.getTraitValue(LanternEnumTraits.HORIZONTAL_FACING).get()).get();
        getLocation().setBlock(blockState);
    }
}
Also used : IIngredient(org.lanternpowered.server.item.recipe.IIngredient) PeekedOfferTransactionResult(org.lanternpowered.server.inventory.PeekedOfferTransactionResult) OptionalInt(java.util.OptionalInt) BlockState(org.spongepowered.api.block.BlockState) SmeltingRecipe(org.spongepowered.api.item.recipe.smelting.SmeltingRecipe) ISmeltingRecipe(org.lanternpowered.server.item.recipe.smelting.ISmeltingRecipe) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) IFuel(org.lanternpowered.server.item.recipe.fuel.IFuel) ISmeltingRecipe(org.lanternpowered.server.item.recipe.smelting.ISmeltingRecipe) ItemStack(org.spongepowered.api.item.inventory.ItemStack) SmeltingResult(org.spongepowered.api.item.recipe.smelting.SmeltingResult)

Example 43 with BlockState

use of org.spongepowered.api.block.BlockState in project LanternServer by LanternPowered.

the class LanternBlockState method merge.

@Override
public BlockState merge(BlockState that, MergeFunction function) {
    if (!getType().equals(that.getType())) {
        return this;
    } else {
        BlockState temp = this;
        for (ImmutableDataManipulator<?, ?> manipulator : that.getManipulators()) {
            final ImmutableDataManipulator old = temp.get(manipulator.getClass()).orElse(null);
            final Optional<BlockState> optional = temp.with(checkNotNull(function.merge(old, manipulator)));
            if (optional.isPresent()) {
                temp = optional.get();
            } else {
                return temp;
            }
        }
        return temp;
    }
}
Also used : BlockState(org.spongepowered.api.block.BlockState) ImmutableDataManipulator(org.spongepowered.api.data.manipulator.ImmutableDataManipulator)

Example 44 with BlockState

use of org.spongepowered.api.block.BlockState in project LanternServer by LanternPowered.

the class OpenableDoorInteractionBehavior method tryInteract.

@Override
public BehaviorResult tryInteract(BehaviorPipeline<Behavior> pipeline, BehaviorContext context) {
    BehaviorResult result = super.tryInteract(pipeline, context);
    if (result != BehaviorResult.SUCCESS && result != BehaviorResult.CONTINUE) {
        return result;
    }
    final Location<World> location = context.requireContext(ContextKeys.BLOCK_LOCATION);
    final BlockState baseState = location.getBlock();
    final LanternDoorHalf half = baseState.get(LanternKeys.DOOR_HALF).orElse(null);
    if (half == null) {
        return result;
    }
    final Direction dir = half == LanternDoorHalf.LOWER ? Direction.UP : Direction.DOWN;
    final LanternDoorHalf other = half == LanternDoorHalf.LOWER ? LanternDoorHalf.UPPER : LanternDoorHalf.LOWER;
    final Location<World> loc = location.getBlockRelative(dir);
    BlockState otherState = loc.getBlock();
    if (otherState.get(LanternKeys.DOOR_HALF).orElse(null) == other && otherState.with(LanternKeys.DOOR_HALF, half).orElse(null) == baseState) {
        result = super.tryInteract(pipeline, context);
    }
    return result;
}
Also used : LanternDoorHalf(org.lanternpowered.server.data.type.LanternDoorHalf) BlockState(org.spongepowered.api.block.BlockState) BehaviorResult(org.lanternpowered.server.behavior.BehaviorResult) World(org.spongepowered.api.world.World) Direction(org.spongepowered.api.util.Direction)

Example 45 with BlockState

use of org.spongepowered.api.block.BlockState in project LanternServer by LanternPowered.

the class PlayerInteractionHandler method handleBrokenBlock.

private void handleBrokenBlock() {
    final Location<World> location = new Location<>(this.player.getWorld(), this.diggingBlock);
    final CauseStack causeStack = CauseStack.current();
    try (CauseStack.Frame frame = causeStack.pushCauseFrame()) {
        frame.pushCause(this.player);
        // Add context
        frame.addContext(EventContextKeys.PLAYER, this.player);
        frame.addContext(ContextKeys.INTERACTION_LOCATION, location);
        frame.addContext(ContextKeys.BLOCK_LOCATION, location);
        final BehaviorContextImpl context = new BehaviorContextImpl(causeStack);
        final BlockState blockState = location.getBlock();
        final LanternBlockType blockType = (LanternBlockType) blockState.getType();
        if (context.process(blockType.getPipeline().pipeline(BreakBlockBehavior.class), (ctx, behavior) -> behavior.tryBreak(blockType.getPipeline(), ctx)).isSuccess()) {
            context.accept();
            this.diggingBlock = null;
            this.diggingBlockType = null;
        } else {
            context.revert();
            // TODO: Resend tile entity data, action data, ... ???
            this.player.sendBlockChange(this.diggingBlock, blockState);
        }
        if (this.lastBreakState != -1) {
            sendBreakUpdate(-1);
        }
    }
}
Also used : MessagePlayOutEntityAnimation(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityAnimation) LanternKeys(org.lanternpowered.server.data.key.LanternKeys) Keys(org.spongepowered.api.data.key.Keys) EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) LanternBlockType(org.lanternpowered.server.block.LanternBlockType) MessagePlayInPlayerSwingArm(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerSwingArm) BehaviorContextImpl(org.lanternpowered.server.behavior.BehaviorContextImpl) Vector3d(com.flowpowered.math.vector.Vector3d) MessagePlayInOutFinishUsingItem(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutFinishUsingItem) MessagePlayInPlayerDigging(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerDigging) HandType(org.spongepowered.api.data.type.HandType) MinimumUseDurationProperty(org.lanternpowered.server.item.property.MinimumUseDurationProperty) GameModes(org.spongepowered.api.entity.living.player.gamemode.GameModes) BreakBlockBehavior(org.lanternpowered.server.block.behavior.types.BreakBlockBehavior) ItemStack(org.spongepowered.api.item.inventory.ItemStack) BehaviorContext(org.lanternpowered.server.behavior.BehaviorContext) CauseStack(org.lanternpowered.server.event.CauseStack) InteractWithItemBehavior(org.lanternpowered.server.item.behavior.types.InteractWithItemBehavior) MessagePlayOutBlockBreakAnimation(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutBlockBreakAnimation) BehaviorResult(org.lanternpowered.server.behavior.BehaviorResult) LanternWorld(org.lanternpowered.server.world.LanternWorld) InteractWithBlockBehavior(org.lanternpowered.server.block.behavior.types.InteractWithBlockBehavior) Nullable(javax.annotation.Nullable) ContextKeys(org.lanternpowered.server.behavior.ContextKeys) FinishUsingItemBehavior(org.lanternpowered.server.item.behavior.types.FinishUsingItemBehavior) Location(org.spongepowered.api.world.Location) MaximumUseDurationProperty(org.lanternpowered.server.item.property.MaximumUseDurationProperty) LanternItemType(org.lanternpowered.server.item.LanternItemType) MessagePlayInPlayerUseItem(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerUseItem) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) BlockTypes(org.spongepowered.api.block.BlockTypes) SwingHandEntityEvent(org.lanternpowered.server.entity.event.SwingHandEntityEvent) Set(java.util.Set) LanternGame(org.lanternpowered.server.game.LanternGame) BlockState(org.spongepowered.api.block.BlockState) Objects(java.util.Objects) Direction(org.spongepowered.api.util.Direction) DualWieldProperty(org.lanternpowered.server.item.property.DualWieldProperty) Lantern(org.lanternpowered.server.game.Lantern) Vector3i(com.flowpowered.math.vector.Vector3i) World(org.spongepowered.api.world.World) BlockType(org.spongepowered.api.block.BlockType) HandTypes(org.spongepowered.api.data.type.HandTypes) Optional(java.util.Optional) MessagePlayInPlayerBlockPlacement(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerBlockPlacement) CauseStack(org.lanternpowered.server.event.CauseStack) BehaviorContextImpl(org.lanternpowered.server.behavior.BehaviorContextImpl) BlockState(org.spongepowered.api.block.BlockState) LanternWorld(org.lanternpowered.server.world.LanternWorld) World(org.spongepowered.api.world.World) LanternBlockType(org.lanternpowered.server.block.LanternBlockType) Location(org.spongepowered.api.world.Location)

Aggregations

BlockState (org.spongepowered.api.block.BlockState)133 World (org.spongepowered.api.world.World)39 IBlockState (net.minecraft.block.state.IBlockState)29 BlockType (org.spongepowered.api.block.BlockType)27 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)22 Direction (org.spongepowered.api.util.Direction)21 Optional (java.util.Optional)20 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)20 Vector3i (com.flowpowered.math.vector.Vector3i)19 Location (org.spongepowered.api.world.Location)18 ItemStack (org.spongepowered.api.item.inventory.ItemStack)17 LocatableBlock (org.spongepowered.api.world.LocatableBlock)14 Sponge (org.spongepowered.api.Sponge)13 ItemType (org.spongepowered.api.item.ItemType)13 ArrayList (java.util.ArrayList)12 Player (org.spongepowered.api.entity.living.player.Player)12 List (java.util.List)11 InvalidDataException (org.spongepowered.api.data.persistence.InvalidDataException)11 Vector3d (com.flowpowered.math.vector.Vector3d)10 Listener (org.spongepowered.api.event.Listener)10