forked from SteamWar/SteamWar
Reduce usable tile area
Fix DynamicRegionVisualizer throwing exceptions
This commit is contained in:
+18
-10
@@ -89,7 +89,7 @@ public class DynamicRegionVisualizer implements SWPlayer.Component, Listener {
|
||||
Set<Tile> tileSet = entityServer.getEntitiesByType(CTile.class)
|
||||
.stream()
|
||||
.filter(cTile -> {
|
||||
if (Math.abs(cTile.tile.getTileX() - dx) > 20 || Math.abs(cTile.tile.getTileZ() - dz) > 20) {
|
||||
if (Math.abs(cTile.tile.getTileX() - dx) > 40 || Math.abs(cTile.tile.getTileZ() - dz) > 40) {
|
||||
cTile.die();
|
||||
return false;
|
||||
} else {
|
||||
@@ -99,8 +99,8 @@ public class DynamicRegionVisualizer implements SWPlayer.Component, Listener {
|
||||
.map(cTile -> cTile.tile)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
for (int x = dx - 10; x <= dx + 10; x++) {
|
||||
for (int z = dz - 10; z <= dz + 10; z++) {
|
||||
for (int x = dx - 20; x <= dx + 20; x++) {
|
||||
for (int z = dz - 20; z <= dz + 20; z++) {
|
||||
Tile tile = sourceTile.add(x, z).orElse(null);
|
||||
if (tile == null || tileSet.contains(tile)) continue;
|
||||
new CTile(entityServer, tile);
|
||||
@@ -214,12 +214,14 @@ public class DynamicRegionVisualizer implements SWPlayer.Component, Listener {
|
||||
private boolean valid = false;
|
||||
|
||||
private Location getMinLocation() {
|
||||
Tile tile = sourceTile.add(-DynamicRegionVisualizer.this.sourceTile.getTileX(), -DynamicRegionVisualizer.this.sourceTile.getTileZ()).orElseThrow();
|
||||
Tile tile = sourceTile.add(-DynamicRegionVisualizer.this.sourceTile.getTileX(), -DynamicRegionVisualizer.this.sourceTile.getTileZ()).orElse(null);
|
||||
if (tile == null) tile = Tile.ZERO;
|
||||
return sourceLocation.clone().add(tile.getTileX(), 0, tile.getTileZ());
|
||||
}
|
||||
|
||||
private Location getMaxLocation() {
|
||||
Tile tile = sourceTile.add(-DynamicRegionVisualizer.this.sourceTile.getTileX(), -DynamicRegionVisualizer.this.sourceTile.getTileZ()).orElseThrow();
|
||||
Tile tile = sourceTile.add(-DynamicRegionVisualizer.this.sourceTile.getTileX(), -DynamicRegionVisualizer.this.sourceTile.getTileZ()).orElse(null);
|
||||
if (tile == null) tile = Tile.ZERO;
|
||||
return sourceLocation.clone().add(tile.getTileX(), 0, tile.getTileZ()).add(dx, 0, dz);
|
||||
}
|
||||
|
||||
@@ -243,7 +245,8 @@ public class DynamicRegionVisualizer implements SWPlayer.Component, Listener {
|
||||
wireframe.setPos1And2(getMinLocation(), getMaxLocation());
|
||||
for (int x = 0; x <= dx; x++) {
|
||||
for (int z = 0; z <= dz; z++) {
|
||||
if (!DynamicRegionSystem.INSTANCE.get(sourceTile.add(x, z).orElseThrow()).getType().isGlobal()) {
|
||||
Tile tile = sourceTile.add(x, z).orElse(null);
|
||||
if (tile == null || !DynamicRegionSystem.INSTANCE.get(tile).getType().isGlobal()) {
|
||||
wireframe.setBlock(Material.RED_CONCRETE.createBlockData());
|
||||
valid = false;
|
||||
return;
|
||||
@@ -282,19 +285,23 @@ public class DynamicRegionVisualizer implements SWPlayer.Component, Listener {
|
||||
Set<Tile> tiles = new HashSet<>();
|
||||
for (int x = 0; x <= dx; x++) {
|
||||
for (int z = 0; z <= dz; z++) {
|
||||
tiles.add(Tile.fromTile(x + sourceTile.getTileX(), z + sourceTile.getTileZ()).orElseThrow());
|
||||
tiles.add(Tile.fromTile(x + sourceTile.getTileX(), z + sourceTile.getTileZ()).orElse(null));
|
||||
}
|
||||
}
|
||||
tiles.remove(null);
|
||||
Tile selected = tiles.stream().min(Comparator.comparing(current -> {
|
||||
int dx = current.getTileX() - tile.getTileX();
|
||||
int dz = current.getTileZ() - tile.getTileZ();
|
||||
return dx * dx + dz * dz;
|
||||
}))
|
||||
.orElseThrow();
|
||||
.orElse(null);
|
||||
if (selected == null) return;
|
||||
|
||||
int dx = tile.getTileX() - selected.getTileX();
|
||||
int dz = tile.getTileZ() - selected.getTileZ();
|
||||
sourceTile = sourceTile.add(dx, dz).orElseThrow();
|
||||
Tile newSourceTile = sourceTile.add(dx, dz).orElse(null);
|
||||
if (newSourceTile == null) return;
|
||||
sourceTile = newSourceTile;
|
||||
check();
|
||||
}
|
||||
|
||||
@@ -313,9 +320,10 @@ public class DynamicRegionVisualizer implements SWPlayer.Component, Listener {
|
||||
Set<Tile> tiles = new HashSet<>();
|
||||
for (int x = 0; x <= dx; x++) {
|
||||
for (int z = 0; z <= dz; z++) {
|
||||
tiles.add(Tile.fromTile(x + sourceTile.getTileX(), z + sourceTile.getTileZ()).orElseThrow());
|
||||
tiles.add(Tile.fromTile(x + sourceTile.getTileX(), z + sourceTile.getTileZ()).orElse(null));
|
||||
}
|
||||
}
|
||||
tiles.remove(null);
|
||||
SWPlayer.allWithSingleComponent(DynamicRegionVisualizer.class)
|
||||
.forEach(pair -> pair.getComponent().resetTiles(tiles));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user