]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blobdiff - src/main/java/com/irtimaled/bbor/common/StructureProcessor.java
1.18.2-rc1
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / common / StructureProcessor.java
index f1681cec64f5d14e6ed38933224919d68caef74b..de83f67cfa8fe1329573803f87b51652f99b5ed6 100644 (file)
@@ -4,6 +4,10 @@ import com.irtimaled.bbor.common.models.AbstractBoundingBox;
 import com.irtimaled.bbor.common.models.BoundingBoxCuboid;
 import com.irtimaled.bbor.common.models.Coords;
 import com.irtimaled.bbor.mixin.access.IStructureStart;
+import it.unimi.dsi.fastutil.objects.Object2ObjectMaps;
+import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
+import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
+import it.unimi.dsi.fastutil.objects.ObjectSets;
 import net.minecraft.structure.StructurePiece;
 import net.minecraft.structure.StructureStart;
 import net.minecraft.util.math.BlockBox;
@@ -12,11 +16,12 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
-class StructureProcessor {
-    private static final Set<BoundingBoxType> supportedStructures = new HashSet<>();
+public class StructureProcessor {
+    private static final Map<String, BoundingBoxType> supportedStructures = Object2ObjectMaps.synchronize(new Object2ObjectOpenHashMap<>());
+    public static final Set<String> supportedStructureIds = ObjectSets.synchronize(new ObjectOpenHashSet<>());
 
-    static void registerSupportedStructure(BoundingBoxType type) {
-        supportedStructures.add(type);
+    public static void registerSupportedStructure(BoundingBoxType type) {
+        supportedStructures.put(type.getName(), type);
     }
 
     StructureProcessor(BoundingBoxCache boundingBoxCache) {
@@ -25,7 +30,7 @@ class StructureProcessor {
 
     private final BoundingBoxCache boundingBoxCache;
 
-    private void addStructures(BoundingBoxType type, StructureStart<?> structureStart) {
+    private void addStructures(BoundingBoxType type, StructureStart structureStart) {
         if (structureStart == null) return;
 
         try {
@@ -52,9 +57,12 @@ class StructureProcessor {
         return BoundingBoxCuboid.from(min, max, type);
     }
 
-    void process(Map<String, StructureStart<?>> structures) {
-        if (structures.size() > 0) {
-            supportedStructures.forEach(type -> addStructures(type, structures.get(type.getName())));
+    void process(Map<String, StructureStart> structures) {
+        for (Map.Entry<String, StructureStart> entry : structures.entrySet()) {
+            final BoundingBoxType type = supportedStructures.get("structure:" + entry.getKey());
+            if (type != null) {
+                addStructures(type, entry.getValue());
+            }
         }
     }
 }