Search in sources :

Example 1 with ChunkCuboid

use of dev.frankheijden.insights.api.objects.chunk.ChunkCuboid in project Insights by InsightsPlugin.

the class Cuboid method toChunkParts.

/**
 * Converts this cuboid into a List of ChunkParts.
 */
public List<ChunkPart> toChunkParts() {
    ChunkVector minV = ChunkVector.from(this.min);
    int minX = this.min.x >> 4;
    int minZ = this.min.z >> 4;
    ChunkVector maxV = ChunkVector.from(this.max);
    int maxX = this.max.x >> 4;
    int maxZ = this.max.z >> 4;
    List<ChunkPart> parts = new ArrayList<>(maxX - minX + 1 + maxZ - minZ + 1);
    for (int x = minX; x <= maxX; x++) {
        int xmin = (x == minX) ? minV.getX() : 0;
        int ymin = minV.getY();
        int xmax = (x == maxX) ? maxV.getX() : 15;
        for (int z = minZ; z <= maxZ; z++) {
            int zmin = (z == minZ) ? minV.getZ() : 0;
            int ymax = maxV.getY();
            int zmax = (z == maxZ) ? maxV.getZ() : 15;
            ChunkLocation loc = new ChunkLocation(world, x, z);
            ChunkVector vmin = new ChunkVector(xmin, ymin, zmin);
            ChunkVector vmax = new ChunkVector(xmax, ymax, zmax);
            parts.add(new ChunkPart(loc, new ChunkCuboid(vmin, vmax)));
        }
    }
    return parts;
}
Also used : ChunkCuboid(dev.frankheijden.insights.api.objects.chunk.ChunkCuboid) ChunkVector(dev.frankheijden.insights.api.objects.chunk.ChunkVector) ArrayList(java.util.ArrayList) ChunkPart(dev.frankheijden.insights.api.objects.chunk.ChunkPart) ChunkLocation(dev.frankheijden.insights.api.objects.chunk.ChunkLocation)

Aggregations

ChunkCuboid (dev.frankheijden.insights.api.objects.chunk.ChunkCuboid)1 ChunkLocation (dev.frankheijden.insights.api.objects.chunk.ChunkLocation)1 ChunkPart (dev.frankheijden.insights.api.objects.chunk.ChunkPart)1 ChunkVector (dev.frankheijden.insights.api.objects.chunk.ChunkVector)1 ArrayList (java.util.ArrayList)1