]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blobdiff - src/main/java/com/irtimaled/bbor/client/providers/FlowerForestProvider.java
Several fixes
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / client / providers / FlowerForestProvider.java
index 1ca34ec938c8672ac4db7cfacadc5f7a64b8f4d4..b26745e5c8a56d7f81db9051f6b12d29a678d626 100644 (file)
@@ -10,7 +10,9 @@ import com.irtimaled.bbor.common.BoundingBoxType;
 import com.irtimaled.bbor.common.MathHelper;
 import com.irtimaled.bbor.common.models.Coords;
 import com.irtimaled.bbor.common.models.DimensionId;
+import net.minecraft.client.MinecraftClient;
 import net.minecraft.util.registry.BuiltinRegistries;
+import net.minecraft.world.Heightmap;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -57,7 +59,7 @@ public class FlowerForestProvider implements IBoundingBoxProvider<BoundingBoxFlo
         int minZ = blockZ - width;
         int maxZ = blockZ + width;
 
-        Map<Coords, BoundingBoxFlowerForest> boundingBoxes = new HashMap<>();
+        Map<Coords, BoundingBoxFlowerForest> boundingBoxes = new HashMap<>((maxX - minX) * (maxZ - minZ));
         for (int x = minX; x <= maxX; x++) {
             for (int z = minZ; z <= maxZ; z++) {
                 int biomeId = BiomeBorderHelper.getBiomeId(x, 255, z);
@@ -78,9 +80,11 @@ public class FlowerForestProvider implements IBoundingBoxProvider<BoundingBoxFlo
     }
 
     private static int getMaxYForPos(int x, int y, int z) {
-        while (y > 0) {
-            if (FlowerForestHelper.canGrowFlower(x, y, z)) return y;
-            y--;
+        int topY = MinecraftClient.getInstance().world.getTopY(Heightmap.Type.MOTION_BLOCKING, x, z);
+        if (topY == 0) topY = y; // heightmap appears to be broken
+        while (topY > 0) {
+            if (FlowerForestHelper.canGrowFlower(x, topY, z)) return topY;
+            topY--;
         }
         return 0;
     }