Search in sources :

Example 1 with Half

use of net.minecraft.state.properties.Half in project Mekanism by mekanism.

the class AdditionsBlockStateProvider method coloredStairs.

private void coloredStairs(Map<?, ? extends BlockRegistryObject<? extends BlockPlasticStairs, ?>> stairs, String existingPrefix) {
    ModelFile stairsModel = models().getExistingFile(modLoc("block/plastic/" + existingPrefix + "stairs"));
    ModelFile stairsInner = models().getExistingFile(modLoc("block/plastic/" + existingPrefix + "stairs_inner"));
    ModelFile stairsOuter = models().getExistingFile(modLoc("block/plastic/" + existingPrefix + "stairs_outer"));
    for (BlockRegistryObject<? extends BlockPlasticStairs, ?> stair : stairs.values()) {
        BlockPlasticStairs block = stair.getBlock();
        // Copy of BlockStateProvider#stairsBlock, except also ignores our fluid logging extension
        getVariantBuilder(block).forAllStatesExcept(state -> {
            Direction facing = state.getValue(StairsBlock.FACING);
            Half half = state.getValue(StairsBlock.HALF);
            StairsShape shape = state.getValue(StairsBlock.SHAPE);
            // Stairs model is rotated 90 degrees clockwise for some reason
            int yRot = (int) facing.getClockWise().toYRot();
            if (shape == StairsShape.INNER_LEFT || shape == StairsShape.OUTER_LEFT) {
                // Left facing stairs are rotated 90 degrees clockwise
                yRot += 270;
            }
            if (shape != StairsShape.STRAIGHT && half == Half.TOP) {
                // Top stairs are rotated 90 degrees clockwise
                yRot += 90;
            }
            yRot %= 360;
            // Don't set uvlock for states that have no rotation
            boolean uvlock = yRot != 0 || half == Half.TOP;
            return ConfiguredModel.builder().modelFile(shape == StairsShape.STRAIGHT ? stairsModel : shape == StairsShape.INNER_LEFT || shape == StairsShape.INNER_RIGHT ? stairsInner : stairsOuter).rotationX(half == Half.BOTTOM ? 0 : 180).rotationY(yRot).uvLock(uvlock).build();
        }, StairsBlock.WATERLOGGED, block.getFluidLoggedProperty());
    }
}
Also used : Half(net.minecraft.state.properties.Half) ModelFile(net.minecraftforge.client.model.generators.ModelFile) BlockPlasticStairs(mekanism.additions.common.block.plastic.BlockPlasticStairs) StairsShape(net.minecraft.state.properties.StairsShape) Direction(net.minecraft.util.Direction)

Example 2 with Half

use of net.minecraft.state.properties.Half in project Structurize by ldtteam.

the class ModBlockStateProvider method stairsBlockUnlockUV.

public void stairsBlockUnlockUV(StairsBlock block, ModelFile stairs, ModelFile stairsInner, ModelFile stairsOuter) {
    getVariantBuilder(block).forAllStatesExcept(state -> {
        Direction facing = state.getValue(StairsBlock.FACING);
        Half half = state.getValue(StairsBlock.HALF);
        StairsShape shape = state.getValue(StairsBlock.SHAPE);
        // Stairs model is rotated 90 degrees clockwise for some reason
        int yRot = (int) facing.getClockWise().toYRot();
        if (shape == StairsShape.INNER_LEFT || shape == StairsShape.OUTER_LEFT) {
            // Left facing stairs are rotated 90 degrees clockwise
            yRot += 270;
        }
        if (shape != StairsShape.STRAIGHT && half == Half.TOP) {
            // Top stairs are rotated 90 degrees clockwise
            yRot += 90;
        }
        yRot %= 360;
        return ConfiguredModel.builder().modelFile(shape == StairsShape.STRAIGHT ? stairs : shape == StairsShape.INNER_LEFT || shape == StairsShape.INNER_RIGHT ? stairsInner : stairsOuter).rotationX(half == Half.BOTTOM ? 0 : 180).rotationY(yRot).uvLock(false).build();
    }, StairsBlock.WATERLOGGED);
}
Also used : Half(net.minecraft.state.properties.Half) StairsShape(net.minecraft.state.properties.StairsShape) Direction(net.minecraft.util.Direction)

