Fix runtime errors

This commit is contained in:
2026-03-04 19:19:08 +01:00
parent 09be2b434d
commit 2116e1ee8d
10 changed files with 79 additions and 79 deletions
@@ -38,6 +38,7 @@ import java.util.stream.Stream;
public class DynamicRegionSystem implements RegionSystem {
private static final int TILE_SIZE_ADJUSTED = Tile.tileSize - 1;
public static DynamicRegionSystem INSTANCE;
private static final Map<Long, Region> regionCache = new LinkedHashMap<>(16, 0.75f, true) {
@@ -100,10 +101,12 @@ public class DynamicRegionSystem implements RegionSystem {
}
public @NonNull Region get(@Nullable Tile tile) {
return get(tile, true, Collections.emptySet());
if (tile == null) return getGlobalRegion();
return get(tile.getCenterLocation().getBlockX(), tile.getCenterLocation().getBlockZ(), true, Collections.emptySet());
}
private Region get(Tile tile, boolean fastCache, Collection<Region> regions) {
private Region get(int x, int z, boolean fastCache, Collection<Region> regions) {
Tile tile = Tile.fromXZ(x, z).orElse(null);
if (tile == null) {
return getGlobalRegion();
}
@@ -111,8 +114,6 @@ public class DynamicRegionSystem implements RegionSystem {
Region region = regionCache.get(tile.getId());
if (fastCache || regions.contains(region)) return region;
}
int x = tile.getMinX();
int z = tile.getMinZ();
Region region = regions.stream()
.filter(rg -> rg.getArea().inRegion(x, z, false))
.findFirst()
@@ -121,11 +122,6 @@ public class DynamicRegionSystem implements RegionSystem {
return region;
}
private Region get(int x, int z, boolean fastCache, Collection<Region> regions) {
Tile tile = Tile.fromXZ(x, z).validOrNull();
return get(tile, fastCache, regions);
}
@Override
public @NonNull Region get(@NonNull Location location) {
return get(location.getBlockX(), location.getBlockZ(), true, regionMap.values());
@@ -142,27 +138,18 @@ public class DynamicRegionSystem implements RegionSystem {
}
private Stream<Region> getNeighbours(Region region, boolean noCorners, boolean fastCache, Collection<Region> regions) {
Tile min = Tile.fromPoint(region.getArea().getMinPoint(false)).add(-1, -1);
Tile max = Tile.fromPoint(region.getArea().getMaxPoint(false)).add(1, 1);
if (min == null || max == null) return Stream.empty(); // TODO: Maybe fix this?
Point minPoint = region.getArea().getMinPoint(false).subtract(TILE_SIZE_ADJUSTED, 0, TILE_SIZE_ADJUSTED);
Point maxPoint = region.getArea().getMaxPoint(false).add(Tile.tileSize, 0, Tile.tileSize);
Set<Region> neighbours = new HashSet<>();
for (int x = min.getTileX() + (noCorners ? 1 : 0); x <= max.getTileX() - (noCorners ? 1 : 0); x++) {
for (int x = minPoint.getX() + (noCorners ? TILE_SIZE_ADJUSTED : 0); x <= maxPoint.getX() - (noCorners ? Tile.tileSize : 0); x += Tile.tileSize) {
neighbours.add(get(x, minPoint.getZ(), fastCache, regions));
neighbours.add(get(x, maxPoint.getZ(), fastCache, regions));
}
for (int x = minPoint.getX() + (noCorners ? 18 : 0); x <= maxPoint.getX() - (noCorners ? 19 : 0); x += 19) {
int minZ = minPoint.getZ();
int maxZ = maxPoint.getZ();
neighbours.add(get(x, minZ, fastCache, regions));
neighbours.add(get(x, maxZ, fastCache, regions));
}
for (int z = minPoint.getZ() + 18; z <= maxPoint.getZ() - 19; z += 19) {
int minX = minPoint.getX();
int maxX = maxPoint.getX();
neighbours.add(get(minX, z, fastCache, regions));
neighbours.add(get(maxX, z, fastCache, regions));
for (int z = minPoint.getZ() + TILE_SIZE_ADJUSTED; z <= maxPoint.getZ() - Tile.tileSize; z += Tile.tileSize) {
neighbours.add(get(minPoint.getX(), z, fastCache, regions));
neighbours.add(get(maxPoint.getX(), z, fastCache, regions));
}
neighbours.remove(getGlobalRegion());