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.client.models.Point;
10 import com.irtimaled.bbor.common.BoundingBoxType;
11 import com.irtimaled.bbor.common.MathHelper;
12 import com.irtimaled.bbor.common.models.DimensionId;
13 import net.minecraft.client.Minecraft;
15 import java.util.HashSet;
18 public class SpawningSphereProvider implements IBoundingBoxProvider<BoundingBoxSpawningSphere> {
19 public static final Minecraft minecraft = Minecraft.getInstance();
20 private static Long lastGameTime = null;
22 private static Set<BoundingBoxSpawningSphere> lastBoundingBox = null;
23 private static BoundingBoxSpawningSphere spawningSphere;
24 private static DimensionId dimensionId;
26 public static void setSphere(Point point) {
27 if (spawningSphere != null && spawningSphere.getPoint().equals(point)) return;
30 dimensionId = Player.getDimensionId();
31 spawningSphere = new BoundingBoxSpawningSphere(point);
32 lastBoundingBox = null;
35 public static boolean clear() {
36 if (spawningSphere != null) {
37 lastBoundingBox = null;
38 spawningSphere = null;
45 public static void calculateSpawnableSpacesCount(BlockProcessor blockProcessor) {
46 if (spawningSphere != null) {
47 Point sphereCenter = spawningSphere.getPoint();
48 int size = BoundingBoxSpawningSphere.SPAWN_RADIUS + 2;
49 SpawningSphereHelper.findSpawnableSpaces(sphereCenter, sphereCenter.getCoords(), size, size, blockProcessor);
53 static boolean playerInsideSphere() {
54 return hasSpawningSphereInDimension(Player.getDimensionId()) && spawningSphere.isWithinSphere(Player.getPoint());
57 public static boolean hasSpawningSphereInDimension(DimensionId dimensionId) {
58 return spawningSphere != null && SpawningSphereProvider.dimensionId == dimensionId;
61 public static void setSpawnableSpacesCount(int count) {
62 if (spawningSphere != null) {
63 spawningSphere.setSpawnableCount(count);
68 public boolean canProvide(DimensionId dimensionId) {
69 return hasSpawningSphereInDimension(dimensionId) && BoundingBoxTypeHelper.shouldRender(BoundingBoxType.AFKSphere);
73 public Iterable<BoundingBoxSpawningSphere> get(DimensionId dimensionId) {
74 long gameTime = minecraft.world.getGameTime();
75 if (lastBoundingBox == null || (!((Long) gameTime).equals(lastGameTime) && gameTime % 2L == 0L)) {
76 lastGameTime = gameTime;
77 lastBoundingBox = getSpawningSphere();
79 return lastBoundingBox;
82 private Set<BoundingBoxSpawningSphere> getSpawningSphere() {
83 spawningSphere.getBlocks().clear();
84 if (ConfigManager.renderAFKSpawnableBlocks.get()) {
85 int width = MathHelper.floor(Math.pow(2, 1 + ConfigManager.spawnableBlocksRenderWidth.get()));
86 int height = MathHelper.floor(Math.pow(2, ConfigManager.spawnableBlocksRenderHeight.get()));
88 SpawningSphereHelper.findSpawnableSpaces(spawningSphere.getPoint(), Player.getCoords(), width, height, spawningSphere.getBlocks()::add);
90 Set<BoundingBoxSpawningSphere> boundingBoxes = new HashSet<>();
91 boundingBoxes.add(spawningSphere);