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.BlockProcessor;
7 import com.irtimaled.bbor.client.interop.SpawningSphereHelper;
8 import com.irtimaled.bbor.client.models.BoundingBoxSpawningSphere;
9 import com.irtimaled.bbor.common.BoundingBoxType;
10 import com.irtimaled.bbor.common.MathHelper;
11 import com.irtimaled.bbor.common.models.Point;
12 import net.minecraft.client.Minecraft;
14 import java.util.HashSet;
17 public class SpawningSphereProvider implements IBoundingBoxProvider<BoundingBoxSpawningSphere> {
18 public static final Minecraft minecraft = Minecraft.getInstance();
19 private static Long lastGameTime = null;
21 private static Set<BoundingBoxSpawningSphere> lastBoundingBox = null;
22 private static BoundingBoxSpawningSphere spawningSphere;
23 private static Integer dimensionId;
25 public static void setSphere(Point point) {
26 if (spawningSphere != null && spawningSphere.getPoint().equals(point)) return;
29 dimensionId = Player.getDimensionId();
30 spawningSphere = new BoundingBoxSpawningSphere(point);
31 lastBoundingBox = null;
34 public static boolean clear() {
35 if (spawningSphere != null) {
36 lastBoundingBox = null;
37 spawningSphere = null;
44 public static void calculateSpawnableSpacesCount(BlockProcessor blockProcessor) {
45 if (spawningSphere != null) {
46 Point sphereCenter = spawningSphere.getPoint();
47 int size = BoundingBoxSpawningSphere.SPAWN_RADIUS + 2;
48 SpawningSphereHelper.findSpawnableSpaces(sphereCenter, sphereCenter.getCoords(), size, size, blockProcessor);
52 static boolean playerInsideSphere() {
53 return hasSpawningSphereInDimension(Player.getDimensionId()) && spawningSphere.isWithinSphere(Player.getPoint());
56 public static boolean hasSpawningSphereInDimension(int dimensionId) {
57 return spawningSphere != null && SpawningSphereProvider.dimensionId == dimensionId;
60 public static void setSpawnableSpacesCount(int count) {
61 if (spawningSphere != null) {
62 spawningSphere.setSpawnableCount(count);
67 public boolean canProvide(int dimensionId) {
68 return hasSpawningSphereInDimension(dimensionId) && BoundingBoxTypeHelper.shouldRender(BoundingBoxType.AFKSphere);
72 public Iterable<BoundingBoxSpawningSphere> get(int dimensionId) {
73 long gameTime = minecraft.world.getGameTime();
74 if (lastBoundingBox == null || (!((Long) gameTime).equals(lastGameTime) && gameTime % 2L == 0L)) {
75 lastGameTime = gameTime;
76 lastBoundingBox = getSpawningSphere();
78 return lastBoundingBox;
81 private Set<BoundingBoxSpawningSphere> getSpawningSphere() {
82 spawningSphere.getBlocks().clear();
83 if (ConfigManager.renderAFKSpawnableBlocks.get()) {
84 int width = MathHelper.floor(Math.pow(2, 1 + ConfigManager.spawnableBlocksRenderWidth.get()));
85 int height = MathHelper.floor(Math.pow(2, ConfigManager.spawnableBlocksRenderHeight.get()));
87 SpawningSphereHelper.findSpawnableSpaces(spawningSphere.getPoint(), Player.getCoords(), width, height, spawningSphere.getBlocks()::add);
89 Set<BoundingBoxSpawningSphere> boundingBoxes = new HashSet<>();
90 boundingBoxes.add(spawningSphere);