Example 3 with Half

use of net.minecraft.state.properties.Half in project Materialis by RCXcrafter.

the class WrenchingModifier method blockUse.

public ActionResultType blockUse(IModifierToolStack tool, int level, World world, BlockPos pos, BlockState state, ItemUseContext context) {
    if (context.getPlayer().isSecondaryUseActive() || !state.getBlock().canEntityDestroy(state, world, pos, context.getPlayer()) || state.getHarvestLevel() > tool.getStats().getInt(ToolStats.HARVEST_LEVEL) || !isRotatable(state, world, pos))
        return ActionResultType.PASS;
    Direction face = context.getClickedFace();
    Rotation rotation = context.getClickedFace().getAxisDirection() == Direction.AxisDirection.POSITIVE ? Rotation.CLOCKWISE_90 : Rotation.COUNTERCLOCKWISE_90;
    for (Property<?> prop : state.getProperties()) {
        if (prop instanceof DirectionProperty) {
            Direction direction = state.getValue((DirectionProperty) prop);
            Direction newDirection = rotateDirection(direction, face.getAxis(), rotation);
            if (newDirection != direction) {
                // make sure something changed
                BlockState newState = null;
                // check if the block can even be rotated like this
                int attempts = 0;
                boolean success = false;
                while (attempts < 3) {
                    if (prop.getPossibleValues().contains(newDirection)) {
                        newState = state.setValue((DirectionProperty) prop, newDirection);
                        if (newState.canSurvive(world, pos)) {
                            success = true;
                            break;
                        }
                    }
                    // try the next rotation
                    newDirection = rotateDirection(newDirection, face.getAxis(), rotation);
                    attempts++;
                }
                if (success) {
                    world.setBlock(pos, newState, Constants.BlockFlags.DEFAULT_AND_RERENDER);
                    ToolDamageUtil.damage(tool, 1, context.getPlayer(), context.getItemInHand());
                    return ActionResultType.SUCCESS;
                }
            }
        }
        if (prop == BlockStateProperties.AXIS || prop == BlockStateProperties.HORIZONTAL_AXIS) {
            Direction.Axis axis = prop == BlockStateProperties.AXIS ? state.getValue(BlockStateProperties.AXIS) : state.getValue(BlockStateProperties.HORIZONTAL_AXIS);
            Direction.Axis newAxis = rotateAxis(axis, face.getAxis(), rotation);
            if (newAxis != axis) {
                // check if the block can even be rotated like this
                if (prop.getPossibleValues().contains(newAxis)) {
                    BlockState newState;
                    if (prop == BlockStateProperties.AXIS)
                        newState = state.setValue(BlockStateProperties.AXIS, newAxis);
                    else
                        newState = state.setValue(BlockStateProperties.HORIZONTAL_AXIS, newAxis);
                    if (newState.canSurvive(world, pos)) {
                        world.setBlock(pos, newState, Constants.BlockFlags.DEFAULT_AND_RERENDER);
                        ToolDamageUtil.damage(tool, 1, context.getPlayer(), context.getItemInHand());
                        return ActionResultType.SUCCESS;
                    }
                }
            }
        }
        if (prop == BlockStateProperties.RAIL_SHAPE || prop == BlockStateProperties.RAIL_SHAPE_STRAIGHT) {
            RailShape shape = prop == BlockStateProperties.RAIL_SHAPE ? state.getValue(BlockStateProperties.RAIL_SHAPE) : state.getValue(BlockStateProperties.RAIL_SHAPE_STRAIGHT);
            RailShape newShape = rotateRail(shape, face.getAxis(), rotation);
            if (newShape != shape) {
                // check if the block can even be rotated like this
                if (shouldRailBeRemoved(pos, world, newShape))
                    newShape = rotateRail(shape, face.getAxis(), rotation.getRotated(Rotation.CLOCKWISE_180));
                if (!shouldRailBeRemoved(pos, world, newShape) && prop.getPossibleValues().contains(newShape)) {
                    BlockState newState;
                    if (prop == BlockStateProperties.RAIL_SHAPE)
                        newState = state.setValue(BlockStateProperties.RAIL_SHAPE, newShape);
                    else
                        newState = state.setValue(BlockStateProperties.RAIL_SHAPE_STRAIGHT, newShape);
                    world.setBlock(pos, newState, Constants.BlockFlags.DEFAULT_AND_RERENDER);
                    ToolDamageUtil.damage(tool, 1, context.getPlayer(), context.getItemInHand());
                    return ActionResultType.SUCCESS;
                }
            }
        }
        if (prop == BlockStateProperties.ROTATION_16) {
            int rotation16 = state.getValue(BlockStateProperties.ROTATION_16);
            rotation16 = (rotation16 + 1) % 16;
            world.setBlock(pos, state.setValue(BlockStateProperties.ROTATION_16, rotation16), Constants.BlockFlags.DEFAULT_AND_RERENDER);
            ToolDamageUtil.damage(tool, 1, context.getPlayer(), context.getItemInHand());
            return ActionResultType.SUCCESS;
        }
        if (prop == BlockStateProperties.HALF) {
            Half half = state.getValue(BlockStateProperties.HALF);
            if (half == Half.TOP)
                half = Half.BOTTOM;
            else
                half = Half.TOP;
            BlockState newState = state.setValue(BlockStateProperties.HALF, half);
            if (newState.canSurvive(world, pos)) {
                world.setBlock(pos, state.setValue(BlockStateProperties.HALF, half), Constants.BlockFlags.DEFAULT_AND_RERENDER);
                ToolDamageUtil.damage(tool, 1, context.getPlayer(), context.getItemInHand());
                return ActionResultType.SUCCESS;
            }
        }
        if (prop == BlockStateProperties.SLAB_TYPE) {
            SlabType half = state.getValue(BlockStateProperties.SLAB_TYPE);
            if (half != SlabType.DOUBLE) {
                if (half == SlabType.TOP)
                    half = SlabType.BOTTOM;
                else
                    half = SlabType.TOP;
                BlockState newState = state.setValue(BlockStateProperties.SLAB_TYPE, half);
                if (newState.canSurvive(world, pos)) {
                    world.setBlock(pos, newState, Constants.BlockFlags.DEFAULT_AND_RERENDER);
                    ToolDamageUtil.damage(tool, 1, context.getPlayer(), context.getItemInHand());
                    return ActionResultType.SUCCESS;
                }
            }
        }
    }
    return ActionResultType.PASS;
}
Also used : Half(net.minecraft.state.properties.Half) SlabType(net.minecraft.state.properties.SlabType) BlockState(net.minecraft.block.BlockState) RailShape(net.minecraft.state.properties.RailShape) DirectionProperty(net.minecraft.state.DirectionProperty) Direction(net.minecraft.util.Direction) Rotation(net.minecraft.util.Rotation)

Aggregations

Half (net.minecraft.state.properties.Half)3 Direction (net.minecraft.util.Direction)3 StairsShape (net.minecraft.state.properties.StairsShape)2 BlockPlasticStairs (mekanism.additions.common.block.plastic.BlockPlasticStairs)1 BlockState (net.minecraft.block.BlockState)1 DirectionProperty (net.minecraft.state.DirectionProperty)1 RailShape (net.minecraft.state.properties.RailShape)1 SlabType (net.minecraft.state.properties.SlabType)1 Rotation (net.minecraft.util.Rotation)1 ModelFile (net.minecraftforge.client.model.generators.ModelFile)1