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.Registry;
14 import net.minecraft.world.biome.Biomes;
16 import java.util.HashMap;
19 public class FlowerForestProvider implements IBoundingBoxProvider<BoundingBoxFlowerForest>, ICachingProvider {
20 public static final int FLOWER_FOREST_BIOME_ID = Registry.BIOME.getRawId(Biomes.FLOWER_FOREST);
21 private static Coords lastPlayerCoords = null;
22 private static Integer lastRenderDistance = null;
23 private static Map<Coords, BoundingBoxFlowerForest> lastBoundingBoxes = new HashMap<>();
26 public boolean canProvide(DimensionId dimensionId) {
27 return BoundingBoxTypeHelper.shouldRender(BoundingBoxType.FlowerForest);
31 public Iterable<BoundingBoxFlowerForest> get(DimensionId dimensionId) {
32 Coords playerCoords = Player.getCoords();
33 Integer renderDistance = ConfigManager.flowerForestsRenderDistance.get();
34 if (!playerCoords.equals(lastPlayerCoords) || !renderDistance.equals(lastRenderDistance)) {
35 lastPlayerCoords = playerCoords;
36 lastRenderDistance = renderDistance;
37 lastBoundingBoxes = getBoundingBoxes();
39 return lastBoundingBoxes.values();
42 public void clearCache() {
43 lastBoundingBoxes = new HashMap<>();
44 lastPlayerCoords = null;
47 private Map<Coords, BoundingBoxFlowerForest> getBoundingBoxes() {
48 int renderDistance = lastRenderDistance;
49 Coords playerCoords = lastPlayerCoords;
51 int width = MathHelper.floor(Math.pow(2, 2 + renderDistance));
53 int blockX = playerCoords.getX();
54 int minX = blockX - width;
55 int maxX = blockX + width;
57 int blockZ = playerCoords.getZ();
58 int minZ = blockZ - width;
59 int maxZ = blockZ + width;
61 Map<Coords, BoundingBoxFlowerForest> boundingBoxes = new HashMap<>();
62 for (int x = minX; x <= maxX; x++) {
63 for (int z = minZ; z <= maxZ; z++) {
64 int biomeId = BiomeBorderHelper.getBiomeId(x, 255, z);
65 if (biomeId == FLOWER_FOREST_BIOME_ID) {
66 int y = getMaxYForPos(x, playerCoords.getY() + 1, z);
70 Coords coords = new Coords(x, y + 1, z);
71 BoundingBoxFlowerForest boundingBox = lastBoundingBoxes.containsKey(coords)
72 ? lastBoundingBoxes.get(coords)
73 : new BoundingBoxFlowerForest(coords, FlowerForestHelper.getFlowerColorAtPos(coords));
74 boundingBoxes.put(coords, boundingBox);
81 private static int getMaxYForPos(int x, int y, int z) {
83 if (FlowerForestHelper.canGrowFlower(x, y, z)) return y;