Jump to content

Generating VoxelShapes from model


Robsutar

Recommended Posts

I would like to know if there is a faster method of generating VoxelShapes in different directions in a less boring way, currently I go to the blockbench, rotate my block to a certain direction, and export the model's VoxelShape in that direction. I have to do this for all six directions (north, east, south, west, up, down) every time I create a new rotating block.

Code:

    private static final VoxelShape NORTH = Shapes.box(0.25, 0.25, 0, 0.75, 0.75, 0.25);
    private static final VoxelShape EAST = Shapes.box(0.75, 0.25, 0.25, 1, 0.75, 0.75);
    private static final VoxelShape SOUTH = Shapes.box(0.25, 0.25, 0.75, 0.75, 0.75, 1);
    private static final VoxelShape WEST = Shapes.box(0, 0.25, 0.25, 0.25, 0.75, 0.75);
    private static final VoxelShape UP = Shapes.box(0.25, 0.75, 0.25, 0.75, 1, 0.75);
    private static final VoxelShape DOWN = Shapes.box(0.25, 0, 0.25, 0.75, 0.25, 0.75);
    @Override
    public @NotNull VoxelShape getShape(BlockState state, BlockGetter p_60556_, BlockPos p_60557_, CollisionContext p_60558_) {
        switch (state.getValue(FACING)) {
            case DOWN -> {
                return DOWN;
            }
            case UP -> {
                return UP;
            }
            case SOUTH -> {
                return SOUTH;
            }
            case WEST -> {
                return WEST;
            }
            case EAST -> {
                return EAST;
            }
            default -> {
                return NORTH;
            }
        }
    }

File generated by Blockbench (using extension) in north direction:

public VoxelShape makeShape(){
	VoxelShape shape = VoxelShapes.empty();
	shape = VoxelShapes.join(shape, VoxelShapes.box(0.25, 0.25, 0, 0.75, 0.75, 0.25), IBooleanFunction.OR);
    	//                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the values used in the static field "NORTH"
	return shape;
}

Remembering that the model from all directions is the same, but rotated.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.