]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blobdiff - src/main/java/com/irtimaled/bbor/client/ClientRenderer.java
Tidy up
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / client / ClientRenderer.java
index 3ddea1a4333f41ec01a27a900757b0f6f64f462f..769dbcd5e679dd595307475089f1509017b87d44 100644 (file)
@@ -1,9 +1,8 @@
 package com.irtimaled.bbor.client;
 
 import com.irtimaled.bbor.client.interop.ClientInterop;
-import com.irtimaled.bbor.client.providers.IBoundingBoxProvider;
+import com.irtimaled.bbor.client.providers.*;
 import com.irtimaled.bbor.client.renderers.*;
-import com.irtimaled.bbor.common.BoundingBoxCache;
 import com.irtimaled.bbor.common.MathHelper;
 import com.irtimaled.bbor.common.models.*;
 import com.irtimaled.bbor.config.ConfigManager;
@@ -19,7 +18,7 @@ public class ClientRenderer {
     private static final Map<Class<? extends AbstractBoundingBox>, AbstractRenderer> boundingBoxRendererMap = new HashMap<>();
 
     private static boolean active;
-    private Set<IBoundingBoxProvider> providers = new HashSet<>();
+    private static final Set<IBoundingBoxProvider> providers = new HashSet<>();
 
     public static boolean getActive() {
         return active;
@@ -29,17 +28,14 @@ public class ClientRenderer {
         active = !active;
         if (!active) return;
 
-        PlayerCoords.setActiveY();
+        Player.setActiveY();
     }
 
     static void deactivate() {
         active = false;
     }
 
-    private final GetCache getCache;
-
-    ClientRenderer(GetCache getCache) {
-        this.getCache = getCache;
+    static {
         registerRenderer(BoundingBoxVillage.class, new VillageRenderer());
         registerRenderer(BoundingBoxSlimeChunk.class, new SlimeChunkRenderer());
         registerRenderer(BoundingBoxWorldSpawn.class, new WorldSpawnRenderer());
@@ -47,32 +43,38 @@ public class ClientRenderer {
         registerRenderer(BoundingBoxMobSpawner.class, new MobSpawnerRenderer());
         registerRenderer(BoundingBoxSpawningSphere.class, new SpawningSphereRenderer());
         registerRenderer(BoundingBoxBeacon.class, new CuboidRenderer());
+        registerRenderer(BoundingBoxBiomeBorder.class, new BiomeBorderRenderer());
+
+        registerProvider(new SlimeChunkProvider());
+        registerProvider(new WorldSpawnProvider());
+        registerProvider(new SpawningSphereProvider());
+        registerProvider(new BeaconProvider());
+        registerProvider(new CustomBoxProvider());
+        registerProvider(new BiomeBorderProvider());
     }
 
-    public <T extends AbstractBoundingBox> ClientRenderer registerProvider(IBoundingBoxProvider<T> provider) {
-        this.providers.add(provider);
-        return this;
+    public static <T extends AbstractBoundingBox> void registerProvider(IBoundingBoxProvider<T> provider) {
+        providers.add(provider);
     }
 
-    public <T extends AbstractBoundingBox> ClientRenderer registerRenderer(Class<? extends T> type, AbstractRenderer<T> renderer) {
+    public static <T extends AbstractBoundingBox> void registerRenderer(Class<? extends T> type, AbstractRenderer<T> renderer) {
         boundingBoxRendererMap.put(type, renderer);
-        return this;
     }
 
-    private boolean isWithinRenderDistance(AbstractBoundingBox boundingBox) {
+    private static boolean isWithinRenderDistance(AbstractBoundingBox boundingBox) {
         int renderDistanceBlocks = ClientInterop.getRenderDistanceChunks() * CHUNK_SIZE;
-        int minX = MathHelper.floor(PlayerCoords.getX() - renderDistanceBlocks);
-        int maxX = MathHelper.floor(PlayerCoords.getX() + renderDistanceBlocks);
-        int minZ = MathHelper.floor(PlayerCoords.getZ() - renderDistanceBlocks);
-        int maxZ = MathHelper.floor(PlayerCoords.getZ() + renderDistanceBlocks);
+        int minX = MathHelper.floor(Player.getX() - renderDistanceBlocks);
+        int maxX = MathHelper.floor(Player.getX() + renderDistanceBlocks);
+        int minZ = MathHelper.floor(Player.getZ() - renderDistanceBlocks);
+        int maxZ = MathHelper.floor(Player.getZ() + renderDistanceBlocks);
 
         return boundingBox.intersectsBounds(minX, minZ, maxX, maxZ);
     }
 
-    public void render(int dimensionId) {
+    public static void render(int dimensionId) {
         if(!active) return;
 
-        Map<AbstractBoundingBox, Set<AbstractBoundingBox>> boundingBoxes = getBoundingBoxes(dimensionId);
+        Set<AbstractBoundingBox> boundingBoxes = getBoundingBoxes(dimensionId);
 
         GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
         GL11.glLineWidth(2.0f);
@@ -83,21 +85,12 @@ public class ClientRenderer {
             GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
         }
 
-        Boolean outerBoxesOnly = ConfigManager.outerBoxesOnly.get();
-        for (Map.Entry<AbstractBoundingBox, Set<AbstractBoundingBox>> entry : boundingBoxes.entrySet()) {
-            AbstractBoundingBox key = entry.getKey();
-            if (!key.shouldRender()) continue;
+        for (AbstractBoundingBox key : boundingBoxes) {
+            if (!key.shouldRender() || !isWithinRenderDistance(key)) continue;
 
             AbstractRenderer renderer = boundingBoxRendererMap.get(key.getClass());
             if (renderer == null) continue;
 
-            if (!outerBoxesOnly) {
-                Set<AbstractBoundingBox> children = entry.getValue();
-                if (children != null && children.size() > 0) {
-                    children.forEach(renderer::render);
-                    continue;
-                }
-            }
             renderer.render(key);
         }
 
@@ -106,21 +99,11 @@ public class ClientRenderer {
         GL11.glEnable(GL11.GL_TEXTURE_2D);
     }
 
-    private Map<AbstractBoundingBox, Set<AbstractBoundingBox>> getBoundingBoxes(int dimensionId) {
-        Map<AbstractBoundingBox, Set<AbstractBoundingBox>> boundingBoxes = new HashMap<>();
+    private static Set<AbstractBoundingBox> getBoundingBoxes(int dimensionId) {
+        Set<AbstractBoundingBox> boundingBoxes = new HashSet<>();
         for(IBoundingBoxProvider<?> provider: providers) {
             for (AbstractBoundingBox boundingBox : provider.get(dimensionId)) {
-                boundingBoxes.put(boundingBox, null);
-            }
-        }
-
-        BoundingBoxCache cache = getCache.apply(dimensionId);
-        if (cache != null) {
-            for (Map.Entry<AbstractBoundingBox, Set<AbstractBoundingBox>> entry : cache.getBoundingBoxes().entrySet()) {
-                AbstractBoundingBox key = entry.getKey();
-                if (key.shouldRender() && isWithinRenderDistance(key)) {
-                    boundingBoxes.put(key, entry.getValue());
-                }
+                boundingBoxes.add(boundingBox);
             }
         }
         return boundingBoxes;