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.interop.SpawningSphereHelper;
6 import com.irtimaled.bbor.client.models.BoundingBoxSpawningSphere;
7 import com.irtimaled.bbor.common.BoundingBoxType;
8 import com.irtimaled.bbor.common.MathHelper;
9 import com.irtimaled.bbor.common.models.Point;
11 import java.util.HashSet;
14 public class SpawningSphereProvider implements IBoundingBoxProvider<BoundingBoxSpawningSphere> {
15 private static BoundingBoxSpawningSphere spawningSphere;
16 private static Integer dimensionId;
18 public static void setSphere(double x, double y, double z) {
19 Point point = new Point(snapToNearestHalf(x), y, snapToNearestHalf(z));
21 if (spawningSphere != null && spawningSphere.getPoint().equals(point)) {
26 dimensionId = Player.getDimensionId();
27 spawningSphere = new BoundingBoxSpawningSphere(point);
30 private static double snapToNearestHalf(double value) {
31 int floor = MathHelper.floor(value);
32 int fraction = MathHelper.floor((value - floor) * 4.0);
33 if (fraction % 2 == 1) fraction++;
34 return floor + (fraction / 4.0);
37 public static boolean clear() {
38 if(spawningSphere != null) {
39 spawningSphere = null;
46 public static int recalculateSpawnableSpacesCount() {
47 if (spawningSphere != null) {
48 Point sphereCenter = spawningSphere.getPoint();
49 int spawnableSpacesCount = getSpawnableSpacesCount(sphereCenter);
50 spawningSphere.setSpawnableCount(spawnableSpacesCount);
51 return spawnableSpacesCount;
56 private static int getSpawnableSpacesCount(Point center) {
57 int size = BoundingBoxSpawningSphere.SPAWN_RADIUS + 2;
58 return SpawningSphereHelper.findSpawnableSpaces(center, center.getCoords(), size, size, (x, y, z) -> true);
62 public boolean canProvide(int dimensionId) {
63 return spawningSphere != null && SpawningSphereProvider.dimensionId == dimensionId && BoundingBoxTypeHelper.shouldRender(BoundingBoxType.AFKSphere);
67 public Iterable<BoundingBoxSpawningSphere> get(int dimensionId) {
68 Set<BoundingBoxSpawningSphere> boundingBoxes = new HashSet<>();
69 boundingBoxes.add(spawningSphere);