Search in sources :

Example 1 with WallSide

use of net.minecraft.world.level.block.state.properties.WallSide in project MC-Prefab by Brian-Wuest.

the class BuildBlock method SetBlockState.

public static BuildBlock SetBlockState(StructureConfiguration configuration, BlockPos originalPos, BuildBlock block, Block foundBlock, BlockState blockState, Direction structureDirection) {
    try {
        if (!block.blockStateData.equals("")) {
            return BuildBlock.SetBlockStateFromTagData(configuration, originalPos, block, foundBlock, blockState, structureDirection);
        }
        Direction vineFacing = BuildBlock.getVineFacing(configuration, foundBlock, block, structureDirection);
        Direction.Axis logFacing = BuildBlock.getBoneFacing(configuration, foundBlock, block, structureDirection);
        Direction.Axis boneFacing = BuildBlock.getBoneFacing(configuration, foundBlock, block, structureDirection);
        Direction leverOrientation = BuildBlock.getLeverOrientation(configuration, foundBlock, block, structureDirection);
        Map<Direction, Boolean> fourWayFacings = BuildBlock.getFourWayBlockFacings(configuration, foundBlock, block, structureDirection);
        Map<Direction, WallSide> wallShapes = BuildBlock.getWallFacings(configuration, foundBlock, block, structureDirection);
        // expected to place the block.
        if (block.getProperties().size() > 0) {
            Collection<Property<?>> properties = blockState.getProperties();
            // applied.
            for (Property<?> property : properties) {
                BuildProperty buildProperty = block.getProperty(property.getName());
                // mod (or sometimes vanilla) adds properties to vanilla blocks.
                if (buildProperty != null) {
                    try {
                        Optional<?> propertyValue = property.getValue(buildProperty.getValue());
                        if (!propertyValue.isPresent() || propertyValue.getClass().getName().equals("com.google.common.base.Absent")) {
                            Prefab.LOGGER.warn("Property value for property name [" + property.getName() + "] for block [" + block.getBlockName() + "] is considered Absent, figure out why.");
                            continue;
                        }
                        Comparable<?> comparable = property.getValueClass().cast(propertyValue.get());
                        comparable = BuildBlock.setComparable(comparable, foundBlock, property, configuration.houseFacing, block, propertyValue, vineFacing, logFacing, boneFacing, leverOrientation, structureDirection, fourWayFacings, wallShapes);
                        if (comparable == null) {
                            continue;
                        }
                        try {
                            if (blockState.getValue(property) != comparable) {
                                blockState = BuildBlock.setProperty(blockState, property, comparable);
                            }
                        } catch (Exception ex) {
                            System.out.println("Error setting properly value for property name [" + property.getName() + "] property value [" + buildProperty.getValue() + "] for block [" + block.getBlockName() + "] The default value will be used.");
                        }
                    } catch (Exception ex) {
                        System.out.println("Error getting properly value for property name [" + property.getName() + "] property value [" + buildProperty.getValue() + "] for block [" + block.getBlockName() + "]");
                        throw ex;
                    }
                }
            }
        }
        block.setBlockState(blockState);
        return block;
    } catch (Exception ex) {
        System.out.println("Error setting block state for block [" + block.getBlockName() + "] for structure configuration class [" + configuration.getClass().getName() + "]");
        throw ex;
    }
}
Also used : WallSide(net.minecraft.world.level.block.state.properties.WallSide) Direction(net.minecraft.core.Direction) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) Property(net.minecraft.world.level.block.state.properties.Property)

Example 2 with WallSide

use of net.minecraft.world.level.block.state.properties.WallSide in project MC-Prefab by Brian-Wuest.

the class BuildBlock method getWallFacings.

private static Map<Direction, WallSide> getWallFacings(StructureConfiguration configuration, Block foundBlock, BuildBlock block, Direction assumedNorth) {
    Map<Direction, WallSide> facings = new HashMap<>();
    if (foundBlock instanceof WallBlock) {
        // Valid states can be any two directions at a time, not just opposites but adjacents as well (for corners).
        WallSide northValue = BuildBlock.getShapeByName(block.getProperty("north").getValue());
        WallSide eastValue = BuildBlock.getShapeByName(block.getProperty("east").getValue());
        WallSide westValue = BuildBlock.getShapeByName(block.getProperty("west").getValue());
        WallSide southValue = BuildBlock.getShapeByName(block.getProperty("south").getValue());
        WallSide originalNorth = northValue;
        WallSide originalEast = eastValue;
        WallSide originalWest = westValue;
        WallSide originalSouth = southValue;
        if (configuration.houseFacing.getClockWise() == assumedNorth) {
            northValue = originalWest;
            eastValue = originalNorth;
            southValue = originalEast;
            westValue = originalSouth;
        } else if (configuration.houseFacing == assumedNorth) {
            northValue = originalSouth;
            eastValue = originalWest;
            southValue = originalNorth;
            westValue = originalEast;
        } else if (configuration.houseFacing.getCounterClockWise() == assumedNorth) {
            northValue = originalEast;
            eastValue = originalSouth;
            southValue = originalWest;
            westValue = originalNorth;
        }
        facings.put(Direction.NORTH, northValue);
        facings.put(Direction.EAST, eastValue);
        facings.put(Direction.WEST, westValue);
        facings.put(Direction.SOUTH, southValue);
    }
    return facings;
}
Also used : WallSide(net.minecraft.world.level.block.state.properties.WallSide) Direction(net.minecraft.core.Direction)

Aggregations

Direction (net.minecraft.core.Direction)2 WallSide (net.minecraft.world.level.block.state.properties.WallSide)2 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)1 Property (net.minecraft.world.level.block.state.properties.Property)1