Cleanup and add comments

This commit is contained in:
2026-03-06 21:09:09 +01:00
parent 6a4c021b8b
commit 27deebd570
4 changed files with 20 additions and 9 deletions
@@ -26,6 +26,7 @@ import de.steamwar.bausystem.shared.Pair;
import lombok.NonNull;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.io.BufferedReader;
@@ -138,6 +139,10 @@ public class DynamicRegionSystem implements RegionSystem {
return regionMap.values().stream();
}
public @NonNull Stream<Region> getRegionsByType(RegionType type) {
return regionTypeMap.get(type).stream();
}
private Stream<Pair<Region, NeighbourDirection>> getNeighbours(Region region, boolean noCorners, boolean fastCache, Collection<Region> regions) {
Point minPoint = region.getArea().getMinPoint(false).subtract(TILE_SIZE_ADJUSTED, 0, TILE_SIZE_ADJUSTED);
Point maxPoint = region.getArea().getMaxPoint(false).add(Tile.tileSize, 0, Tile.tileSize);
@@ -175,6 +180,7 @@ public class DynamicRegionSystem implements RegionSystem {
}
@Override
@NotNull
public Stream<Region> getConnectedRegions(Region region) {
Set<Region> regions = regionTypeMap.get(region.getType());
@@ -52,20 +52,20 @@ public abstract class DynamicRegion implements Region {
public abstract void init();
public final void updateNeighbours() {
List<Pair<DynamicRegion, NeighbourDirection>> list = DynamicRegionSystem.INSTANCE.getNeighbours(this).toList();
List<Pair<PathRegion, NeighbourDirection>> list = DynamicRegionSystem.INSTANCE.getNeighbours(this)
.filter(data -> data.getKey() instanceof PathRegion)
.map(data -> new Pair<>((PathRegion) data.getKey(), data.getValue()))
.toList();
// Calculate Garden State for all neighbouring PathRegions
list.forEach(data -> {
if (data.getKey() instanceof PathRegion pathRegion) {
pathRegion.calculateGardenState();
}
data.getKey().calculateGardenState();
});
// Updating world state for all neighbouring PathRegions
list.forEach(data -> {
data.getKey().update(this, data.getValue().opposite());
});
}
public void update(DynamicRegion updateFrom, NeighbourDirection direction) {
}
public void setRegionData(@NonNull RegionData regionData) {
this.regionData = regionData;
regionData.setStore(this);
@@ -25,6 +25,7 @@ import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import com.google.gson.stream.JsonWriter;
import de.steamwar.bausystem.region.*;
import de.steamwar.bausystem.region.dynamic.path.PathRegion;
import de.steamwar.bausystem.region.flags.Flag;
import lombok.Cleanup;
import lombok.SneakyThrows;
@@ -136,7 +137,6 @@ public class DynamicRegionRepository {
RegionSystem.LOGGER.log(Level.SEVERE, "Failed to read region metadata file (region no longer exists)");
continue;
}
RegionConstructorData constructorData = DynamicRegionSystem.constructorDataMap.get(regionClass);
Tile tile = Tile.fromTile(tileX, tileZ).orElse(null);
if (tile == null) {
@@ -146,6 +146,12 @@ public class DynamicRegionRepository {
Location minTileLocation = tile.getMinLocation();
constructRegion(regionClass, regionUUID, minTileLocation.getBlockX(), minTileLocation.getBlockZ());
}
// Calculate Garden State for all PathRegions
DynamicRegionSystem.INSTANCE.getRegionsByType(RegionType.PATH)
.forEach(region -> {
((PathRegion) region).calculateGardenState();
});
}
public static DynamicRegion constructRegion(Class<? extends DynamicRegion> clazz, UUID uuid, int minX, int minZ) {
@@ -49,7 +49,6 @@ public class PathRegion extends DynamicRegion {
regionData = new PathRegionData(this);
}
@Override
public void update(DynamicRegion updateFrom, NeighbourDirection direction) {
for (PathSide side : direction.getSideUpdates()) {
area.reset(side);