package com.r3944realms.modernlifepatch.utils;

import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;

import java.util.ArrayList;
import java.util.List;

public final class ShapeUtil {
    public static void initializeByNorth(VoxelShape north, VoxelShape east, VoxelShape south, VoxelShape west) {
        east = ShapeUtil.RotateVoxelShapeClockwise(north);
        south = ShapeUtil.RotateVoxelShapeClockwise(east);
        west = ShapeUtil.RotateVoxelShapeClockwise(south);
    }
    public static VoxelShape RotateVoxelShapeClockwise(VoxelShape in) {
        final List<VoxelShape> generatedShapes = new ArrayList<>();
        in.forAllBoxes((arg0, arg1, arg2, arg3, arg4, arg5) -> {
            VoxelShape shape = Shapes.box(1.0 - arg5, arg1, arg0, 1.0 - arg2, arg4, arg3);
            generatedShapes.add(shape);
        });
        if (generatedShapes.isEmpty()) {
            return Shapes.block();
        } else {
            VoxelShape out = generatedShapes.get(0);

            for(int i = 1; i < generatedShapes.size(); ++i) {
                VoxelShape shape = generatedShapes.get(i);
                out = Shapes.or(out, shape);
            }

            out.optimize();
            return out;
        }
    }
}
