forked from SteamWar/SteamWar
Cleanup and add comments
This commit is contained in:
+6
@@ -26,6 +26,7 @@ import de.steamwar.bausystem.shared.Pair;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@@ -138,6 +139,10 @@ public class DynamicRegionSystem implements RegionSystem {
|
|||||||
return regionMap.values().stream();
|
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) {
|
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 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);
|
Point maxPoint = region.getArea().getMaxPoint(false).add(Tile.tileSize, 0, Tile.tileSize);
|
||||||
@@ -175,6 +180,7 @@ public class DynamicRegionSystem implements RegionSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
public Stream<Region> getConnectedRegions(Region region) {
|
public Stream<Region> getConnectedRegions(Region region) {
|
||||||
Set<Region> regions = regionTypeMap.get(region.getType());
|
Set<Region> regions = regionTypeMap.get(region.getType());
|
||||||
|
|
||||||
|
|||||||
+7
-7
@@ -52,20 +52,20 @@ public abstract class DynamicRegion implements Region {
|
|||||||
public abstract void init();
|
public abstract void init();
|
||||||
|
|
||||||
public final void updateNeighbours() {
|
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 -> {
|
list.forEach(data -> {
|
||||||
if (data.getKey() instanceof PathRegion pathRegion) {
|
data.getKey().calculateGardenState();
|
||||||
pathRegion.calculateGardenState();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
// Updating world state for all neighbouring PathRegions
|
||||||
list.forEach(data -> {
|
list.forEach(data -> {
|
||||||
data.getKey().update(this, data.getValue().opposite());
|
data.getKey().update(this, data.getValue().opposite());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(DynamicRegion updateFrom, NeighbourDirection direction) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRegionData(@NonNull RegionData regionData) {
|
public void setRegionData(@NonNull RegionData regionData) {
|
||||||
this.regionData = regionData;
|
this.regionData = regionData;
|
||||||
regionData.setStore(this);
|
regionData.setStore(this);
|
||||||
|
|||||||
+7
-1
@@ -25,6 +25,7 @@ import com.google.gson.JsonParser;
|
|||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
import de.steamwar.bausystem.region.*;
|
import de.steamwar.bausystem.region.*;
|
||||||
|
import de.steamwar.bausystem.region.dynamic.path.PathRegion;
|
||||||
import de.steamwar.bausystem.region.flags.Flag;
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
import lombok.Cleanup;
|
import lombok.Cleanup;
|
||||||
import lombok.SneakyThrows;
|
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)");
|
RegionSystem.LOGGER.log(Level.SEVERE, "Failed to read region metadata file (region no longer exists)");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
RegionConstructorData constructorData = DynamicRegionSystem.constructorDataMap.get(regionClass);
|
|
||||||
|
|
||||||
Tile tile = Tile.fromTile(tileX, tileZ).orElse(null);
|
Tile tile = Tile.fromTile(tileX, tileZ).orElse(null);
|
||||||
if (tile == null) {
|
if (tile == null) {
|
||||||
@@ -146,6 +146,12 @@ public class DynamicRegionRepository {
|
|||||||
Location minTileLocation = tile.getMinLocation();
|
Location minTileLocation = tile.getMinLocation();
|
||||||
constructRegion(regionClass, regionUUID, minTileLocation.getBlockX(), minTileLocation.getBlockZ());
|
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) {
|
public static DynamicRegion constructRegion(Class<? extends DynamicRegion> clazz, UUID uuid, int minX, int minZ) {
|
||||||
|
|||||||
-1
@@ -49,7 +49,6 @@ public class PathRegion extends DynamicRegion {
|
|||||||
regionData = new PathRegionData(this);
|
regionData = new PathRegionData(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(DynamicRegion updateFrom, NeighbourDirection direction) {
|
public void update(DynamicRegion updateFrom, NeighbourDirection direction) {
|
||||||
for (PathSide side : direction.getSideUpdates()) {
|
for (PathSide side : direction.getSideUpdates()) {
|
||||||
area.reset(side);
|
area.reset(side);
|
||||||
|
|||||||
Reference in New Issue
Block a user