forked from SteamWar/SteamWar
Implement Garden updates for Path Regions correctly
This commit is contained in:
+25
-2
@@ -28,7 +28,9 @@ import de.steamwar.bausystem.shared.Pair;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public abstract class DynamicRegion implements Region {
|
public abstract class DynamicRegion implements Region {
|
||||||
@@ -54,15 +56,36 @@ public abstract class DynamicRegion implements Region {
|
|||||||
public final void updateNeighbours() {
|
public final void updateNeighbours() {
|
||||||
List<Pair<PathRegion, NeighbourDirection>> list = DynamicRegionSystem.INSTANCE.getNeighbours(this)
|
List<Pair<PathRegion, NeighbourDirection>> list = DynamicRegionSystem.INSTANCE.getNeighbours(this)
|
||||||
.filter(data -> data.getKey() instanceof PathRegion)
|
.filter(data -> data.getKey() instanceof PathRegion)
|
||||||
.map(data -> (Pair<PathRegion, NeighbourDirection>)(Pair) data)
|
.map(data -> (Pair<PathRegion, NeighbourDirection>) (Pair) data)
|
||||||
.toList();
|
.toList();
|
||||||
// Calculate Garden State for all neighbouring PathRegions
|
// Calculate Garden State for all neighbouring PathRegions
|
||||||
|
Set<UUID> needsFullReset = new HashSet<>();
|
||||||
list.forEach(data -> {
|
list.forEach(data -> {
|
||||||
|
boolean previousGardenState = data.getKey().isGarden();
|
||||||
data.getKey().calculateGardenState();
|
data.getKey().calculateGardenState();
|
||||||
|
if (data.getKey().isGarden() != previousGardenState) {
|
||||||
|
needsFullReset.add(data.getKey().getID());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// Updating world state for all neighbouring PathRegions
|
// Updating world state for all neighbouring PathRegions
|
||||||
list.forEach(data -> {
|
list.forEach(data -> {
|
||||||
data.getKey().update(this, data.getValue().opposite());
|
if (needsFullReset.contains(data.getKey().getID())) {
|
||||||
|
data.getKey().getArea().reset(null, false);
|
||||||
|
} else {
|
||||||
|
data.getKey().update(this, data.getValue().opposite());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// All full reset regions need to update their neighbours!
|
||||||
|
needsFullReset.forEach(uuid -> {
|
||||||
|
Region region = DynamicRegionSystem.INSTANCE.getRegion(uuid).orElse(null);
|
||||||
|
if (!(region instanceof DynamicRegion dynamicRegion)) return;
|
||||||
|
DynamicRegionSystem.INSTANCE.getNeighbours(dynamicRegion)
|
||||||
|
.filter(data -> data.getKey() instanceof PathRegion)
|
||||||
|
.map(data -> (Pair<PathRegion, NeighbourDirection>) (Pair) data)
|
||||||
|
.forEach(data -> {
|
||||||
|
if (data.getKey().isGarden()) return;
|
||||||
|
data.getKey().update(dynamicRegion, data.getValue().opposite());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-1
@@ -44,6 +44,7 @@ public class PathArea implements Region.Area {
|
|||||||
private static final File PATH_DIR = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "sections/path");
|
private static final File PATH_DIR = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "sections/path");
|
||||||
private static final File FALLBACK_SCHEM = new File(PATH_DIR, "Fallback.schem");
|
private static final File FALLBACK_SCHEM = new File(PATH_DIR, "Fallback.schem");
|
||||||
|
|
||||||
|
private static final VariantSelector GARDEN = VariantSelector.Get(new File(PATH_DIR, "garden"));
|
||||||
private static final VariantSelector CENTER_NORMAL = VariantSelector.Get(new File(PATH_DIR, "center/normal"));
|
private static final VariantSelector CENTER_NORMAL = VariantSelector.Get(new File(PATH_DIR, "center/normal"));
|
||||||
private static final VariantSelector SIDE_GLOBAL = VariantSelector.Get(new File(PATH_DIR, "side/global"));
|
private static final VariantSelector SIDE_GLOBAL = VariantSelector.Get(new File(PATH_DIR, "side/global"));
|
||||||
private static final VariantSelector CORNER_INNER_GLOBAL = VariantSelector.Get(new File(PATH_DIR, "cinner/global"));
|
private static final VariantSelector CORNER_INNER_GLOBAL = VariantSelector.Get(new File(PATH_DIR, "cinner/global"));
|
||||||
@@ -150,7 +151,11 @@ public class PathArea implements Region.Area {
|
|||||||
@Override
|
@Override
|
||||||
public void reset(PasteBuilder pasteBuilder, boolean extension) {
|
public void reset(PasteBuilder pasteBuilder, boolean extension) {
|
||||||
if (region.isGarden()) {
|
if (region.isGarden()) {
|
||||||
// TODO: Implement Garden case!
|
File resetFile = GARDEN.select(regionIdentifier, 0).orElse(null);
|
||||||
|
if (resetFile != null) {
|
||||||
|
PasteUtils.paste(resetFile, minPoint, 0);
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
File resetFile = CENTER_NORMAL.select(regionIdentifier, 0).orElse(null);
|
File resetFile = CENTER_NORMAL.select(regionIdentifier, 0).orElse(null);
|
||||||
|
|||||||
+6
@@ -40,6 +40,7 @@ public class PathRegion extends DynamicRegion {
|
|||||||
|
|
||||||
public PathRegion(UUID id, int minX, int minZ) {
|
public PathRegion(UUID id, int minX, int minZ) {
|
||||||
super(id, minX, minZ);
|
super(id, minX, minZ);
|
||||||
|
calculateGardenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -122,4 +123,9 @@ public class PathRegion extends DynamicRegion {
|
|||||||
public void loadRegion(RegionData regionData) {
|
public void loadRegion(RegionData regionData) {
|
||||||
DynamicRegionRepository.loadRegionData(this, regionData);
|
DynamicRegionRepository.loadRegionData(this, regionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return tile + "=" + getID();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user