Skip to content

Commit 36c2ab6

Browse files
fix(ravengard): dungeon stamping loads its chunks and joins stop colliding
The stamp batch never completed because block batches only land in loaded chunks and a freshly created instance has none, which left every runner stuck on the preparing message; the stamper now loads every chunk under the layout's bounds before applying. The static dungeon game also pulled orchestrated runners into itself a second after connecting, which is where the surprise spectator switch came from, so it now skips anyone already assigned to a generated instance. Re-running join while a dungeon is still stamping answers with a wait message instead of restarting the flow.
1 parent 66b0b91 commit 36c2ab6

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

type.ravengarddungeon/src/main/java/net/swofty/type/ravengarddungeon/events/ActionPlayerJoin.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ public void run(AsyncPlayerConfigurationEvent event) {
1717
RavengardDungeonPlayer player = (RavengardDungeonPlayer) event.getPlayer();
1818
ScheduleUtility.delay(() -> {
1919
if (!player.isOnline()) return;
20+
for (var instance : net.swofty.type.ravengarddungeon.game.DungeonInstanceRegistry.all()) {
21+
if (instance.getPlayers().contains(player.getUuid())) {
22+
return;
23+
}
24+
}
2025
Game.JoinResult result = TypeRavengardDungeonLoader.getGame().join(player);
2126
if (result instanceof Game.JoinResult.Denied(String reason)) {
2227
player.sendMessage("§cCould not enter the dungeon: " + reason);

type.ravengarddungeon/src/main/java/net/swofty/type/ravengarddungeon/game/DungeonInstanceRegistry.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ public static DungeonInstance findByIdPrefix(String prefix) {
146146
}
147147

148148
public static void sendPlayerIn(net.minestom.server.entity.Player player, DungeonInstance instance) {
149+
if (instance.getPlayers().contains(player.getUuid()) && !instance.whenReady().isDone()) {
150+
player.sendMessage("§7Your dungeon is still being stamped, hold on...");
151+
return;
152+
}
149153
instance.markPlayerJoined(player.getUuid());
150154
player.sendMessage("§7Preparing your dungeon (seed §f" + instance.getSeed() + "§7)...");
151155
boolean aerial = instance.getMode().equals("ADMIN");

type.ravengarddungeon/src/main/java/net/swofty/type/ravengarddungeon/generator/RavengardDungeonGenerator.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,29 @@ public static CompletableFuture<Void> stamp(GeneratedDungeon generated, Instance
8989
plugDoorway(batch, socket);
9090
}
9191

92+
// batches only land in loaded chunks, and a fresh instance has none
93+
int minX = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE;
94+
int minZ = Integer.MAX_VALUE, maxZ = Integer.MIN_VALUE;
95+
for (RoomPlacement placement : generated.dungeon().getPlacements()) {
96+
minX = Math.min(minX, placement.originX() - 2);
97+
maxX = Math.max(maxX, placement.originX() + placement.getFootprintWidth() + 2);
98+
minZ = Math.min(minZ, placement.originZ() - 2);
99+
maxZ = Math.max(maxZ, placement.originZ() + placement.getFootprintDepth() + 2);
100+
}
101+
List<CompletableFuture<?>> chunkLoads = new ArrayList<>();
102+
for (int chunkX = minX >> 4; chunkX <= (maxX >> 4); chunkX++) {
103+
for (int chunkZ = minZ >> 4; chunkZ <= (maxZ >> 4); chunkZ++) {
104+
chunkLoads.add(instance.loadChunk(chunkX, chunkZ));
105+
}
106+
}
107+
92108
CompletableFuture<Void> future = new CompletableFuture<>();
93-
batch.apply(instance, applied -> future.complete(null));
109+
CompletableFuture.allOf(chunkLoads.toArray(new CompletableFuture[0]))
110+
.thenRun(() -> batch.apply(instance, applied -> future.complete(null)))
111+
.exceptionally(throwable -> {
112+
future.completeExceptionally(throwable);
113+
return null;
114+
});
94115
return future;
95116
}
96117

0 commit comments

Comments
 (0)