forked from SteamWar/SteamWar
Improve PathRegion.calculateGardenState
This commit is contained in:
+4
-1
@@ -1,6 +1,9 @@
|
||||
{
|
||||
"region_identifier": "SpawnRegion",
|
||||
"tiles": [
|
||||
{ "tile_x": 0, "tile_z": 0 }
|
||||
{
|
||||
"tile_x": 0,
|
||||
"tile_z": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
+8
-13
@@ -29,7 +29,9 @@ import lombok.NonNull;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RegionConstructorData(
|
||||
identifier = "path",
|
||||
@@ -81,19 +83,12 @@ public class PathRegion extends DynamicRegion {
|
||||
|
||||
public void calculateGardenState() {
|
||||
garden = false;
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
for (int z = -1; z <= 1; z++) {
|
||||
if (x == 0 && z == 0) continue;
|
||||
Tile t = tile.add(x, z).orElse(null);
|
||||
if (t == null) {
|
||||
return;
|
||||
}
|
||||
if (!DynamicRegionSystem.INSTANCE.get(t).getType().isPath()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
garden = true;
|
||||
Set<Tile> neighbours = tile.neighboursRing().collect(Collectors.toSet());
|
||||
if (neighbours.size() == 8) return;
|
||||
garden = neighbours.stream()
|
||||
.map(DynamicRegionSystem.INSTANCE::get)
|
||||
.map(Region::getType)
|
||||
.allMatch(RegionType::isPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user