1 package com.irtimaled.bbor.client.providers;
3 import com.irtimaled.bbor.client.Player;
4 import com.irtimaled.bbor.client.config.BoundingBoxTypeHelper;
5 import com.irtimaled.bbor.client.config.ConfigManager;
6 import com.irtimaled.bbor.client.interop.BiomeBorderHelper;
7 import com.irtimaled.bbor.client.interop.FlowerForestHelper;
8 import com.irtimaled.bbor.client.models.BoundingBoxFlowerForest;
9 import com.irtimaled.bbor.common.BoundingBoxType;
10 import com.irtimaled.bbor.common.MathHelper;
11 import com.irtimaled.bbor.common.models.Coords;
12 import com.irtimaled.bbor.common.models.DimensionId;
13 import net.minecraft.util.registry.BuiltinRegistries;
15 import java.util.HashMap;
18 public class FlowerForestProvider implements IBoundingBoxProvider<BoundingBoxFlowerForest>, ICachingProvider {
19 public static final int FLOWER_FOREST_BIOME_ID = BuiltinRegistries.BIOME.getRawId(FlowerForestHelper.BIOME);
20 private static Coords lastPlayerCoords = null;
21 private static Integer lastRenderDistance = null;
22 private static Map<Coords, BoundingBoxFlowerForest> lastBoundingBoxes = new HashMap<>();
25 public boolean canProvide(DimensionId dimensionId) {
26 return BoundingBoxTypeHelper.shouldRender(BoundingBoxType.FlowerForest);
30 public Iterable<BoundingBoxFlowerForest> get(DimensionId dimensionId) {
31 Coords playerCoords = Player.getCoords();
32 Integer renderDistance = ConfigManager.flowerForestsRenderDistance.get();
33 if (!playerCoords.equals(lastPlayerCoords) || !renderDistance.equals(lastRenderDistance)) {
34 lastPlayerCoords = playerCoords;
35 lastRenderDistance = renderDistance;
36 lastBoundingBoxes = getBoundingBoxes();
38 return lastBoundingBoxes.values();
41 public void clearCache() {
42 lastBoundingBoxes = new HashMap<>();
43 lastPlayerCoords = null;
46 private Map<Coords, BoundingBoxFlowerForest> getBoundingBoxes() {
47 int renderDistance = lastRenderDistance;
48 Coords playerCoords = lastPlayerCoords;
50 int width = MathHelper.floor(Math.pow(2, 2 + renderDistance));
52 int blockX = playerCoords.getX();
53 int minX = blockX - width;
54 int maxX = blockX + width;
56 int blockZ = playerCoords.getZ();
57 int minZ = blockZ - width;
58 int maxZ = blockZ + width;
60 Map<Coords, BoundingBoxFlowerForest> boundingBoxes = new HashMap<>();
61 for (int x = minX; x <= maxX; x++) {
62 for (int z = minZ; z <= maxZ; z++) {
63 int biomeId = BiomeBorderHelper.getBiomeId(x, 255, z);
64 if (biomeId == FLOWER_FOREST_BIOME_ID) {
65 int y = getMaxYForPos(x, playerCoords.getY() + 1, z);
69 Coords coords = new Coords(x, y + 1, z);
70 BoundingBoxFlowerForest boundingBox = lastBoundingBoxes.containsKey(coords)
71 ? lastBoundingBoxes.get(coords)
72 : new BoundingBoxFlowerForest(coords, FlowerForestHelper.getFlowerColorAtPos(coords));
73 boundingBoxes.put(coords, boundingBox);
80 private static int getMaxYForPos(int x, int y, int z) {
82 if (FlowerForestHelper.canGrowFlower(x, y, z)) return y;