#How to rotate blocks around z axis?

7 messages · Page 1 of 1 (latest)

noble copper
#

I'm making a button, and I wanted to have it be able to face any direction, while also being able to rotate the output around. X and Y work, but I can't seem to get it to rotate around Z.

block states:

{
  "variants": {
    "facing=north,rotation=1": { "model": "mymod:block/big_button", "x": 270, "y": 0, "z": 0 },
    "facing=north,rotation=2": { "model": "mymod:block/big_button", "x": 270, "y": 0, "z": 90 },
    "facing=north,rotation=3": { "model": "mymod:block/big_button", "x": 270, "y": 0, "z": 180 },
    "facing=north,rotation=4": { "model": "mymod:block/big_button", "x": 270, "y": 0, "z": 270 },

    "facing=south": { "model": "mymod:block/big_button", "x": 90 },


    "facing=east": { "model": "mymod:block/big_button", "x": 90, "y": 90 },


    "facing=west": { "model": "mymod:block/big_button", "x": 90, "y": 270 },


    "facing=up": { "model": "mymod:block/big_button", "y": 90 },


    "facing=down": { "model": "mymod:block/big_button", "y": 90, "x": 180 }
  }
}
#

block code:

public class BigButton extends Block {
    public static final IntProperty ROTATION = IntProperty.of("rotation", 1, 4);

    public BigButton(Settings settings) {
        super(settings);
        setDefaultState(getDefaultState().with(Properties.FACING, Direction.NORTH).with(ROTATION, 1));
    }

    public static final MapCodec<BigButton> CODEC = Block.createCodec(BigButton::new);

    @Override
    protected MapCodec<? extends BigButton> getCodec() {
        return CODEC;
    }

    @Override
    protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
        builder.add(Properties.FACING, ROTATION);
    }

    @Override
    public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) {
        return VoxelShapes.fullCube();
    }

    @Override
    public BlockState getPlacementState(ItemPlacementContext ctx) {
        Direction facing = ctx.getHorizontalPlayerFacing();
        int rotation = 1;

        return this.getDefaultState()
                .with(Properties.FACING, facing)
                .with(ROTATION, rotation);
    }
}
regal sage
#

You might have to rotate around both the X and Y axes to simulate rotation around Z.

noble copper
#

Is there anyway to reload the blockstates from in game, constantly restarting the game is taking quite a bit 😅

noble copper
#

I've think gone through all the combinations (unless I managed to miss one) and unfortunately i dont think i can get the horizontal ones to get all 4 rotations

#

i there any other way to rotate around z or get the same effect

noble copper
#

Ended up just making a second model with a 90 degree rotation and using that for the other 2 rotations