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 com.irtimaled.bbor.mixin.access.IStructureStart;
7 import net.minecraft.structure.StructurePiece;
8 import net.minecraft.structure.StructureStart;
9 import net.minecraft.util.math.BlockBox;
11 import java.util.HashSet;
15 class StructureProcessor {
16 private static final Set<BoundingBoxType> supportedStructures = new HashSet<>();
18 static void registerSupportedStructure(BoundingBoxType type) {
19 supportedStructures.add(type);
22 StructureProcessor(BoundingBoxCache boundingBoxCache) {
23 this.boundingBoxCache = boundingBoxCache;
26 private final BoundingBoxCache boundingBoxCache;
28 private void addStructures(BoundingBoxType type, StructureStart<?> structureStart) {
29 if (structureStart == null) return;
32 structureStart.getBoundingBox();
33 } catch (Throwable ignored) {
36 BlockBox bb = ((IStructureStart) structureStart).getBoundingBox1();
37 if (bb == null) return;
39 AbstractBoundingBox boundingBox = buildStructure(bb, type);
40 if (boundingBoxCache.isCached(boundingBox)) return;
42 Set<AbstractBoundingBox> structureBoundingBoxes = new HashSet<>();
43 for (StructurePiece structureComponent : structureStart.getChildren()) {
44 structureBoundingBoxes.add(buildStructure(structureComponent.getBoundingBox(), type));
46 boundingBoxCache.addBoundingBoxes(boundingBox, structureBoundingBoxes);
49 private AbstractBoundingBox buildStructure(BlockBox bb, BoundingBoxType type) {
50 Coords min = new Coords(bb.getMinX(), bb.getMinY(), bb.getMinZ());
51 Coords max = new Coords(bb.getMaxX(), bb.getMaxY(), bb.getMaxZ());
52 return BoundingBoxCuboid.from(min, max, type);
55 void process(Map<String, StructureStart<?>> structures) {
56 if (structures.size() > 0) {
57 supportedStructures.forEach(type -> addStructures(type, structures.get(type.getName())));