Fix DynamicRegion.updateNeighbours

This commit is contained in:
2026-03-06 20:40:38 +01:00
parent aaa8a9d122
commit 6a4c021b8b
2 changed files with 27 additions and 23 deletions
@@ -23,9 +23,12 @@ import de.steamwar.bausystem.region.DynamicRegionSystem;
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.shared.Pair;
import lombok.Getter;
import lombok.NonNull;
import java.util.List;
import java.util.UUID;
public abstract class DynamicRegion implements Region {
@@ -49,14 +52,18 @@ public abstract class DynamicRegion implements Region {
public abstract void init();
public final void updateNeighbours() {
DynamicRegionSystem.INSTANCE.getNeighbours(this)
.forEach(data -> {
data.getKey().update(this, data.getValue().opposite());
});
List<Pair<DynamicRegion, NeighbourDirection>> list = DynamicRegionSystem.INSTANCE.getNeighbours(this).toList();
list.forEach(data -> {
if (data.getKey() instanceof PathRegion pathRegion) {
pathRegion.calculateGardenState();
}
});
list.forEach(data -> {
data.getKey().update(this, data.getValue().opposite());
});
}
public void update(DynamicRegion updateFrom, NeighbourDirection direction) {
// TODO: Implement further
}
public void setRegionData(@NonNull RegionData regionData) {
@@ -22,6 +22,7 @@ package de.steamwar.bausystem.region.dynamic.path;
import de.steamwar.bausystem.region.*;
import de.steamwar.bausystem.region.dynamic.*;
import de.steamwar.sql.GameModeConfig;
import lombok.Getter;
import lombok.NonNull;
import org.bukkit.Material;
@@ -50,7 +51,6 @@ public class PathRegion extends DynamicRegion {
@Override
public void update(DynamicRegion updateFrom, NeighbourDirection direction) {
gardenCache = null;
for (PathSide side : direction.getSideUpdates()) {
area.reset(side);
}
@@ -59,27 +59,24 @@ public class PathRegion extends DynamicRegion {
}
}
private Boolean gardenCache = null;
@Getter
private boolean garden = false;
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;
}
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;
}
}
gardenCache = true;
}
return gardenCache;
garden = true;
}
@Override