forked from SteamWar/SteamWar
Fix DynamicRegion.updateNeighbours
This commit is contained in:
+12
-5
@@ -23,9 +23,12 @@ 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.RegionData;
|
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.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public abstract class DynamicRegion implements Region {
|
public abstract class DynamicRegion implements Region {
|
||||||
@@ -49,14 +52,18 @@ public abstract class DynamicRegion implements Region {
|
|||||||
public abstract void init();
|
public abstract void init();
|
||||||
|
|
||||||
public final void updateNeighbours() {
|
public final void updateNeighbours() {
|
||||||
DynamicRegionSystem.INSTANCE.getNeighbours(this)
|
List<Pair<DynamicRegion, NeighbourDirection>> list = DynamicRegionSystem.INSTANCE.getNeighbours(this).toList();
|
||||||
.forEach(data -> {
|
list.forEach(data -> {
|
||||||
data.getKey().update(this, data.getValue().opposite());
|
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) {
|
public void update(DynamicRegion updateFrom, NeighbourDirection direction) {
|
||||||
// TODO: Implement further
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRegionData(@NonNull RegionData regionData) {
|
public void setRegionData(@NonNull RegionData regionData) {
|
||||||
|
|||||||
+15
-18
@@ -22,6 +22,7 @@ package de.steamwar.bausystem.region.dynamic.path;
|
|||||||
import de.steamwar.bausystem.region.*;
|
import de.steamwar.bausystem.region.*;
|
||||||
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.NonNull;
|
import lombok.NonNull;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
@@ -50,7 +51,6 @@ public class PathRegion extends DynamicRegion {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(DynamicRegion updateFrom, NeighbourDirection direction) {
|
public void update(DynamicRegion updateFrom, NeighbourDirection direction) {
|
||||||
gardenCache = null;
|
|
||||||
for (PathSide side : direction.getSideUpdates()) {
|
for (PathSide side : direction.getSideUpdates()) {
|
||||||
area.reset(side);
|
area.reset(side);
|
||||||
}
|
}
|
||||||
@@ -59,27 +59,24 @@ public class PathRegion extends DynamicRegion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Boolean gardenCache = null;
|
@Getter
|
||||||
|
private boolean garden = false;
|
||||||
|
|
||||||
public boolean isGarden() {
|
public void calculateGardenState() {
|
||||||
if (gardenCache == null) {
|
garden = false;
|
||||||
for (int x = -1; x <= 1; x++) {
|
for (int x = -1; x <= 1; x++) {
|
||||||
for (int z = -1; z <= 1; z++) {
|
for (int z = -1; z <= 1; z++) {
|
||||||
if (x == 0 && z == 0) continue;
|
if (x == 0 && z == 0) continue;
|
||||||
Tile t = tile.add(x, z).orElse(null);
|
Tile t = tile.add(x, z).orElse(null);
|
||||||
if (t == null) {
|
if (t == null) {
|
||||||
gardenCache = false;
|
return;
|
||||||
return false;
|
}
|
||||||
}
|
if (!DynamicRegionSystem.INSTANCE.get(t).getType().isPath()) {
|
||||||
if (!DynamicRegionSystem.INSTANCE.get(t).getType().isPath()) {
|
return;
|
||||||
gardenCache = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gardenCache = true;
|
|
||||||
}
|
}
|
||||||
return gardenCache;
|
garden = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user