1 package com.irtimaled.bbor.client.providers;
3 import com.irtimaled.bbor.client.Player;
4 import com.irtimaled.bbor.client.models.BoundingBoxLine;
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 CustomLineProvider implements IBoundingBoxProvider<BoundingBoxLine> {
13 private static final Map<Integer, Map<Integer, BoundingBoxLine>> dimensionCache = new HashMap<>();
15 private static int getHashKey(Point minPoint, Point maxPoint) {
16 return (31 + minPoint.hashCode()) * 31 + maxPoint.hashCode();
19 private static Map<Integer, BoundingBoxLine> getCache(int dimensionId) {
20 return dimensionCache.computeIfAbsent(dimensionId, i -> new ConcurrentHashMap<>());
23 public static void add(Point minPoint, Point maxPoint, Double width) {
24 int dimensionId = Player.getDimensionId();
25 int cacheKey = getHashKey(minPoint, maxPoint);
26 BoundingBoxLine line = BoundingBoxLine.from(minPoint, maxPoint, width, BoundingBoxType.Custom);
27 getCache(dimensionId).put(cacheKey, line);
30 public static boolean remove(Point min, Point max) {
31 int dimensionId = Player.getDimensionId();
32 int cacheKey = getHashKey(min, max);
33 return getCache(dimensionId).remove(cacheKey) != null;
36 public static void clear() {
37 dimensionCache.values().forEach(Map::clear);
40 public Iterable<BoundingBoxLine> get(int dimensionId) {
41 return getCache(dimensionId).values();