forked from SteamWar/SteamWar
Add DynamicRegion.shouldPathConnect
This commit is contained in:
@@ -32,9 +32,8 @@ public enum RegionType {
|
||||
*/
|
||||
NORMAL(ConnectionType.Plot),
|
||||
|
||||
SPAWN(ConnectionType.Plot),
|
||||
SPAWN_PATH(ConnectionType.Path),
|
||||
SPAWN_EXTENSION(ConnectionType.Plot),
|
||||
SPAWN(ConnectionType.Void),
|
||||
SPAWN_EXTENSION(ConnectionType.Void),
|
||||
PATH(ConnectionType.Path),
|
||||
|
||||
DRY(ConnectionType.Void),
|
||||
@@ -58,11 +57,7 @@ public enum RegionType {
|
||||
}
|
||||
|
||||
public boolean isSpawn() {
|
||||
return this == SPAWN || this == SPAWN_PATH || this == SPAWN_EXTENSION;
|
||||
}
|
||||
|
||||
public boolean isPath() {
|
||||
return this == PATH || this == SPAWN_PATH;
|
||||
return this == SPAWN || this == SPAWN_EXTENSION;
|
||||
}
|
||||
|
||||
public enum ConnectionType {
|
||||
|
||||
+1
-1
@@ -354,7 +354,7 @@ public class DynamicRegionEditor implements SWPlayer.Component, Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (region.getType().isPath() || (force && region.getType().isSpecial())) {
|
||||
if (region.getType() == RegionType.PATH || (force && region.getType().isSpecial())) {
|
||||
region.delete();
|
||||
} else {
|
||||
deleteRegion(player, tile, region);
|
||||
|
||||
+1
-1
@@ -94,7 +94,7 @@ public class DynamicRegionSystem implements RegionSystem {
|
||||
|
||||
@Override
|
||||
public @NonNull Location getWorldSpawn() {
|
||||
return Bukkit.getWorlds().get(0).getSpawnLocation(); // TODO: Temporary
|
||||
return Bukkit.getWorlds().get(0).getSpawnLocation().clone().add(0.5, 0, 0.5); // TODO: Temporary
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+26
@@ -26,6 +26,7 @@ import de.steamwar.bausystem.region.Point;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.RegionData;
|
||||
import de.steamwar.bausystem.region.dynamic.path.PathRegion;
|
||||
import de.steamwar.bausystem.region.dynamic.path.PathSide;
|
||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
@@ -117,6 +118,31 @@ public abstract class DynamicRegion implements Region {
|
||||
regionData.setStore(this);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public PathConnectResult shouldPathConnect(Tile source, PathSide side, boolean diagonal) {
|
||||
return PathConnectResult.BY_TYPE;
|
||||
}
|
||||
|
||||
public enum PathConnectResult {
|
||||
ALWAYS,
|
||||
NEVER,
|
||||
BY_TYPE,
|
||||
;
|
||||
|
||||
public static PathConnectResult of(Boolean result) {
|
||||
return of(result, NEVER);
|
||||
}
|
||||
|
||||
public static PathConnectResult of(Boolean result, PathConnectResult falseResult) {
|
||||
if (result == null) return BY_TYPE;
|
||||
if (result) {
|
||||
return ALWAYS;
|
||||
} else {
|
||||
return falseResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
if (!getType().isDeletable()) return;
|
||||
|
||||
+14
-16
@@ -25,6 +25,7 @@ import de.steamwar.bausystem.region.DynamicRegionSystem;
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.RegionType;
|
||||
import de.steamwar.bausystem.region.dynamic.DynamicRegion;
|
||||
import de.steamwar.bausystem.region.dynamic.PasteUtils;
|
||||
import de.steamwar.bausystem.region.dynamic.Tile;
|
||||
import de.steamwar.bausystem.region.dynamic.VariantSelector;
|
||||
@@ -224,30 +225,27 @@ public class PathArea extends Region.Area {
|
||||
}
|
||||
}
|
||||
|
||||
protected static RegionType.ConnectionType getConnectionType(Tile tile, PathSide side, PathSide optionalSide, RegionType.ConnectionType spawnPathConnection) {
|
||||
Optional<Tile> optionalTile = tile.add(side.tileOffsetX, side.tileOffsetZ);
|
||||
protected static RegionType.ConnectionType getConnectionType(Tile source, PathSide side, PathSide optionalSide) {
|
||||
Optional<Tile> optionalTile = source.add(side.tileOffsetX, side.tileOffsetZ);
|
||||
if (optionalSide != null) {
|
||||
optionalTile = optionalTile.flatMap(t -> t.add(optionalSide.tileOffsetX, optionalSide.tileOffsetZ));
|
||||
}
|
||||
if (optionalTile.isEmpty()) {
|
||||
return Void;
|
||||
}
|
||||
tile = optionalTile.get();
|
||||
Tile tile = optionalTile.get();
|
||||
Region region = DynamicRegionSystem.INSTANCE.get(tile);
|
||||
if (region instanceof PathRegion pathRegion) {
|
||||
return pathRegion.isGarden() ? Garden : Path;
|
||||
if (region instanceof PathRegion pathRegion && pathRegion.isGarden()) {
|
||||
return Garden;
|
||||
}
|
||||
if (region instanceof SpawnRegion spawnRegion) {
|
||||
if (optionalSide == null && side.opposite().equals(spawnRegion.getPathSide())) {
|
||||
return spawnPathConnection;
|
||||
} else {
|
||||
return Void;
|
||||
}
|
||||
if (!(region instanceof DynamicRegion dynamicRegion)) {
|
||||
return region.getType().getConnectionType();
|
||||
}
|
||||
return region.getType().getConnectionType();
|
||||
}
|
||||
|
||||
protected static RegionType.ConnectionType getConnectionType(Tile tile, PathSide side, PathSide optionalSide) {
|
||||
return getConnectionType(tile, side, optionalSide, Path);
|
||||
DynamicRegion.PathConnectResult result = dynamicRegion.shouldPathConnect(source, side.opposite(), optionalSide != null);
|
||||
return switch (result) {
|
||||
case ALWAYS -> Path;
|
||||
case NEVER -> Void;
|
||||
default -> region.getType().getConnectionType();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+20
-5
@@ -21,7 +21,10 @@ package de.steamwar.bausystem.region.dynamic.path;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import de.steamwar.bausystem.region.*;
|
||||
import de.steamwar.bausystem.region.DynamicRegionSystem;
|
||||
import de.steamwar.bausystem.region.RegionBackups;
|
||||
import de.steamwar.bausystem.region.RegionHistory;
|
||||
import de.steamwar.bausystem.region.RegionType;
|
||||
import de.steamwar.bausystem.region.dynamic.*;
|
||||
import de.steamwar.sql.GameModeConfig;
|
||||
import lombok.Getter;
|
||||
@@ -29,6 +32,7 @@ import lombok.NonNull;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@RegionConstructorData(
|
||||
@@ -70,6 +74,15 @@ public class PathRegion extends DynamicRegion {
|
||||
TileUtils.writeTile(writer, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @org.jspecify.annotations.NonNull PathConnectResult shouldPathConnect(Tile source, PathSide side, boolean diagonal) {
|
||||
if (diagonal) {
|
||||
// Needed for inner corners of Small Spawn
|
||||
return PathConnectResult.of(!(tile.equals(Tile.TILE_NN) || tile.equals(Tile.TILE_NP) || tile.equals(Tile.TILE_PN) || tile.equals(Tile.TILE_PP)));
|
||||
}
|
||||
return PathConnectResult.BY_TYPE;
|
||||
}
|
||||
|
||||
public void update(DynamicRegion updateFrom, NeighbourDirection direction) {
|
||||
for (PathSide side : direction.getSideUpdates()) {
|
||||
area.reset(side);
|
||||
@@ -85,12 +98,14 @@ public class PathRegion extends DynamicRegion {
|
||||
public void calculateGardenState() {
|
||||
garden = false;
|
||||
for (PathSide pathSide : PathSide.values()) {
|
||||
RegionType.ConnectionType connectionType = PathArea.getConnectionType(tile, pathSide, null, null);
|
||||
if (connectionType != RegionType.ConnectionType.Path && connectionType != RegionType.ConnectionType.Garden) return;
|
||||
Optional<Tile> optionalTile = tile.add(pathSide.tileOffsetX, pathSide.tileOffsetZ);
|
||||
if (optionalTile.isEmpty()) return;
|
||||
if (DynamicRegionSystem.INSTANCE.get(optionalTile.get()).getType() != RegionType.PATH) return;
|
||||
}
|
||||
for (PathCorner pathCorner : PathCorner.values()) {
|
||||
RegionType.ConnectionType connectionType = PathArea.getConnectionType(tile, pathCorner.side1, pathCorner.side2, null);
|
||||
if (connectionType != RegionType.ConnectionType.Path && connectionType != RegionType.ConnectionType.Garden) return;
|
||||
Optional<Tile> optionalTile = tile.add(pathCorner.side1.tileOffsetX + pathCorner.side2.tileOffsetX, pathCorner.side1.tileOffsetZ + pathCorner.side2.tileOffsetZ);
|
||||
if (optionalTile.isEmpty()) return;
|
||||
if (DynamicRegionSystem.INSTANCE.get(optionalTile.get()).getType() != RegionType.PATH) return;
|
||||
}
|
||||
garden = true;
|
||||
}
|
||||
|
||||
+13
-16
@@ -54,8 +54,6 @@ public class SpawnRegion extends DynamicRegion {
|
||||
@Getter
|
||||
private final Tile tile;
|
||||
|
||||
@Getter
|
||||
private final PathSide pathSide;
|
||||
private final SpawnArea area;
|
||||
|
||||
public SpawnRegion(Tile tile) {
|
||||
@@ -71,17 +69,6 @@ public class SpawnRegion extends DynamicRegion {
|
||||
private SpawnRegion(UUID id, Tile tile) {
|
||||
super(id, null);
|
||||
this.tile = tile;
|
||||
if (tile.equals(Tile.TILE_PZ)) {
|
||||
pathSide = PathSide.East;
|
||||
} else if (tile.equals(Tile.TILE_NZ)) {
|
||||
pathSide = PathSide.West;
|
||||
} else if (tile.equals(Tile.TILE_ZP)) {
|
||||
pathSide = PathSide.South;
|
||||
} else if (tile.equals(Tile.TILE_ZN)) {
|
||||
pathSide = PathSide.North;
|
||||
} else {
|
||||
pathSide = null;
|
||||
}
|
||||
area = new SpawnArea(tile);
|
||||
regionData = PathRegionData.INSTANCE;
|
||||
}
|
||||
@@ -91,12 +78,22 @@ public class SpawnRegion extends DynamicRegion {
|
||||
TileUtils.writeTile(writer, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @org.jspecify.annotations.NonNull PathConnectResult shouldPathConnect(Tile source, PathSide side, boolean diagonal) {
|
||||
System.out.println(tile + " " + side + " " + diagonal);
|
||||
if (diagonal) return PathConnectResult.BY_TYPE;
|
||||
return switch (side) {
|
||||
case North -> PathConnectResult.of(tile.equals(Tile.TILE_ZN), PathConnectResult.BY_TYPE);
|
||||
case South -> PathConnectResult.of(tile.equals(Tile.TILE_ZP), PathConnectResult.BY_TYPE);
|
||||
case East -> PathConnectResult.of(tile.equals(Tile.TILE_PZ), PathConnectResult.BY_TYPE);
|
||||
case West -> PathConnectResult.of(tile.equals(Tile.TILE_NZ), PathConnectResult.BY_TYPE);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull RegionType getType() {
|
||||
if (tile.equals(Tile.ZERO)) {
|
||||
if (tile.getTileX() == 0 || tile.getTileZ() == 0) {
|
||||
return RegionType.SPAWN;
|
||||
} else if (pathSide != null) {
|
||||
return RegionType.SPAWN_PATH;
|
||||
} else {
|
||||
return RegionType.SPAWN_EXTENSION;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user