mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 01:34:04 +00:00
Report stopped river searches
- A timed-out hydrology search throws HydrologySearchTimeoutException carrying the nearest feature found so far - nearestRiver answers RiverSearch.Stopped with the nearer of that feature and recorded water, and a message saying a nearer one may exist - Bukkit and modded find river print the stopped message and never teleport on a stopped search - Both commands catch every throwable while delivering a result and log it before telling the player - Modded logs a result that cannot reach the server thread instead of dropping it - The four-argument nearestFeature is removed; tests call the six-argument form
This commit is contained in:
1 parent
474b1e873a
commit
9afd70e69f
11 files changed
+247
-76
No files matched your search
+30
-12
@@ -153,28 +153,46 @@ final class ModdedLocateCommands {
|
||||
RiverRequest request = new RiverRequest(source, level, player, featureType);
|
||||
IrisModdedCommands.ok(source, GenerationSemanticQueries.riverSearchMessage(featureType, GenerationSemanticQueries.RIVER_SEARCH_DISTANCE));
|
||||
GenerationSemanticQueries.startRiverSearch(player.id(), MultiBurst.burst, engine, featureType, player.blockX(), player.blockZ())
|
||||
.whenComplete((GenerationSemanticQueries.RiverSearch search, Throwable error) -> {
|
||||
if (!(error instanceof CancellationException)) {
|
||||
server.execute(() -> finishRiverSearch(request, search, error));
|
||||
}
|
||||
});
|
||||
.whenComplete((GenerationSemanticQueries.RiverSearch search, Throwable error) ->
|
||||
deliverRiverSearch(server, request, search, error));
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static void deliverRiverSearch(NativeModdedServer server, RiverRequest request, GenerationSemanticQueries.RiverSearch search,
|
||||
Throwable error) {
|
||||
if (error instanceof CancellationException) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
server.execute(() -> finishRiverSearch(request, search, error));
|
||||
} catch (Throwable rejected) {
|
||||
ModdedIrisLog.error("Hydrology locate result for {} could not reach the server thread", request.type().key(), rejected);
|
||||
}
|
||||
}
|
||||
|
||||
private static void finishRiverSearch(RiverRequest request, GenerationSemanticQueries.RiverSearch search, Throwable error) {
|
||||
if (error != null) {
|
||||
ModdedIrisLog.error("Hydrology locate failed for {}", request.type().key(), error);
|
||||
IrisModdedCommands.fail(request.source(), "Could not search for " + request.label() + ": " + error.getClass().getSimpleName()
|
||||
+ (error.getMessage() == null ? "" : " - " + error.getMessage()));
|
||||
reportRiverFailure(request, error);
|
||||
return;
|
||||
}
|
||||
switch (search) {
|
||||
case GenerationSemanticQueries.RiverSearch.Missing missing -> IrisModdedCommands.fail(request.source(), missing.message());
|
||||
case GenerationSemanticQueries.RiverSearch.Found found -> teleportToStructure(request.source(), request.level(),
|
||||
request.player(), found.feature().x(), found.feature().y() + 2, found.feature().z(), request.label());
|
||||
try {
|
||||
switch (search) {
|
||||
case GenerationSemanticQueries.RiverSearch.Missing missing -> IrisModdedCommands.fail(request.source(), missing.message());
|
||||
case GenerationSemanticQueries.RiverSearch.Stopped stopped -> IrisModdedCommands.fail(request.source(), stopped.message());
|
||||
case GenerationSemanticQueries.RiverSearch.Found found -> teleportToStructure(request.source(), request.level(),
|
||||
request.player(), found.feature().x(), found.feature().y() + 2, found.feature().z(), request.label());
|
||||
}
|
||||
} catch (Throwable failure) {
|
||||
reportRiverFailure(request, failure);
|
||||
}
|
||||
}
|
||||
|
||||
private static void reportRiverFailure(RiverRequest request, Throwable error) {
|
||||
ModdedIrisLog.error("Hydrology locate failed for {}", request.type().key(), error);
|
||||
IrisModdedCommands.fail(request.source(), "Could not search for " + request.label() + ": " + error.getClass().getSimpleName()
|
||||
+ (error.getMessage() == null ? "" : " - " + error.getMessage()));
|
||||
}
|
||||
|
||||
static int gotoStructure(NativeCommandSource source, String keyRaw) {
|
||||
NativeWorld level = source.world();
|
||||
Engine engine = IrisModdedCommands.engineFor(level);
|
||||
|
||||
+31
@@ -4,6 +4,7 @@ import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureQuery;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureRef;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureType;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologySearchTimeoutException;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
@@ -18,6 +19,7 @@ import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.MockedConstruction;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -81,6 +83,35 @@ public class ModdedLocateRiverTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stoppedSearchReportsTheNearestWaterWithoutTeleporting() throws Exception {
|
||||
Fixture fixture = new Fixture();
|
||||
when(fixture.runtime.nearestFeature(anyInt(), anyInt(), any(), anyInt(), any(), any())).thenThrow(new HydrologySearchTimeoutException(
|
||||
Duration.ofSeconds(30L), new HydrologyFeatureRef(9L, HydrologyFeatureType.WATERFALL, 400, 130, -250)));
|
||||
try (MockedStatic<IrisModdedCommands> commands = fixture.commands()) {
|
||||
assertEquals(1, ModdedLocateCommands.gotoRiver(fixture.source, "waterfall"));
|
||||
fixture.finishOnServerThread();
|
||||
|
||||
commands.verify(() -> IrisModdedCommands.fail(fixture.source, "Stopped searching for the nearest waterfall after 30 seconds. "
|
||||
+ "The nearest waterfall found so far is at 400, 66, -250; a nearer one may exist."));
|
||||
verify(fixture.player, never()).teleport(any(), anyDouble(), anyDouble(), anyDouble());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deliveryFailureIsReportedInsteadOfLost() throws Exception {
|
||||
Fixture fixture = new Fixture();
|
||||
when(fixture.runtime.nearestFeature(anyInt(), anyInt(), any(), anyInt(), any(), any())).thenReturn(Optional.empty());
|
||||
try (MockedStatic<IrisModdedCommands> commands = fixture.commands()) {
|
||||
commands.when(() -> IrisModdedCommands.fail(fixture.source, "No river found within " + DISTANCE + " blocks."))
|
||||
.thenThrow(new LinkageError("source gone"));
|
||||
assertEquals(1, ModdedLocateCommands.gotoRiver(fixture.source, "river"));
|
||||
fixture.finishOnServerThread();
|
||||
|
||||
commands.verify(() -> IrisModdedCommands.fail(fixture.source, "Could not search for river: LinkageError - source gone"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plannerFailureIsReportedAsAnErrorNotAsNotFound() throws Exception {
|
||||
Fixture fixture = new Fixture();
|
||||
|
||||
Reference in new issue
Block a user