mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 01:34:04 +00:00
Give modded teleports a 120 s first-chunk deadline and report their real failure
A cold dimension loads the pack and binds the engine on its first chunk, so the 10 s deadline failed teleports that would have worked. /iris tp, primary world routing and Iris Vision now share one 120 s deadline, and /iris tp reports a failed teleport, an unloaded dimension, an offline player or a refused teleport separately instead of always claiming the dimension is not loaded. Upstream:82fa696112d5af3b61f55fde17d
This commit is contained in:
1 parent
92ab8b6d01
commit
149a257a4c
26 files changed
+220
-40
No files matched your search
+1
-14
@@ -65,7 +65,6 @@ public final class ModdedDimensionManager {
|
||||
private static final ConcurrentHashMap<String, Handle> HANDLES = new ConcurrentHashMap<>();
|
||||
private static final TicketType TELEPORT_WARM_TICKET = new TicketType(TicketType.NO_TIMEOUT,
|
||||
TicketType.FLAG_LOADING | TicketType.FLAG_KEEP_DIMENSION_ACTIVE);
|
||||
private static final long TELEPORT_TIMEOUT_SECONDS = 10L;
|
||||
private static volatile ModdedServerAccess access;
|
||||
|
||||
private ModdedDimensionManager() {
|
||||
@@ -265,18 +264,6 @@ public final class ModdedDimensionManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static CompletableFuture<Boolean> teleportAsync(
|
||||
ServerPlayer player,
|
||||
MinecraftServer server,
|
||||
String dimensionId,
|
||||
double x,
|
||||
double y,
|
||||
double z
|
||||
) {
|
||||
return teleportAsync(player, server, dimensionId, x, y, z,
|
||||
System.nanoTime() + TimeUnit.SECONDS.toNanos(TELEPORT_TIMEOUT_SECONDS));
|
||||
}
|
||||
|
||||
public static CompletableFuture<Boolean> teleportAsync(
|
||||
ServerPlayer player,
|
||||
MinecraftServer server,
|
||||
@@ -513,7 +500,7 @@ public final class ModdedDimensionManager {
|
||||
return new TimeoutException("Teleport into " + level.dimension().identifier()
|
||||
+ " at " + ModdedTeleportBounds.blockCoordinate(x) + ","
|
||||
+ ModdedTeleportBounds.blockCoordinate(z)
|
||||
+ " exceeded " + TELEPORT_TIMEOUT_SECONDS + " seconds.");
|
||||
+ " did not finish before its deadline.");
|
||||
}
|
||||
|
||||
private static void runOnServer(MinecraftServer server, Runnable task) {
|
||||
|
||||
+2
-1
@@ -101,7 +101,8 @@ public final class ModdedPrimaryWorldRouter {
|
||||
primary,
|
||||
player.getX(),
|
||||
Double.MIN_VALUE,
|
||||
player.getZ());
|
||||
player.getZ(),
|
||||
ModdedTeleportDeadline.fromNow());
|
||||
teleport.whenComplete((success, failure) -> {
|
||||
inFlight.remove(id);
|
||||
if (Boolean.TRUE.equals(success) && failure == null) {
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Deadline for a teleport that waits on its destination chunk. The first chunk of a cold dimension also loads the
|
||||
* pack and binds the engine; the deadline only bounds a destination whose chunk never completes.
|
||||
*/
|
||||
public final class ModdedTeleportDeadline {
|
||||
private static final long DEADLINE_SECONDS = 120L;
|
||||
|
||||
private ModdedTeleportDeadline() {
|
||||
}
|
||||
|
||||
public static long fromNow() {
|
||||
return System.nanoTime() + TimeUnit.SECONDS.toNanos(DEADLINE_SECONDS);
|
||||
}
|
||||
}
|
||||
+36
-4
@@ -36,6 +36,7 @@ import art.arcane.iris.modded.ModdedForcedDatapack;
|
||||
import art.arcane.iris.modded.ModdedLoader;
|
||||
import art.arcane.iris.modded.ModdedScheduler;
|
||||
import art.arcane.iris.modded.ModdedServerLevels;
|
||||
import art.arcane.iris.modded.ModdedTeleportDeadline;
|
||||
import art.arcane.iris.modded.ModdedWorldgenIds;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
@@ -58,6 +59,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import art.arcane.volmlib.util.localization.MessageArgument;
|
||||
@@ -135,7 +137,8 @@ public final class IrisModdedCommands {
|
||||
dimensionId,
|
||||
8.5D,
|
||||
Double.MIN_VALUE,
|
||||
8.5D);
|
||||
8.5D,
|
||||
ModdedTeleportDeadline.fromNow());
|
||||
teleport.whenComplete((success, failure) -> {
|
||||
if (Boolean.TRUE.equals(success) && failure == null) {
|
||||
return;
|
||||
@@ -144,14 +147,43 @@ public final class IrisModdedCommands {
|
||||
ModdedIrisLog.error("Iris teleport into '{}' failed for {}",
|
||||
dimensionId, player.getUUID(), failure);
|
||||
}
|
||||
server.execute(() -> fail(source, IrisLanguage.plain(
|
||||
ModdedCommandMessages.IRIS_MODDED_COMMANDS_TELEPORT_FAILED_DIMENSION_IS_NOT_LOADED,
|
||||
MessageArgument.untrusted("dimensionId", dimensionId))));
|
||||
server.execute(() -> fail(source, teleportFailure(dimensionId, player.getScoreboardName(), failure,
|
||||
ModdedDimensionManager.level(server, dimensionId) != null,
|
||||
server.getPlayerList().getPlayer(player.getUUID()) != null)));
|
||||
});
|
||||
ok(source, IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_TELEPORTING, MessageArgument.untrusted("value", player.getScoreboardName()), MessageArgument.untrusted("dimensionId", dimensionId)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static String teleportFailure(String dimensionId, String playerName, Throwable failure,
|
||||
boolean dimensionLoaded, boolean playerOnline) {
|
||||
if (failure != null) {
|
||||
return IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_TELEPORT_FAILED_REASON,
|
||||
MessageArgument.untrusted("dimensionId", dimensionId),
|
||||
MessageArgument.untrusted("reason", failureReason(failure)));
|
||||
}
|
||||
if (!dimensionLoaded) {
|
||||
return IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_TELEPORT_FAILED_DIMENSION_IS_NOT_LOADED,
|
||||
MessageArgument.untrusted("dimensionId", dimensionId));
|
||||
}
|
||||
if (!playerOnline) {
|
||||
return IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_TELEPORT_CANCELLED_PLAYER_OFFLINE,
|
||||
MessageArgument.untrusted("dimensionId", dimensionId),
|
||||
MessageArgument.untrusted("value", playerName));
|
||||
}
|
||||
return IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_TELEPORT_REFUSED,
|
||||
MessageArgument.untrusted("dimensionId", dimensionId));
|
||||
}
|
||||
|
||||
private static String failureReason(Throwable failure) {
|
||||
Throwable cause = failure;
|
||||
while (cause instanceof CompletionException && cause.getCause() != null) {
|
||||
cause = cause.getCause();
|
||||
}
|
||||
String message = cause.getMessage();
|
||||
return message == null || message.isBlank() ? cause.getClass().getSimpleName() : message;
|
||||
}
|
||||
|
||||
static int evacuate(CommandSourceStack source, ServerLevel target) {
|
||||
MinecraftServer server = source.getServer();
|
||||
ServerLevel level = target != null ? target : source.getLevel();
|
||||
|
||||
+2
-2
@@ -25,6 +25,7 @@ import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.render.RenderType;
|
||||
import art.arcane.iris.modded.ModdedDimensionManager;
|
||||
import art.arcane.iris.modded.ModdedIrisLog;
|
||||
import art.arcane.iris.modded.ModdedTeleportDeadline;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
@@ -37,7 +38,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class ModdedVisionOverlay implements GuiOverlay {
|
||||
@@ -103,7 +103,7 @@ public final class ModdedVisionOverlay implements GuiOverlay {
|
||||
blockX + 0.5D,
|
||||
surfaceY,
|
||||
blockZ + 0.5D,
|
||||
System.nanoTime() + TimeUnit.SECONDS.toNanos(10L));
|
||||
ModdedTeleportDeadline.fromNow());
|
||||
UUID playerId = player.getUUID();
|
||||
teleport.whenComplete((success, failure) -> {
|
||||
if (failure != null) {
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ModdedTeleportDeadlineTest {
|
||||
@Test
|
||||
public void deadlineOutlastsAColdFirstChunkAndStaysBounded() {
|
||||
long before = System.nanoTime();
|
||||
long deadline = ModdedTeleportDeadline.fromNow();
|
||||
long after = System.nanoTime();
|
||||
|
||||
assertTrue("deadline must outlast a cold first chunk", deadline - before >= TimeUnit.SECONDS.toNanos(60L));
|
||||
assertTrue("deadline must be bounded", deadline - after <= TimeUnit.SECONDS.toNanos(120L));
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package art.arcane.iris.modded.command;
|
||||
|
||||
import art.arcane.iris.core.localization.IrisLanguage;
|
||||
import art.arcane.iris.core.localization.ModdedCommandMessages;
|
||||
import art.arcane.volmlib.util.localization.MessageArgument;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class IrisModdedCommandsTeleportTest {
|
||||
private static final String DIMENSION = "irisworldgen:1";
|
||||
|
||||
@Test
|
||||
public void failureReportsItsRootCauseInsteadOfAnUnloadedDimension() {
|
||||
String message = IrisModdedCommands.teleportFailure(DIMENSION, "Tester",
|
||||
new CompletionException(new IllegalStateException("Exception generating new chunk")), true, true);
|
||||
|
||||
assertEquals(IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_TELEPORT_FAILED_REASON,
|
||||
MessageArgument.untrusted("dimensionId", DIMENSION),
|
||||
MessageArgument.untrusted("reason", "Exception generating new chunk")), message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failureWithoutMessageNamesTheFailureType() {
|
||||
String message = IrisModdedCommands.teleportFailure(DIMENSION, "Tester", new TimeoutException(), true, true);
|
||||
|
||||
assertEquals(IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_TELEPORT_FAILED_REASON,
|
||||
MessageArgument.untrusted("dimensionId", DIMENSION),
|
||||
MessageArgument.untrusted("reason", "TimeoutException")), message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unloadedDimensionIsReportedOnlyWhenItIsGone() {
|
||||
assertEquals(IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_TELEPORT_FAILED_DIMENSION_IS_NOT_LOADED,
|
||||
MessageArgument.untrusted("dimensionId", DIMENSION)),
|
||||
IrisModdedCommands.teleportFailure(DIMENSION, "Tester", null, false, true));
|
||||
assertEquals(IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_TELEPORT_CANCELLED_PLAYER_OFFLINE,
|
||||
MessageArgument.untrusted("dimensionId", DIMENSION),
|
||||
MessageArgument.untrusted("value", "Tester")),
|
||||
IrisModdedCommands.teleportFailure(DIMENSION, "Tester", null, true, false));
|
||||
assertEquals(IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_TELEPORT_REFUSED,
|
||||
MessageArgument.untrusted("dimensionId", DIMENSION)),
|
||||
IrisModdedCommands.teleportFailure(DIMENSION, "Tester", null, true, true));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user