forked from SteamWar/SteamWar
Improve several things
This commit is contained in:
+25
-9
@@ -28,6 +28,7 @@ import de.steamwar.bausystem.region.dynamic.global.GlobalRegion;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.*;
|
||||
@@ -98,8 +99,11 @@ public class DynamicRegionSystem implements RegionSystem {
|
||||
return GlobalRegion.INSTANCE;
|
||||
}
|
||||
|
||||
private Region get(int x, int z, boolean fastCache, Collection<Region> regions) {
|
||||
Tile tile = Tile.fromXZ(x, z).orElse(null);
|
||||
public @NonNull Region get(@Nullable Tile tile) {
|
||||
return get(tile, true, Collections.emptySet());
|
||||
}
|
||||
|
||||
private Region get(Tile tile, boolean fastCache, Collection<Region> regions) {
|
||||
if (tile == null) {
|
||||
return getGlobalRegion();
|
||||
}
|
||||
@@ -107,6 +111,8 @@ 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()
|
||||
@@ -115,6 +121,11 @@ 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());
|
||||
@@ -131,17 +142,22 @@ public class DynamicRegionSystem implements RegionSystem {
|
||||
}
|
||||
|
||||
private Stream<Region> getNeighbours(Region region, boolean noCorners, boolean fastCache, Collection<Region> regions) {
|
||||
Point minPoint = region.getArea().getMinPoint(false).subtract(18, 0, 18);
|
||||
Point maxPoint = region.getArea().getMaxPoint(false).add(19, 0, 19);
|
||||
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?
|
||||
Set<Region> neighbours = new HashSet<>();
|
||||
|
||||
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 x = min.getTileX() + (noCorners ? 1 : 0); x <= max.getTileX() - (noCorners ? 1 : 0); x++) {
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user