1 package com.irtimaled.bbor.common;
3 import com.irtimaled.bbor.common.models.AbstractBoundingBox;
4 import com.irtimaled.bbor.common.models.BoundingBoxCuboid;
5 import com.irtimaled.bbor.common.models.Coords;
6 import net.minecraft.structure.StructurePiece;
7 import net.minecraft.structure.StructureStart;
8 import net.minecraft.util.math.BlockBox;
10 import java.util.HashSet;
14 class StructureProcessor {
15 private static final Set<BoundingBoxType> supportedStructures = new HashSet<>();
17 static void registerSupportedStructure(BoundingBoxType type) {
18 supportedStructures.add(type);
21 StructureProcessor(BoundingBoxCache boundingBoxCache) {
22 this.boundingBoxCache = boundingBoxCache;
25 private final BoundingBoxCache boundingBoxCache;
27 private void addStructures(BoundingBoxType type, StructureStart<?> structureStart) {
28 if (structureStart == null) return;
30 if (structureStart.hasNoChildren()) return;
32 BlockBox bb = structureStart.setBoundingBoxFromChildren();
33 if (bb == null) return;
35 AbstractBoundingBox boundingBox = buildStructure(bb, type);
36 if (boundingBoxCache.isCached(boundingBox)) return;
38 Set<AbstractBoundingBox> structureBoundingBoxes = new HashSet<>();
39 for (StructurePiece structureComponent : structureStart.getChildren()) {
40 structureBoundingBoxes.add(buildStructure(structureComponent.getBoundingBox(), type));
42 boundingBoxCache.addBoundingBoxes(boundingBox, structureBoundingBoxes);
45 private AbstractBoundingBox buildStructure(BlockBox bb, BoundingBoxType type) {
46 Coords min = new Coords(bb.getMinX(), bb.getMinY(), bb.getMinZ());
47 Coords max = new Coords(bb.getMaxX(), bb.getMaxY(), bb.getMaxZ());
48 return BoundingBoxCuboid.from(min, max, type);
51 void process(Map<String, StructureStart<?>> structures) {
52 if (structures.size() > 0) {
53 supportedStructures.forEach(type -> addStructures(type, structures.get(type.getName())));