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;
7 import com.irtimaled.bbor.common.models.DimensionId;
9 import java.util.HashMap;
11 import java.util.concurrent.ConcurrentHashMap;
13 public class CustomSphereProvider implements IBoundingBoxProvider<BoundingBoxSphere>, ICachingProvider {
14 private static final Map<DimensionId, Map<Integer, BoundingBoxSphere>> dimensionCache = new HashMap<>();
16 private static Map<Integer, BoundingBoxSphere> getCache(DimensionId dimensionId) {
17 return dimensionCache.computeIfAbsent(dimensionId, i -> new ConcurrentHashMap<>());
20 public static void add(Point center, double radius) {
21 DimensionId dimensionId = Player.getDimensionId();
22 int cacheKey = center.hashCode();
23 BoundingBoxSphere sphere = new BoundingBoxSphere(center, radius, BoundingBoxType.Custom);
24 getCache(dimensionId).put(cacheKey, sphere);
27 public static boolean remove(Point center) {
28 DimensionId dimensionId = Player.getDimensionId();
29 int cacheKey = center.hashCode();
30 return getCache(dimensionId).remove(cacheKey) != null;
33 public static void clear() {
34 dimensionCache.values().forEach(Map::clear);
37 public void clearCache() {
42 public Iterable<BoundingBoxSphere> get(DimensionId dimensionId) {
43 return getCache(dimensionId).values();