2020-07-19 19:12:39 +00:00
|
|
|
package com.thebrokenrail.energonrelics.structure;
|
|
|
|
|
|
|
|
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) {
|
2020-07-20 21:03:17 +00:00
|
|
|
part.part.setPos(new BlockPos(part.x, part.y, part.z));
|
|
|
|
part.part.build((x, y, z, newPart) -> newPendingParts.add(new StructurePos(x + part.x, y + part.y, z + part.z, newPart)));
|
2020-07-19 19:12:39 +00:00
|
|
|
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);
|
2020-07-20 21:03:17 +00:00
|
|
|
part.part.place(world, newPos);
|
2020-07-19 19:12:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|