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, Map<String, StructureStart> structureMap) {
28 StructureStart structureStart = structureMap.get(type.getName());
29 if (structureStart == null) return;
31 BlockBox bb = structureStart.getBoundingBox();
32 if (bb == null) return;
34 AbstractBoundingBox boundingBox = buildStructure(bb, type);
35 if (boundingBoxCache.isCached(boundingBox)) return;
37 Set<AbstractBoundingBox> structureBoundingBoxes = new HashSet<>();
38 for (StructurePiece structureComponent : structureStart.getChildren()) {
39 structureBoundingBoxes.add(buildStructure(structureComponent.getBoundingBox(), type));
41 boundingBoxCache.addBoundingBoxes(boundingBox, structureBoundingBoxes);
44 private AbstractBoundingBox buildStructure(BlockBox bb, BoundingBoxType type) {
45 Coords min = new Coords(bb.minX, bb.minY, bb.minZ);
46 Coords max = new Coords(bb.maxX, bb.maxY, bb.maxZ);
47 return BoundingBoxCuboid.from(min, max, type);
50 void process(Map<String, StructureStart> structures) {
51 if (structures.size() > 0) {
52 supportedStructures.forEach(type -> addStructures(type, structures));