From 9f27292fa290a88fab10092fc7069f2b707e3318 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Fri, 6 Mar 2026 13:46:29 +0100 Subject: [PATCH] Add Garden handling for PathRegion --- .../steamwar/bausystem/region/RegionType.java | 1 + .../region/dynamic/path/PathArea.java | 35 ++++++++----------- .../region/dynamic/path/PathRegion.java | 33 ++++++++++++++--- .../region/dynamic/path/SelectorCorner.java | 4 +-- 4 files changed, 45 insertions(+), 28 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionType.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionType.java index a204a68d..b02c7049 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionType.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionType.java @@ -70,5 +70,6 @@ public enum RegionType { Path, Water, Global, + Garden, } } diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/PathArea.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/PathArea.java index 2d702cc6..7347005a 100644 --- a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/PathArea.java +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/PathArea.java @@ -37,8 +37,7 @@ import java.io.File; import java.util.Optional; import java.util.UUID; -import static de.steamwar.bausystem.region.RegionType.ConnectionType.Global; -import static de.steamwar.bausystem.region.RegionType.ConnectionType.Path; +import static de.steamwar.bausystem.region.RegionType.ConnectionType.*; public class PathArea implements Region.Area { @@ -54,6 +53,7 @@ public class PathArea implements Region.Area { .Case(Global, SIDE_GLOBAL); private static final SelectorCorner SELECTOR_CORNER = new SelectorCorner() + // Path to Global! .Case(Path, Global, Global, SIDE_GLOBAL, RotationCorrection.WithCorrection) .Case(Global, Path, Path, SIDE_GLOBAL) .Case(Global, Path, Global, SIDE_GLOBAL) @@ -101,6 +101,7 @@ public class PathArea implements Region.Area { UsingOrdinal, } + private final PathRegion region; private final UUID regionIdentifier; private final Tile tile; private final Point minPoint; @@ -108,6 +109,7 @@ public class PathArea implements Region.Area { private final Point copyPoint; public PathArea(Tile tile, PathRegion region) { + this.region = region; this.regionIdentifier = region.getID(); this.tile = tile; @@ -138,7 +140,7 @@ public class PathArea implements Region.Area { @Override public void reset(PasteBuilder pasteBuilder, boolean extension) { - if (isGarden()) { + if (region.isGarden()) { // TODO: Implement Garden case! } @@ -182,28 +184,19 @@ public class PathArea implements Region.Area { } } - private boolean isGarden() { - for (int x = -1; x <= 1; x++) { - for (int z = -1; z <= 1; z++) { - if (x == 0 && z == 0) continue; - Tile tile = this.tile.add(x, z).orElse(null); - if (tile == null) { - return false; - } - if (!DynamicRegionSystem.INSTANCE.get(tile).getType().isPath()) { - return false; - } - } - } - return true; - } - protected static RegionType.ConnectionType getConnectionType(Tile tile, Side side, Side optionalSide) { Optional optionalTile = tile.add(side.tileOffsetX, side.tileOffsetZ); if (optionalSide != null) { optionalTile = optionalTile.flatMap(t -> t.add(optionalSide.tileOffsetX, optionalSide.tileOffsetZ)); } - return optionalTile.map(t -> DynamicRegionSystem.INSTANCE.get(t.getCenterLocation()).getType().getConnectionType()) - .orElse(RegionType.ConnectionType.Global); + if (optionalTile.isEmpty()) { + return RegionType.ConnectionType.Global; + } + tile = optionalTile.get(); + Region region = DynamicRegionSystem.INSTANCE.get(tile.getCenterLocation()); + if (region instanceof PathRegion pathRegion) { + return pathRegion.isGarden() ? Garden : Path; + } + return region.getType().getConnectionType(); } } diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/PathRegion.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/PathRegion.java index 19c75906..d343b824 100644 --- a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/PathRegion.java +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/PathRegion.java @@ -19,10 +19,7 @@ package de.steamwar.bausystem.region.dynamic.path; -import de.steamwar.bausystem.region.RegionBackups; -import de.steamwar.bausystem.region.RegionData; -import de.steamwar.bausystem.region.RegionHistory; -import de.steamwar.bausystem.region.RegionType; +import de.steamwar.bausystem.region.*; import de.steamwar.bausystem.region.dynamic.DynamicRegion; import de.steamwar.bausystem.region.dynamic.DynamicRegionRepository; import de.steamwar.bausystem.region.dynamic.RegionConstructorData; @@ -41,6 +38,7 @@ import java.util.UUID; public class PathRegion extends DynamicRegion { private PathArea area; + private Tile tile; public PathRegion(UUID id, int minX, int minZ) { super(id, minX, minZ); @@ -48,16 +46,41 @@ public class PathRegion extends DynamicRegion { @Override public void init() { - area = new PathArea(Tile.fromXZ(minX, minZ).orElseThrow(), this); + tile = Tile.fromXZ(minX, minZ).orElseThrow(); + area = new PathArea(tile, this); regionData = new PathRegionData(this); } @Override public void update(DynamicRegion updateFrom) { + gardenCache = null; // TODO: Improve area.reset(null, false); } + private Boolean gardenCache = null; + + public boolean isGarden() { + if (gardenCache == null) { + 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) { + gardenCache = false; + return false; + } + if (!DynamicRegionSystem.INSTANCE.get(t).getType().isPath()) { + gardenCache = false; + return false; + } + } + } + gardenCache = true; + } + return gardenCache; + } + @Override public @NonNull RegionType getType() { return RegionType.PATH; diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/SelectorCorner.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/SelectorCorner.java index a22e5dad..405f2e12 100644 --- a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/SelectorCorner.java +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/dynamic/path/SelectorCorner.java @@ -31,8 +31,8 @@ class SelectorCorner { static { int values = RegionType.ConnectionType.values().length; - BITS = (int) (Math.log(values) / Math.log(2)); - SELECTOR_COUNT = (int) Math.pow(2, BITS * 3); + BITS = (int) Math.ceil(Math.log(values) / Math.log(2)); + SELECTOR_COUNT = (int) Math.pow(2, BITS * 3D); } private VariantSelector[] selectors = new VariantSelector[SELECTOR_COUNT];