1 package com.irtimaled.bbor.client.providers;
3 import com.irtimaled.bbor.client.PlayerCoords;
4 import com.irtimaled.bbor.client.interop.SpawningSphereHelper;
5 import com.irtimaled.bbor.client.models.Point;
6 import com.irtimaled.bbor.common.MathHelper;
7 import com.irtimaled.bbor.common.models.BoundingBoxSpawningSphere;
8 import com.irtimaled.bbor.common.models.Coords;
10 public class SpawningSphereProvider implements IBoundingBoxProvider<BoundingBoxSpawningSphere> {
11 private static BoundingBoxSpawningSphere spawningSphere;
12 private static Integer dimensionId;
14 public static void setSphere() {
15 Coords coords = PlayerCoords.get();
16 double xOffset = snapToNearestHalf(PlayerCoords.getX() -coords.getX());
17 double yOffset = PlayerCoords.getY()- coords.getY();
18 double zOffset = snapToNearestHalf(PlayerCoords.getZ()-coords.getZ());
20 if(spawningSphere != null && spawningSphere.isCenter(coords, xOffset, yOffset, zOffset)) {
25 dimensionId = PlayerCoords.getDimensionId();
26 spawningSphere = new BoundingBoxSpawningSphere(coords, xOffset, yOffset, zOffset);
29 private static double snapToNearestHalf(double value) {
30 int floor = MathHelper.floor(value * 4.0);
31 if(floor % 2 == 1) floor += 1;
35 public static boolean clear() {
36 if(spawningSphere != null) {
37 spawningSphere = null;
44 public static int recalculateSpawnableSpacesCount() {
45 if (spawningSphere != null) {
46 Point sphereCenter = new Point(spawningSphere.getCenter())
47 .offset(spawningSphere.getCenterOffsetX(),
48 spawningSphere.getCenterOffsetY(),
49 spawningSphere.getCenterOffsetZ());
50 int spawnableSpacesCount = getSpawnableSpacesCount(sphereCenter);
51 spawningSphere.setSpawnableCount(spawnableSpacesCount);
52 return spawnableSpacesCount;
57 private static int getSpawnableSpacesCount(Point center) {
58 int size = BoundingBoxSpawningSphere.SPAWN_RADIUS + 2;
59 return SpawningSphereHelper.findSpawnableSpaces(center, center.getCoords(), size, size, (x, y, z) -> true);
62 private static Iterable<BoundingBoxSpawningSphere> iterable = Iterators.singleton(() -> spawningSphere);
64 public Iterable<BoundingBoxSpawningSphere> get(int dimensionId) {
65 if(spawningSphere == null || SpawningSphereProvider.dimensionId != dimensionId) {
66 return Iterators.empty();