TheBrokenRail
6d51dee9c7
All checks were successful
EnergonRelics/pipeline/head This commit looks good
61 lines
1.9 KiB
Java
61 lines
1.9 KiB
Java
package com.thebrokenrail.energonrelics.structure;
|
|
|
|
import net.minecraft.block.Blocks;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.world.World;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class StructurePlacer {
|
|
private static class StructurePos {
|
|
private final int x;
|
|
private final int y;
|
|
private final int z;
|
|
private final StructurePart<?> part;
|
|
|
|
private StructurePos(int x, int y, int z, StructurePart<?> part) {
|
|
this.x = x;
|
|
this.y = y;
|
|
this.z = z;
|
|
this.part = part;
|
|
}
|
|
}
|
|
|
|
private final List<StructurePos> pendingParts = new ArrayList<>();
|
|
private final List<StructurePos> parts = new ArrayList<>();
|
|
|
|
public StructurePlacer(StructurePart<?> firstPart) {
|
|
pendingParts.add(new StructurePos(0, 0, 0, firstPart));
|
|
run();
|
|
}
|
|
|
|
private void run() {
|
|
while (!pendingParts.isEmpty()) {
|
|
List<StructurePos> newPendingParts = new ArrayList<>();
|
|
for (StructurePos part : pendingParts) {
|
|
if (part.part != null) {
|
|
part.part.build((x, y, z, newPart) -> {
|
|
newPendingParts.add(new StructurePos(x + part.x, y + part.y, z + part.z, null));
|
|
//newPendingParts.add(new StructurePos(x + part.x, y + part.y, z + part.z, newPart));
|
|
});
|
|
}
|
|
parts.add(part);
|
|
}
|
|
pendingParts.clear();
|
|
pendingParts.addAll(newPendingParts);
|
|
}
|
|
}
|
|
|
|
public void place(World world, BlockPos pos) {
|
|
for (StructurePos part : parts) {
|
|
BlockPos newPos = pos.add(part.x, part.y, part.z);
|
|
if (part.part != null) {
|
|
part.part.place(world, newPos);
|
|
} else {
|
|
world.setBlockState(newPos, Blocks.DIORITE.getDefaultState());
|
|
}
|
|
}
|
|
}
|
|
}
|