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