#i want to make a block like stairs (different states, states differ) 1.20.1

3 messages · Page 1 of 1 (latest)

thorny agate
#

but I have too little experience, what i did wrong?

public class StaircaseBlock extends Block {
    public static final DirectionProperty FACING = HorizontalFacingBlock.FACING;
    private final Block baseBlock;
    private final BlockState baseBlockState;

    private static final VoxelShape SHAPE = VoxelShapes.cuboid(
            0.0, 0.0, 0.0,
            1.0, 0.5, 1.0);

    private static final VoxelShape NORTH_SHAPE = VoxelShapes.cuboid(
            0.0, 0.0, 0.0,
            1.0, 1.0, 0.5);
    private static final VoxelShape SOUTH_SHAPE = VoxelShapes.cuboid(
            0.0, 0.0, 0.5,
            1.0, 1.0, 0.5);
    private static final VoxelShape WEST_SHAPE = VoxelShapes.cuboid(
            0.0, 0.0, 0.0,
            0.5, 1.0, 1.0);
    private static final VoxelShape EAST_SHAPE = VoxelShapes.cuboid(
            0.5, 0.0, 0.0,
            0.5, 1.0, 1.0);

    public StaircaseBlock(BlockState baseBlockState, AbstractBlock.Settings settings) {
        super(settings);

        MrMyronsFurnitureMod.LOGGER.info( "43125" );

        this.setDefaultState(
                this.stateManager
                        .getDefaultState()
                        .with(FACING, Direction.NORTH)
        );
        this.baseBlock = baseBlockState.getBlock();
        this.baseBlockState = baseBlockState;
    }

    @Override
    public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {

            //MrMyronsFurnitureMod.LOGGER.info( "" + state.get(FACING).getHorizontal() );

        return SHAPE;
    }

    @Override
    public BlockRenderType getRenderType(BlockState state) {
        return BlockRenderType.MODEL;
    }

}

when i run it says Caused by: java.lang.IllegalArgumentException: Cannot set property DirectionProperty{name=facing, clazz=class net.minecraft.util.math.Direction, values=[north, south, west, east]} as it does not exist in Block{minecraft:air}

wide linden
#

!!appendproperties

tranquil tapirBOT
#

When trying to create a block with block state properties you might come across an error like this:
java.lang.IllegalArgumentException: Cannot set property ... as it does not exist in Block{minecraft:air}

This happens when you don't (correctly) override the appendProperties method in your block class. Overriding this method is necessary to tell minecraft which properties your block has.
It should look something like this:

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
	builder.add(YOUR, PROPERTIES, HERE);
}

On older versions (before 1.20.5) the method has to be public instead of protected.

The error refers to your block as minecraft:air because it usually hasn't been registered by the time the error is thrown.
You can usually find which block is having issues by looking for the constructor of it in the stacktrace.