Skip to content

Commit

Permalink
don't run empty events or send empty packets
Browse files Browse the repository at this point in the history
  • Loading branch information
sisby-folk committed Mar 29, 2024
1 parent 1e9fdc9 commit 595365e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/main/java/folk/sisby/surveyor/SurveyorEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,24 @@ public class SurveyorEvents {

public static class Invoke {
public static void worldLoad(ServerWorld world) {
if (worldLoad.isEmpty()) return;
WorldSummary summary = WorldSummary.of(world);
worldLoad.forEach((id, handler) -> handler.onWorldLoad(world, summary));
}

public static void terrainUpdated(World world, Collection<ChunkPos> chunks) {
if (terrainUpdated.isEmpty() || chunks.isEmpty()) return;
WorldTerrainSummary summary = WorldSummary.of(world).terrain();
terrainUpdated.forEach((id, handler) -> handler.onTerrainUpdated(world, summary, chunks));
}

public static void terrainUpdated(World world, ChunkPos pos) {

terrainUpdated(world, List.of(pos));
}

public static void structuresAdded(World world, Multimap<RegistryKey<Structure>, ChunkPos> structures) {
if (structuresAdded.isEmpty() || structures.isEmpty()) return;
WorldStructureSummary summary = WorldSummary.of(world).structures();
structuresAdded.forEach((id, handler) -> handler.onStructuresAdded(world, summary, structures));
}
Expand All @@ -51,11 +55,13 @@ public static void structuresAdded(World world, RegistryKey<Structure> key, Chun
}

public static void landmarksAdded(World world, Multimap<LandmarkType<?>, BlockPos> landmarks) {
if (landmarksAdded.isEmpty() || landmarks.isEmpty()) return;
WorldLandmarks summary = WorldSummary.of(world).landmarks();
landmarksAdded.forEach((id, handler) -> handler.onLandmarksAdded(world, summary, landmarks));
}

public static void landmarksRemoved(World world, Multimap<LandmarkType<?>, BlockPos> landmarks) {
if (landmarksRemoved.isEmpty() || landmarks.isEmpty()) return;
WorldLandmarks summary = WorldSummary.of(world).landmarks();
landmarksRemoved.forEach((id, handler) -> handler.onLandmarksRemoved(world, summary, landmarks));
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/folk/sisby/surveyor/SurveyorNetworking.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static void handleKnownTerrain(ServerPlayerEntity player, ServerWorld wo
Map<ChunkPos, BitSet> clientBits = packet.regionBits();
serverBits.forEach((rPos, set) -> {
if (clientBits.containsKey(rPos)) set.andNot(clientBits.get(rPos));
new S2CUpdateRegionPacket(rPos, summary.terrain().getRegion(rPos), set).send(player);
if (!set.isEmpty()) new S2CUpdateRegionPacket(rPos, summary.terrain().getRegion(rPos), set).send(player);
});
}

Expand All @@ -60,6 +60,7 @@ private static void handleKnownStructures(ServerPlayerEntity player, ServerWorld
if (structures.get(key).isEmpty()) structures.remove(key);
}
});
if (structures.isEmpty()) return;
Map<RegistryKey<Structure>, RegistryKey<StructureType<?>>> structureTypes = new HashMap<>();
Multimap<RegistryKey<Structure>, TagKey<Structure>> structureTags = HashMultimap.create();
for (RegistryKey<Structure> key : structures.keySet()) {
Expand All @@ -75,7 +76,7 @@ private static void handleKnownLandmarks(ServerPlayerEntity player, ServerWorld
landmarks.get(type).remove(pos);
if (landmarks.get(type).isEmpty()) landmarks.remove(type);
});
new SyncLandmarksAddedPacket(landmarks).send(player);
if (!landmarks.isEmpty()) new SyncLandmarksAddedPacket(landmarks).send(player);
}

private static void handleLandmarksAdded(ServerPlayerEntity player, ServerWorld world, WorldSummary summary, SyncLandmarksAddedPacket packet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class SurveyorClientEvents {

public static class Invoke {
public static void worldLoad(ClientWorld world, ClientPlayerEntity player) {
if (worldLoad.isEmpty()) return;
SurveyorExploration exploration = SurveyorClient.getExploration(player);
WorldSummary summary = WorldSummary.of(world);
Map<ChunkPos, BitSet> terrain = summary.terrain().bitSet(exploration);
Expand All @@ -42,6 +43,7 @@ public static void worldLoad(ClientWorld world, ClientPlayerEntity player) {
}

public static void terrainUpdated(World world, Collection<ChunkPos> chunks) {
if (terrainUpdated.isEmpty() || chunks.isEmpty()) return;
WorldTerrainSummary summary = WorldSummary.of(world).terrain();
terrainUpdated.forEach((id, handler) -> handler.onTerrainUpdated(world, summary, chunks));
}
Expand All @@ -51,6 +53,7 @@ public static void terrainUpdated(World world, ChunkPos pos) {
}

public static void structuresAdded(World world, Multimap<RegistryKey<Structure>, ChunkPos> structures) {
if (structuresAdded.isEmpty() || structures.isEmpty()) return;
WorldStructureSummary summary = WorldSummary.of(world).structures();
structuresAdded.forEach((id, handler) -> handler.onStructuresAdded(world, summary, structures));
}
Expand All @@ -60,11 +63,13 @@ public static void structuresAdded(World world, RegistryKey<Structure> key, Chun
}

public static void landmarksAdded(World world, Multimap<LandmarkType<?>, BlockPos> landmarks) {
if (landmarksAdded.isEmpty() || landmarks.isEmpty()) return;
WorldLandmarks summary = WorldSummary.of(world).landmarks();
landmarksAdded.forEach((id, handler) -> handler.onLandmarksAdded(world, summary, landmarks));
}

public static void landmarksRemoved(World world, Multimap<LandmarkType<?>, BlockPos> landmarks) {
if (landmarksRemoved.isEmpty() || landmarks.isEmpty()) return;
WorldLandmarks summary = WorldSummary.of(world).landmarks();
landmarksRemoved.forEach((id, handler) -> handler.onLandmarksRemoved(world, summary, landmarks));
}
Expand Down

0 comments on commit 595365e

Please sign in to comment.