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.client.models.Point;
8 import com.irtimaled.bbor.common.BoundingBoxType;
9 import com.irtimaled.bbor.common.MathHelper;
10 import com.irtimaled.bbor.common.models.Coords;
12 import java.util.HashSet;
15 public class SpawningSphereProvider implements IBoundingBoxProvider<BoundingBoxSpawningSphere> {
16 private static BoundingBoxSpawningSphere spawningSphere;
17 private static Integer dimensionId;
19 public static void setSphere(double x, double y, double z) {
20 Coords coords = new Coords(x, y, z);
21 double xOffset = snapToNearestHalf(x -coords.getX());
22 double yOffset = y- coords.getY();
23 double zOffset = snapToNearestHalf(z-coords.getZ());
25 if(spawningSphere != null && spawningSphere.isCenter(coords, xOffset, yOffset, zOffset)) {
30 dimensionId = Player.getDimensionId();
31 spawningSphere = new BoundingBoxSpawningSphere(coords, xOffset, yOffset, zOffset);
34 private static double snapToNearestHalf(double value) {
35 int floor = MathHelper.floor(value * 4.0);
36 if(floor % 2 == 1) floor += 1;
40 public static boolean clear() {
41 if(spawningSphere != null) {
42 spawningSphere = null;
49 public static int recalculateSpawnableSpacesCount() {
50 if (spawningSphere != null) {
51 Point sphereCenter = new Point(spawningSphere.getCenter())
52 .offset(spawningSphere.getCenterOffsetX(),
53 spawningSphere.getCenterOffsetY(),
54 spawningSphere.getCenterOffsetZ());
55 int spawnableSpacesCount = getSpawnableSpacesCount(sphereCenter);
56 spawningSphere.setSpawnableCount(spawnableSpacesCount);
57 return spawnableSpacesCount;
62 private static int getSpawnableSpacesCount(Point center) {
63 int size = BoundingBoxSpawningSphere.SPAWN_RADIUS + 2;
64 return SpawningSphereHelper.findSpawnableSpaces(center, center.getCoords(), size, size, (x, y, z) -> true);
68 public boolean canProvide(int dimensionId) {
69 return spawningSphere != null && SpawningSphereProvider.dimensionId == dimensionId && BoundingBoxTypeHelper.shouldRender(BoundingBoxType.AFKSphere);
73 public Iterable<BoundingBoxSpawningSphere> get(int dimensionId) {
74 Set<BoundingBoxSpawningSphere> boundingBoxes = new HashSet<>();
75 boundingBoxes.add(spawningSphere);