]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/client/renderers/SpawningSphereRenderer.java
Switch to using Blaze managed GL
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / client / renderers / SpawningSphereRenderer.java
1 package com.irtimaled.bbor.client.renderers;
2
3 import com.irtimaled.bbor.client.Player;
4 import com.irtimaled.bbor.client.config.BoundingBoxTypeHelper;
5 import com.irtimaled.bbor.client.config.ColorHelper;
6 import com.irtimaled.bbor.client.config.ConfigManager;
7 import com.irtimaled.bbor.client.models.BoundingBoxSpawningSphere;
8 import com.irtimaled.bbor.client.models.Point;
9 import com.irtimaled.bbor.common.BoundingBoxType;
10 import net.minecraft.client.resources.I18n;
11
12 import java.awt.*;
13
14 public class SpawningSphereRenderer extends AbstractRenderer<BoundingBoxSpawningSphere> {
15     @Override
16     public void render(BoundingBoxSpawningSphere boundingBox) {
17         Point point = boundingBox.getPoint();
18         OffsetPoint sphereCenter = new OffsetPoint(point);
19
20         Color safeAreaColor = ColorHelper.getColor(ConfigManager.colorAFKSpheresSafeArea);
21         renderSphere(point, BoundingBoxSpawningSphere.SAFE_RADIUS, safeAreaColor);
22
23         renderOuterSphere(boundingBox, point);
24
25         OffsetBox offsetBox = new OffsetBox(sphereCenter, sphereCenter).grow(0.5, 0, 0.5);
26         renderCuboid(offsetBox, safeAreaColor);
27
28         Integer spawnableSpacesCount = boundingBox.getSpawnableSpacesCount();
29         if (spawnableSpacesCount != null) {
30             renderText(sphereCenter, I18n.format("bbor.renderer.spawningSphere.spawnable"),
31                     spawnableSpacesCount == 0 ?
32                             I18n.format("bbor.renderer.spawningSphere.none") :
33                             String.format("%,d", spawnableSpacesCount));
34         }
35         renderSphere(point, BoundingBoxSpawningSphere.SAFE_RADIUS, safeAreaColor);
36
37         if (ConfigManager.renderAFKSpawnableBlocks.get() && boundingBox.isWithinSphere(Player.getPoint())) {
38             renderSpawnableSpaces(boundingBox);
39         }
40     }
41
42     private void renderOuterSphere(BoundingBoxSpawningSphere boundingBox, Point point) {
43         Color color = BoundingBoxTypeHelper.getColor(boundingBox.getType());
44         renderSphere(point, BoundingBoxSpawningSphere.SPAWN_RADIUS, color);
45     }
46
47     private void renderSpawnableSpaces(BoundingBoxSpawningSphere boundingBox) {
48         Color color = BoundingBoxTypeHelper.getColor(BoundingBoxType.SpawnableBlocks);
49         boundingBox.getBlocks().forEach(c -> {
50             int x = c.getX();
51             int y = c.getY();
52             int z = c.getZ();
53             OffsetBox offsetBox = new OffsetBox(x, y, z, x + 1, y, z + 1);
54             renderCuboid(offsetBox, color);
55         });
56     }
57 }