forked from SteamWar/SteamWar
Reduce usable tile area
Fix DynamicRegionVisualizer throwing exceptions
This commit is contained in:
+10
-1
@@ -88,6 +88,14 @@ public class DynamicRegionSystem implements RegionSystem {
|
|||||||
.collect(Collectors.toUnmodifiableMap(entry -> entry.getValue().identifier(), Map.Entry::getKey));
|
.collect(Collectors.toUnmodifiableMap(entry -> entry.getValue().identifier(), Map.Entry::getKey));
|
||||||
|
|
||||||
DynamicRegionRepository.loadRegions();
|
DynamicRegionRepository.loadRegions();
|
||||||
|
// [STDOUT] PATH 239
|
||||||
|
// [STDOUT] DRY 4
|
||||||
|
// [STDOUT] DRY_SPECIAL 18
|
||||||
|
// [STDOUT] WET 2
|
||||||
|
// [STDOUT] WET_SPECIAL 9
|
||||||
|
regionTypeMap.forEach((type, regions) -> {
|
||||||
|
System.out.println(type + " " + regions.size());
|
||||||
|
});
|
||||||
new DynamicRegionCommand();
|
new DynamicRegionCommand();
|
||||||
new WireframeCommand();
|
new WireframeCommand();
|
||||||
}
|
}
|
||||||
@@ -109,9 +117,10 @@ public class DynamicRegionSystem implements RegionSystem {
|
|||||||
Set<Tile> tiles = new HashSet<>();
|
Set<Tile> tiles = new HashSet<>();
|
||||||
for (int x = minPoint.getX(); x < maxPoint.getX(); x += Tile.tileSize) {
|
for (int x = minPoint.getX(); x < maxPoint.getX(); x += Tile.tileSize) {
|
||||||
for (int z = minPoint.getZ(); z < maxPoint.getZ(); z += Tile.tileSize) {
|
for (int z = minPoint.getZ(); z < maxPoint.getZ(); z += Tile.tileSize) {
|
||||||
tiles.add(Tile.fromXZ(x, z).orElseThrow());
|
tiles.add(Tile.fromXZ(x, z).orElse(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
tiles.remove(null);
|
||||||
return Collections.unmodifiableSet(tiles);
|
return Collections.unmodifiableSet(tiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+18
-10
@@ -89,7 +89,7 @@ public class DynamicRegionVisualizer implements SWPlayer.Component, Listener {
|
|||||||
Set<Tile> tileSet = entityServer.getEntitiesByType(CTile.class)
|
Set<Tile> tileSet = entityServer.getEntitiesByType(CTile.class)
|
||||||
.stream()
|
.stream()
|
||||||
.filter(cTile -> {
|
.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();
|
cTile.die();
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@@ -99,8 +99,8 @@ public class DynamicRegionVisualizer implements SWPlayer.Component, Listener {
|
|||||||
.map(cTile -> cTile.tile)
|
.map(cTile -> cTile.tile)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
for (int x = dx - 10; x <= dx + 10; x++) {
|
for (int x = dx - 20; x <= dx + 20; x++) {
|
||||||
for (int z = dz - 10; z <= dz + 10; z++) {
|
for (int z = dz - 20; z <= dz + 20; z++) {
|
||||||
Tile tile = sourceTile.add(x, z).orElse(null);
|
Tile tile = sourceTile.add(x, z).orElse(null);
|
||||||
if (tile == null || tileSet.contains(tile)) continue;
|
if (tile == null || tileSet.contains(tile)) continue;
|
||||||
new CTile(entityServer, tile);
|
new CTile(entityServer, tile);
|
||||||
@@ -214,12 +214,14 @@ public class DynamicRegionVisualizer implements SWPlayer.Component, Listener {
|
|||||||
private boolean valid = false;
|
private boolean valid = false;
|
||||||
|
|
||||||
private Location getMinLocation() {
|
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());
|
return sourceLocation.clone().add(tile.getTileX(), 0, tile.getTileZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Location getMaxLocation() {
|
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);
|
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());
|
wireframe.setPos1And2(getMinLocation(), getMaxLocation());
|
||||||
for (int x = 0; x <= dx; x++) {
|
for (int x = 0; x <= dx; x++) {
|
||||||
for (int z = 0; z <= dz; z++) {
|
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());
|
wireframe.setBlock(Material.RED_CONCRETE.createBlockData());
|
||||||
valid = false;
|
valid = false;
|
||||||
return;
|
return;
|
||||||
@@ -282,19 +285,23 @@ public class DynamicRegionVisualizer implements SWPlayer.Component, Listener {
|
|||||||
Set<Tile> tiles = new HashSet<>();
|
Set<Tile> tiles = new HashSet<>();
|
||||||
for (int x = 0; x <= dx; x++) {
|
for (int x = 0; x <= dx; x++) {
|
||||||
for (int z = 0; z <= dz; z++) {
|
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 -> {
|
Tile selected = tiles.stream().min(Comparator.comparing(current -> {
|
||||||
int dx = current.getTileX() - tile.getTileX();
|
int dx = current.getTileX() - tile.getTileX();
|
||||||
int dz = current.getTileZ() - tile.getTileZ();
|
int dz = current.getTileZ() - tile.getTileZ();
|
||||||
return dx * dx + dz * dz;
|
return dx * dx + dz * dz;
|
||||||
}))
|
}))
|
||||||
.orElseThrow();
|
.orElse(null);
|
||||||
|
if (selected == null) return;
|
||||||
|
|
||||||
int dx = tile.getTileX() - selected.getTileX();
|
int dx = tile.getTileX() - selected.getTileX();
|
||||||
int dz = tile.getTileZ() - selected.getTileZ();
|
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();
|
check();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,9 +320,10 @@ public class DynamicRegionVisualizer implements SWPlayer.Component, Listener {
|
|||||||
Set<Tile> tiles = new HashSet<>();
|
Set<Tile> tiles = new HashSet<>();
|
||||||
for (int x = 0; x <= dx; x++) {
|
for (int x = 0; x <= dx; x++) {
|
||||||
for (int z = 0; z <= dz; z++) {
|
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)
|
SWPlayer.allWithSingleComponent(DynamicRegionVisualizer.class)
|
||||||
.forEach(pair -> pair.getComponent().resetTiles(tiles));
|
.forEach(pair -> pair.getComponent().resetTiles(tiles));
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -34,7 +34,7 @@ public class Tile {
|
|||||||
|
|
||||||
public static final int tileSize = 21;
|
public static final int tileSize = 21;
|
||||||
public static final int tileOffset = tileSize / 2;
|
public static final int tileOffset = tileSize / 2;
|
||||||
public static final int maxTile = 1023;
|
public static final int maxTile = 255;
|
||||||
public static final int minTile = -maxTile;
|
public static final int minTile = -maxTile;
|
||||||
public static final int tilesPerAxis = maxTile * 2 + 1;
|
public static final int tilesPerAxis = maxTile * 2 + 1;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user