]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/client/renderers/SpawningSphereRenderer.java
ff5749c03bbe1c78f83d5920f6d63c2852bbb658
[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.ConfigManager;
5 import com.irtimaled.bbor.client.interop.SpawningSphereHelper;
6 import com.irtimaled.bbor.client.models.BoundingBoxSpawningSphere;
7 import com.irtimaled.bbor.common.MathHelper;
8 import com.irtimaled.bbor.common.models.Point;
9 import net.minecraft.client.resources.I18n;
10
11 import java.awt.*;
12
13 public class SpawningSphereRenderer extends AbstractRenderer<BoundingBoxSpawningSphere> {
14     @Override
15     public void render(BoundingBoxSpawningSphere boundingBox) {
16         Point point = boundingBox.getPoint();
17         OffsetPoint sphereCenter = new OffsetPoint(point);
18
19         OffsetBox offsetBox = new OffsetBox(sphereCenter, sphereCenter).grow(0.5, 0, 0.5);
20         renderCuboid(offsetBox, Color.GREEN);
21
22         Integer spawnableSpacesCount = boundingBox.getSpawnableSpacesCount();
23         if (spawnableSpacesCount != null) {
24             renderText(sphereCenter, I18n.format("bbor.renderer.spawningSphere.spawnable"),
25                     spawnableSpacesCount == 0 ?
26                             I18n.format("bbor.renderer.spawningSphere.none") :
27                             String.format("%,d", spawnableSpacesCount));
28         }
29
30         renderSphere(sphereCenter, BoundingBoxSpawningSphere.SAFE_RADIUS, Color.GREEN, 5, 5);
31         renderSphere(sphereCenter, BoundingBoxSpawningSphere.SPAWN_RADIUS, Color.RED, 5, 5);
32
33         if(ConfigManager.renderAFKSpawnableBlocks.get()) {
34             renderSpawnableSpaces(point);
35         }
36     }
37
38     private void renderSpawnableSpaces(Point center) {
39         Integer renderDistance = ConfigManager.afkSpawnableBlocksRenderDistance.get();
40         int width = MathHelper.floor(Math.pow(2, 2 + renderDistance));
41         int height = MathHelper.floor(Math.pow(2, renderDistance));
42
43         SpawningSphereHelper.findSpawnableSpaces(center, Player.getCoords(), width, height,
44                 (x, y, z) -> {
45                     OffsetBox offsetBox = new OffsetBox(x, y, z, x + 1, y, z + 1);
46                     renderCuboid(offsetBox, Color.RED);
47                     return false;
48                 });
49     }
50 }