Search in sources :

Example 6 with PositionedRect

use of gregtech.api.util.PositionedRect in project GregTech by GregTechCE.

the class StonePileModelGenerator method generateCuboidList.

private static List<IndexedCuboid6> generateCuboidList(Random random) {
    ArrayList<IndexedCuboid6> result = new ArrayList<>();
    List<PositionedRect> occupiedAreas = new ArrayList<>();
    int stonePlaceAttempts = 64;
    int maxStones = 8;
    int stonesPlaced = 0;
    for (int i = 0; i < stonePlaceAttempts && stonesPlaced < maxStones; i++) {
        int sizeX = 2 + random.nextInt(3);
        int sizeZ = 2 + random.nextInt(3);
        int stoneHeight = 4 + random.nextInt(4);
        int posX = random.nextInt(16 - sizeX);
        int posZ = random.nextInt(16 - sizeZ);
        PositionedRect rect = new PositionedRect(new Position(posX, posZ), new Size(sizeX, sizeZ));
        if (occupiedAreas.stream().noneMatch(rect::intersects)) {
            Vector3 minVector = new Vector3(posX / 16.0, 0 / 16.0, posZ / 16.0);
            Cuboid6 bounds = new Cuboid6(minVector, minVector.copy());
            bounds.max.add(sizeX / 16.0, stoneHeight / 16.0, sizeZ / 16.0);
            int brightness = 100 + random.nextInt(130);
            result.add(new IndexedCuboid6(brightness, bounds));
            occupiedAreas.add(rect);
            stonesPlaced++;
        }
    }
    return result;
}
Also used : IndexedCuboid6(codechicken.lib.raytracer.IndexedCuboid6) Position(gregtech.api.util.Position) Size(gregtech.api.util.Size) ArrayList(java.util.ArrayList) Vector3(codechicken.lib.vec.Vector3) IndexedCuboid6(codechicken.lib.raytracer.IndexedCuboid6) Cuboid6(codechicken.lib.vec.Cuboid6) PositionedRect(gregtech.api.util.PositionedRect)

Aggregations

PositionedRect (gregtech.api.util.PositionedRect)6 Position (gregtech.api.util.Position)4 Size (gregtech.api.util.Size)2 IndexedCuboid6 (codechicken.lib.raytracer.IndexedCuboid6)1 Cuboid6 (codechicken.lib.vec.Cuboid6)1 Transformation (codechicken.lib.vec.Transformation)1 Vector3 (codechicken.lib.vec.Vector3)1 ArrayList (java.util.ArrayList)1