]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/client/ClientRenderer.java
ba230499fe9c7f4f9eecf7ac16d5f18c63ed91cf
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / client / ClientRenderer.java
1 package com.irtimaled.bbor.client;
2
3 import com.irtimaled.bbor.client.renderers.*;
4 import com.irtimaled.bbor.common.models.*;
5 import com.irtimaled.bbor.config.ConfigManager;
6 import net.minecraft.world.DimensionType;
7 import org.lwjgl.opengl.GL11;
8
9 import java.util.HashMap;
10 import java.util.Map;
11 import java.util.Set;
12
13 public class ClientRenderer {
14     private final ClientBoundingBoxProvider clientBoundingBoxProvider;
15     private static final Map<Class<? extends BoundingBox>, Renderer> boundingBoxRendererMap = new HashMap<>();
16
17     ClientRenderer(ClientDimensionCache dimensionCache) {
18         this.clientBoundingBoxProvider = new ClientBoundingBoxProvider(dimensionCache);
19         boundingBoxRendererMap.put(BoundingBoxVillage.class, new VillageRenderer());
20         boundingBoxRendererMap.put(BoundingBoxSlimeChunk.class, new SlimeChunkRenderer());
21         boundingBoxRendererMap.put(BoundingBoxWorldSpawn.class, new WorldSpawnRenderer());
22         boundingBoxRendererMap.put(BoundingBoxStructure.class, new StructureRenderer());
23     }
24
25     public void render(DimensionType dimensionType, Boolean outerBoxesOnly) {
26         Set<BoundingBox> boundingBoxes = clientBoundingBoxProvider.getBoundingBoxes(dimensionType, outerBoxesOnly);
27         if (boundingBoxes == null || boundingBoxes.size() == 0)
28             return;
29
30         GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
31         GL11.glLineWidth(2.0f);
32         GL11.glDisable(GL11.GL_TEXTURE_2D);
33         GL11.glDisable(GL11.GL_CULL_FACE);
34
35         if (ConfigManager.alwaysVisible.getBoolean()) {
36             GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
37         }
38         for (BoundingBox bb : boundingBoxes) {
39             Renderer renderer = boundingBoxRendererMap.get(bb.getClass());
40             if (renderer != null) {
41                 renderer.render(bb);
42             }
43         }
44
45         GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
46         GL11.glEnable(GL11.GL_CULL_FACE);
47         GL11.glEnable(GL11.GL_TEXTURE_2D);
48     }
49 }