package su.a71.new_soviet.util;

import net.minecraft.block.Block;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;

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

public class Shapes {
    public static class NHShape{
        private VoxelShape NORTH;
        private VoxelShape WEST;
        private VoxelShape SOUTH;
        private VoxelShape EAST;
        private double minX;
        private double minY;
        private double minZ;
        private double maxX;
        private double maxY;
        private double maxZ;

        public NHShape(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
            this.minX = minX;
            this.minY = minY;
            this.minZ = minZ;
            this.maxX = maxX;
            this.maxY = maxY;
            this.maxZ = maxZ;
            this.NORTH = Block.createCuboidShape(minX, minY, minZ, maxX, maxY, maxZ);
            this.WEST = Block.createCuboidShape(minZ, minY, minX, maxZ, maxY, maxX);
            this.SOUTH = Block.createCuboidShape(minX, minY, (16 - maxZ), maxX, maxY, (16 - minZ));
            this.EAST = Block.createCuboidShape((16 - maxZ), minY, minX, (16 - minZ), maxY, maxX);
        }

        public VoxelShape north(){
            return NORTH;
        }

        public VoxelShape west(){
            return WEST;
        }

        public VoxelShape south(){
            return SOUTH;
        }

        public VoxelShape east(){
            return EAST;
        }
    }

    public static class NHShape2{
        private VoxelShape NORTH;
        private VoxelShape WEST;
        private VoxelShape SOUTH;
        private VoxelShape EAST;
        private double minX;
        private double minY;
        private double minZ;
        private double maxX;
        private double maxY;
        private double maxZ;

        public NHShape2(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
            this.minX = minX;
            this.minY = minY;
            this.minZ = minZ;
            this.maxX = maxX;
            this.maxY = maxY;
            this.maxZ = maxZ;
            this.NORTH = Block.createCuboidShape((16 - maxX), minY, minZ, (16 - minX), maxY, maxZ);
            this.WEST = Block.createCuboidShape(minZ, minY, minX, maxZ, maxY, maxX);
            this.SOUTH = Block.createCuboidShape(minX, minY, (16 - maxZ), maxX, maxY, (16 - minZ));
            this.EAST = Block.createCuboidShape((16 - maxZ), minY, (16 - maxX), (16 - minZ), maxY, (16 - minX));
        }

        public VoxelShape north(){
            return NORTH;
        }

        public VoxelShape west(){
            return WEST;
        }

        public VoxelShape south(){
            return SOUTH;
        }

        public VoxelShape east(){
            return EAST;
        }
    }

    public static class HorizontalShape{
        private List ShapesListN;
        private List ShapesListS;
        private List ShapesListW;
        private List ShapesListE;
        public HorizontalShape(List<List<Double>> list) {
            this.ShapesListN = new ArrayList<>();
            this.ShapesListS = new ArrayList<>();
            this.ShapesListW = new ArrayList<>();
            this.ShapesListE = new ArrayList<>();
            for (List<Double> i : list) {
                NHShape shape = new NHShape(i.get(0), i.get(1), i.get(2), i.get(3), i.get(4), i.get(5));
                ShapesListN.add(shape.north());
                ShapesListS.add(shape.south());
                ShapesListW.add(shape.west());
                ShapesListE.add(shape.east());
            }
        }

        public VoxelShape north() {
            VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);
            for (int i=0;i<ShapesListN.size();i++) {
                shape = VoxelShapes.union(shape, (VoxelShape) ShapesListN.get(i));
            }
            return shape;
        }

        public VoxelShape west() {
            VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
            for (int i=0;i<ShapesListW.size();i++) {
                shape = VoxelShapes.union(shape, (VoxelShape) ShapesListW.get(i));
            }
            return shape;
        }

        public VoxelShape south() {
            VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
            for (int i=0;i<ShapesListS.size();i++) {
                shape = VoxelShapes.union(shape, (VoxelShape) ShapesListS.get(i));
            }
            return shape;
        }

        public VoxelShape east() {
            VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
            for (int i=0;i<ShapesListE.size();i++) {
                shape = VoxelShapes.union(shape, (VoxelShape) ShapesListE.get(i));
            }
            return shape;
        }
    }

    public static class HorizontalShape2{
        private List ShapesListN;
        private List ShapesListS;
        private List ShapesListW;
        private List ShapesListE;
        public HorizontalShape2(List<List<Double>> list) {
            this.ShapesListN = new ArrayList<>();
            this.ShapesListS = new ArrayList<>();
            this.ShapesListW = new ArrayList<>();
            this.ShapesListE = new ArrayList<>();
            for (List<Double> i : list) {
                NHShape2 shape = new NHShape2(i.get(0), i.get(1), i.get(2), i.get(3), i.get(4), i.get(5));
                ShapesListN.add(shape.north());
                ShapesListS.add(shape.south());
                ShapesListW.add(shape.west());
                ShapesListE.add(shape.east());
            }
        }

        public VoxelShape north() {
            VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);
            for (int i=0;i<ShapesListN.size();i++) {
                shape = VoxelShapes.union(shape, (VoxelShape) ShapesListN.get(i));
            }
            return shape;
        }

        public VoxelShape west() {
            VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
            for (int i=0;i<ShapesListW.size();i++) {
                shape = VoxelShapes.union(shape, (VoxelShape) ShapesListW.get(i));
            }
            return shape;
        }

        public VoxelShape south() {
            VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
            for (int i=0;i<ShapesListS.size();i++) {
                shape = VoxelShapes.union(shape, (VoxelShape) ShapesListS.get(i));
            }
            return shape;
        }

        public VoxelShape east() {
            VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
            for (int i=0;i<ShapesListE.size();i++) {
                shape = VoxelShapes.union(shape, (VoxelShape) ShapesListE.get(i));
            }
            return shape;
        }
    }
}

