1 package com.irtimaled.bbor.client.providers;
3 import com.irtimaled.bbor.client.Player;
4 import com.irtimaled.bbor.client.models.BoundingBoxSphere;
5 import com.irtimaled.bbor.client.models.Point;
6 import com.irtimaled.bbor.common.BoundingBoxType;
8 import java.util.HashMap;
10 import java.util.concurrent.ConcurrentHashMap;
12 public class CustomSphereProvider implements IBoundingBoxProvider<BoundingBoxSphere> {
13 private static final Map<Integer, Map<Integer, BoundingBoxSphere>> dimensionCache = new HashMap<>();
15 private static Map<Integer, BoundingBoxSphere> getCache(int dimensionId) {
16 return dimensionCache.computeIfAbsent(dimensionId, i -> new ConcurrentHashMap<>());
19 public static void add(Point center, double radius) {
20 int dimensionId = Player.getDimensionId();
21 int cacheKey = center.hashCode();
22 BoundingBoxSphere sphere = new BoundingBoxSphere(center, radius, BoundingBoxType.Custom);
23 getCache(dimensionId).put(cacheKey, sphere);
26 public static boolean remove(Point center) {
27 int dimensionId = Player.getDimensionId();
28 int cacheKey = center.hashCode();
29 return getCache(dimensionId).remove(cacheKey) != null;
32 public static void clear() {
33 dimensionCache.values().forEach(Map::clear);
37 public Iterable<BoundingBoxSphere> get(int dimensionId) {
38 return getCache(dimensionId).values();