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>, ICachingProvider {
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;
29 dimensionId = Player.getDimensionId();
30 spawningSphere = new BoundingBoxSpawningSphere(point);
31 lastBoundingBox = null;
34 public static boolean clearSphere() {
35 if (spawningSphere != null) {
36 lastBoundingBox = null;
37 spawningSphere = null;
44 public void clearCache() {
48 public static void calculateSpawnableSpacesCount(BlockProcessor blockProcessor) {
49 if (spawningSphere != null) {
50 Point sphereCenter = spawningSphere.getPoint();
51 int size = BoundingBoxSpawningSphere.SPAWN_RADIUS + 2;
52 SpawningSphereHelper.findSpawnableSpaces(sphereCenter, sphereCenter.getCoords(), size, size, blockProcessor);
56 static boolean playerInsideSphere() {
57 return hasSpawningSphereInDimension(Player.getDimensionId()) && spawningSphere.isWithinSphere(Player.getPoint());
60 public static boolean hasSpawningSphereInDimension(DimensionId dimensionId) {
61 return spawningSphere != null && SpawningSphereProvider.dimensionId == dimensionId;
64 public static void setSpawnableSpacesCount(int count) {
65 if (spawningSphere != null) {
66 spawningSphere.setSpawnableCount(count);
71 public boolean canProvide(DimensionId dimensionId) {
72 return hasSpawningSphereInDimension(dimensionId) && BoundingBoxTypeHelper.shouldRender(BoundingBoxType.AFKSphere);
76 public Iterable<BoundingBoxSpawningSphere> get(DimensionId dimensionId) {
77 long gameTime = minecraft.world.getGameTime();
78 if (lastBoundingBox == null || (!((Long) gameTime).equals(lastGameTime) && gameTime % 2L == 0L)) {
79 lastGameTime = gameTime;
80 lastBoundingBox = getSpawningSphere();
82 return lastBoundingBox;
85 private Set<BoundingBoxSpawningSphere> getSpawningSphere() {
86 spawningSphere.getBlocks().clear();
87 if (ConfigManager.renderAFKSpawnableBlocks.get()) {
88 int width = MathHelper.floor(Math.pow(2, 1 + ConfigManager.spawnableBlocksRenderWidth.get()));
89 int height = MathHelper.floor(Math.pow(2, ConfigManager.spawnableBlocksRenderHeight.get()));
91 SpawningSphereHelper.findSpawnableSpaces(spawningSphere.getPoint(), Player.getCoords(), width, height, spawningSphere.getBlocks()::add);
93 Set<BoundingBoxSpawningSphere> boundingBoxes = new HashSet<>();
94 boundingBoxes.add(spawningSphere);