Jump to content

Recommended Posts

Posted (edited)

Is there any way to rotate VoxelShapes? I got various 12+ cube VoxelShapes blocks and it is.. frustrating to do it by hand like vanilla

 

I ended up doing a thingy to automate it

Edited by Afroman
  • 7 months later...
Posted (edited)

For anyone looking, the following code will rotate a VoxelShape around an axis:

public static VoxelShape rotateShape(Direction from, Direction to, VoxelShape shape) {
	VoxelShape[] buffer = new VoxelShape[]{ shape, VoxelShapes.empty() };

	int times = (to.getHorizontalIndex() - from.getHorizontalIndex() + 4) % 4;
	for (int i = 0; i < times; i++) {
		buffer[0].forEachBox((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = VoxelShapes.or(buffer[1], VoxelShapes.create(1-maxZ, minY, minX, 1-minZ, maxY, maxX)));
		buffer[0] = buffer[1];
		buffer[1] = VoxelShapes.empty();
	}

	return buffer[0];
}

 

Edited by wyn_price
Fixed mappings
  • Like 1
  • Thanks 2
  • 2 years later...
Posted

For anyone still wondering, here is the updated code for 1.19.3 with parchment mappings.

 

   public static VoxelShape rotateShape(Direction from, Direction to, VoxelShape shape) {
        VoxelShape[] buffer = new VoxelShape[]{shape, Shapes.empty()};

        int times = (to.ordinal() - from.get2DDataValue() + 4) % 4;
        for (int i = 0; i < times; i++) {
            buffer[0].forAllBoxes((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = Shapes.or(buffer[1], Shapes.create(1 - maxZ, minY, minX, 1 - minZ, maxY, maxX)));
            buffer[0] = buffer[1];
            buffer[1] = Shapes.empty();
        }

        return buffer[0];
    }

 

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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