Bound find river search

- HydrologyFeatureSearch stops after its timeout or when the caller cancels, waiting on plans in 50 ms slices
- Types the dimension cannot form answer at once without planning, naming the setting that turns them off
- channelType reads the tier name (stream, river, major or major_river) and falls back to rank, so one-tier packs match stream
- HydrologyRuntime adds unavailable(type) and passes FEATURE_SEARCH_TIMEOUT (30 s) and a running check to the search
- nearestRiver returns a RiverSearch outcome, reports disabled and timed-out searches, and keeps recorded water on timeout
- startRiverSearch keeps one search per player; a new search cancels the previous one without a message
- Bukkit and modded find river run through the shared per-player search
- Tier name description and schema digest follow the new tier naming
- HydrologyFeatureSearchTest plus new query, Bukkit and modded cases cover the bounds
This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-01 21:27:50 -05:00
1 parent 75d28d16b2
commit 474b1e873a
12 files changed
+826 -167

No files matched your search

@@ -70,6 +70,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CancellationException;
@Director(name = "find", origin = DirectorOrigin.PLAYER, description = "Iris Find commands", descriptionKey = "iris.director.commandfind.director.iris_find_commands", aliases = "goto")
public class CommandFind implements DirectorExecutor {
@@ -218,41 +219,49 @@ public class CommandFind implements DirectorExecutor {
commandSender.sendMessage(C.RED + error.getMessage());
return;
}
String label = featureType.key().replace('_', ' ');
Location origin = target.getLocation();
World originWorld = origin.getWorld();
int maximumDistance = GenerationSemanticQueries.RIVER_SEARCH_DISTANCE;
commandSender.sendMessage(C.GRAY + GenerationSemanticQueries.riverSearchMessage(featureType, maximumDistance));
J.a(() -> {
try {
GenerationSemanticQueries.RiverResult feature = GenerationSemanticQueries.nearestRiver(
activeEngine,
featureType,
origin.getBlockX(),
origin.getBlockZ(),
maximumDistance
).orElse(null);
if (feature == null) {
sendStructureMessage(target, commandSender,
C.YELLOW + GenerationSemanticQueries.riverNotFoundMessage(featureType, maximumDistance));
return;
}
if (!teleport) {
sendStructureMessage(target, commandSender,
C.GREEN + "Found " + label + " at " + feature.x() + ", " + feature.y() + ", " + feature.z() + ".");
return;
}
Location destination = new Location(
originWorld, feature.x(), feature.y(), feature.z());
prepareStructureTeleport(
target, originWorld, commandSender, label, destination, true);
} catch (Throwable error) {
sendStructureMessage(target, commandSender,
C.RED + "Could not search for " + label + ": " + error.getClass().getSimpleName()
+ (error.getMessage() == null ? "" : " - " + error.getMessage()));
Iris.reportError("Could not locate hydrology feature '" + featureType.key() + "'.", error);
RiverRequest request = new RiverRequest(target, origin.getWorld(), commandSender, featureType, teleport);
commandSender.sendMessage(C.GRAY + GenerationSemanticQueries.riverSearchMessage(featureType,
GenerationSemanticQueries.RIVER_SEARCH_DISTANCE));
GenerationSemanticQueries.startRiverSearch(target.getUniqueId(), J::a, activeEngine, featureType, origin.getBlockX(),
origin.getBlockZ())
.whenComplete((search, failure) -> finishRiverSearch(request, search, failure));
}
private void finishRiverSearch(RiverRequest request, GenerationSemanticQueries.RiverSearch search, Throwable failure) {
if (failure instanceof CancellationException) {
return;
}
if (failure != null) {
reportRiverFailure(request, failure);
return;
}
try {
switch (search) {
case GenerationSemanticQueries.RiverSearch.Missing missing ->
sendStructureMessage(request.target(), request.sender(), C.YELLOW + missing.message());
case GenerationSemanticQueries.RiverSearch.Found found -> arriveAtRiver(request, found.feature());
}
});
} catch (RuntimeException error) {
reportRiverFailure(request, error);
}
}
private void arriveAtRiver(RiverRequest request, GenerationSemanticQueries.RiverResult feature) {
if (!request.teleport()) {
sendStructureMessage(request.target(), request.sender(),
C.GREEN + "Found " + request.label() + " at " + feature.x() + ", " + feature.y() + ", " + feature.z() + ".");
return;
}
Location destination = new Location(request.world(), feature.x(), feature.y(), feature.z());
prepareStructureTeleport(request.target(), request.world(), request.sender(), request.label(), destination, true);
}
private void reportRiverFailure(RiverRequest request, Throwable failure) {
sendStructureMessage(request.target(), request.sender(),
C.RED + "Could not search for " + request.label() + ": " + failure.getClass().getSimpleName()
+ (failure.getMessage() == null ? "" : " - " + failure.getMessage()));
Iris.reportError("Could not locate hydrology feature '" + request.type().key() + "'.", failure);
}
@Director(description = "Find a structure (a vanilla key like minecraft:village_plains or minecraft:stronghold, or an imported iris structure key)", descriptionKey = "iris.director.commandfind.director.find_structure_vanilla_key_like_minecraft_village_plains_minecraft_stronghold_imported_iris", sync = true)
@@ -919,6 +928,12 @@ public class CommandFind implements DirectorExecutor {
int configuredUnregistered, int editableUnplaced, int managedUnregistered) {
}
private record RiverRequest(Player target, World world, VolmitSender sender, HydrologyFeatureType type, boolean teleport) {
private String label() {
return type.key().replace('_', ' ');
}
}
private record ManagedDatapackStructure(String key, Set<String> sourceIds) {
private ManagedDatapackStructure(String key) {
this(key, new LinkedHashSet<>());
@@ -1,6 +1,7 @@
package art.arcane.iris.command;
import art.arcane.iris.Iris;
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureType;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.generation.runtime.IrisComplex;
@@ -19,6 +20,7 @@ import org.mockito.MockedStatic;
import java.util.Optional;
import java.util.OptionalLong;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicReference;
@@ -126,11 +128,12 @@ public class CommandFindHydrologyTest {
for (HydrologyFeatureType type : HydrologyFeatureType.values()) {
try (Fixture fixture = new Fixture()) {
fixture.command.river(type.key(), false);
fixture.queries.verify(() -> GenerationSemanticQueries.nearestRiver(any(), any(), anyInt(), anyInt(), anyInt()), never());
fixture.queries.verify(() -> GenerationSemanticQueries.nearestRiver(any(), any(), anyInt(), anyInt(), anyInt(), any()),
never());
fixture.search.get().run();
fixture.queries.verify(() -> GenerationSemanticQueries.nearestRiver(fixture.engine, type, 0, 0,
GenerationSemanticQueries.RIVER_SEARCH_DISTANCE));
fixture.queries.verify(() -> GenerationSemanticQueries.nearestRiver(eq(fixture.engine), eq(type), eq(0), eq(0),
eq(GenerationSemanticQueries.RIVER_SEARCH_DISTANCE), any()));
verify(fixture.sender).sendMessage(contains("Found " + type.key().replace('_', ' ') + " at 32, 63, 32."));
}
}
@@ -146,11 +149,40 @@ public class CommandFindHydrologyTest {
}
}
@Test
public void aNewSearchSilentlyReplacesThePlayersRunningSearch() {
try (Fixture fixture = new Fixture()) {
fixture.command.river("pond", false);
Runnable replaced = fixture.search.get();
fixture.command.river("river", false);
replaced.run();
fixture.queries.verify(() -> GenerationSemanticQueries.nearestRiver(any(), eq(HydrologyFeatureType.POND), anyInt(), anyInt(),
anyInt(), any()), never());
fixture.search.get().run();
verify(fixture.sender).sendMessage(contains("Found river at 32, 63, 32."));
verify(fixture.sender, never()).sendMessage(contains("Found pond"));
verify(fixture.sender, never()).sendMessage(contains("Could not search"));
}
}
@Test
public void disabledTypeIsReportedWithItsReason() throws Exception {
try (Fixture fixture = new Fixture()) {
fixture.searchForReal();
when(fixture.runtime.unavailable(HydrologyFeatureType.LAKE)).thenReturn(Optional.of("hydrology.lakes is disabled"));
fixture.command.river("lake", true);
fixture.search.get().run();
verify(fixture.sender).sendMessage(contains("No lake forms in this dimension: hydrology.lakes is disabled."));
verify(fixture.runtime, never()).nearestFeature(anyInt(), anyInt(), any(), anyInt(), any(), any());
}
}
@Test
public void missingCavePoolIsReportedAsNotFoundInGeneratedChunks() {
try (Fixture fixture = new Fixture()) {
fixture.queries.when(() -> GenerationSemanticQueries.nearestRiver(eq(fixture.engine), any(), eq(0), eq(0), anyInt()))
.thenReturn(Optional.empty());
fixture.searchForReal();
fixture.command.river("cave_pool", true);
fixture.search.get().run();
@@ -162,8 +194,7 @@ public class CommandFindHydrologyTest {
@Test
public void missingFeatureIsReportedAsNotFound() {
try (Fixture fixture = new Fixture()) {
fixture.queries.when(() -> GenerationSemanticQueries.nearestRiver(eq(fixture.engine), any(), eq(0), eq(0), anyInt()))
.thenReturn(Optional.empty());
fixture.searchForReal();
fixture.command.river("sea_inlet", true);
fixture.search.get().run();
@@ -176,7 +207,7 @@ public class CommandFindHydrologyTest {
public void plannerFailureIsReportedAsAnErrorNotAsNotFound() {
try (Fixture fixture = new Fixture()) {
IllegalStateException failure = new IllegalStateException("window planner exploded");
fixture.queries.when(() -> GenerationSemanticQueries.nearestRiver(eq(fixture.engine), any(), eq(0), eq(0), anyInt()))
fixture.queries.when(() -> GenerationSemanticQueries.nearestRiver(eq(fixture.engine), any(), eq(0), eq(0), anyInt(), any()))
.thenThrow(failure);
fixture.command.river("lake", true);
fixture.search.get().run();
@@ -191,6 +222,7 @@ public class CommandFindHydrologyTest {
private final CommandFind command = mock(CommandFind.class, CALLS_REAL_METHODS);
private final Engine engine = mock(Engine.class);
private final IrisComplex complex = mock(IrisComplex.class);
private final HydrologyRuntime runtime = mock(HydrologyRuntime.class);
private final Player player = mock(Player.class);
private final World world = mock(World.class);
private final VolmitSender sender = mock(VolmitSender.class);
@@ -208,6 +240,8 @@ public class CommandFindHydrologyTest {
doReturn(player).when(command).player();
doReturn(sender).when(command).sender();
when(engine.getComplex()).thenReturn(complex);
when(complex.getHydrologyRuntime()).thenReturn(runtime);
when(player.getUniqueId()).thenReturn(UUID.randomUUID());
when(player.getWorld()).thenReturn(world);
when(player.getLocation()).thenReturn(new Location(world, 0, 70, 0));
when(player.isOnline()).thenReturn(true);
@@ -227,12 +261,17 @@ public class CommandFindHydrologyTest {
});
platform.when(() -> BukkitPlatform.chunkAtAsync(any(World.class), anyInt(), anyInt(), eq(true))).thenReturn(chunk);
platform.when(() -> BukkitPlatform.teleportAsync(eq(player), any(Location.class))).thenReturn(teleport);
queries.when(() -> GenerationSemanticQueries.nearestRiver(eq(engine), any(), eq(0), eq(0), anyInt()))
.thenReturn(Optional.of(new GenerationSemanticQueries.RiverResult(
queries.when(() -> GenerationSemanticQueries.nearestRiver(eq(engine), any(), eq(0), eq(0), anyInt(), any()))
.thenReturn(new GenerationSemanticQueries.RiverSearch.Found(new GenerationSemanticQueries.RiverResult(
GenerationSemanticQueries.RiverSource.ACTIVE_PREDICTION,
HydrologyFeatureType.RIVER, 1L, 32, 63, 32, OptionalLong.empty())));
}
private void searchForReal() {
queries.when(() -> GenerationSemanticQueries.nearestRiver(eq(engine), any(), eq(0), eq(0), anyInt(), any()))
.thenCallRealMethod();
}
@Override
public void close() {
logging.close();
@@ -149,39 +149,32 @@ final class ModdedLocateCommands {
IrisModdedCommands.fail(source, error.getMessage());
return 0;
}
String label = featureType.key().replace('_', ' ');
int originX = player.blockX();
int originZ = player.blockZ();
int maximumDistance = GenerationSemanticQueries.RIVER_SEARCH_DISTANCE;
NativeModdedServer server = source.server();
IrisModdedCommands.ok(source, GenerationSemanticQueries.riverSearchMessage(featureType, maximumDistance));
MultiBurst.burst.completeValueAsync(() -> GenerationSemanticQueries.nearestRiver(
engine, featureType, originX, originZ, maximumDistance).orElse(null))
.whenComplete((GenerationSemanticQueries.RiverResult feature, Throwable error) -> server.execute(() -> {
if (error != null) {
Throwable cause = error instanceof CompletionException && error.getCause() != null ? error.getCause() : error;
ModdedIrisLog.error("Hydrology locate failed for {}", featureType.key(), cause);
IrisModdedCommands.fail(source, "Could not search for " + label + ": " + cause.getClass().getSimpleName()
+ (cause.getMessage() == null ? "" : " - " + cause.getMessage()));
return;
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));
}
if (feature == null) {
IrisModdedCommands.fail(source, GenerationSemanticQueries.riverNotFoundMessage(featureType, maximumDistance));
return;
}
teleportToStructure(
source,
level,
player,
feature.x(),
feature.y() + 2,
feature.z(),
label
);
}));
});
return 1;
}
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()));
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());
}
}
static int gotoStructure(NativeCommandSource source, String keyRaw) {
NativeWorld level = source.world();
Engine engine = IrisModdedCommands.engineFor(level);
@@ -706,6 +699,12 @@ final class ModdedLocateCommands {
record CaveDestination(SubterrainPosition target, Optional<SavedBiomeRuntime.ReadSession> read) {
}
private record RiverRequest(NativeCommandSource source, NativeWorld level, NativeProtocolPlayer player, HydrologyFeatureType type) {
private String label() {
return type.key().replace('_', ' ');
}
}
private record CaveLocateRequest(NativeCommandSource source, NativeWorld level, Engine engine,
NativeProtocolPlayer player, String label, NativeModdedServer server,
UUID playerId, CompletableFuture<Position2> search, BiomeLocator locator, Position2 at) {
@@ -19,6 +19,7 @@ import org.mockito.MockedConstruction;
import org.mockito.MockedStatic;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
@@ -41,7 +42,7 @@ public class ModdedLocateRiverTest {
private static final int DISTANCE = GenerationSemanticQueries.RIVER_SEARCH_DISTANCE;
@Test
public void unknownTypeFailsBeforeSearching() {
public void unknownTypeFailsBeforeSearching() throws Exception {
Fixture fixture = new Fixture();
try (MockedStatic<IrisModdedCommands> commands = fixture.commands()) {
assertEquals(0, ModdedLocateCommands.gotoRiver(fixture.source, "ocean_trench"));
@@ -49,14 +50,14 @@ public class ModdedLocateRiverTest {
commands.verify(() -> IrisModdedCommands.fail(eq(fixture.source), anyString()));
commands.verify(() -> IrisModdedCommands.ok(eq(fixture.source), anyString()), never());
verify(fixture.server, never()).execute(any());
verify(fixture.runtime, never()).nearestFeature(anyInt(), anyInt(), any(), anyInt(), any());
verify(fixture.runtime, never()).nearestFeature(anyInt(), anyInt(), any(), anyInt(), any(), any());
}
}
@Test
public void missingFeatureReportsNotFound() throws Exception {
Fixture fixture = new Fixture();
when(fixture.runtime.nearestFeature(anyInt(), anyInt(), any(), anyInt(), any())).thenReturn(Optional.empty());
when(fixture.runtime.nearestFeature(anyInt(), anyInt(), any(), anyInt(), any(), any())).thenReturn(Optional.empty());
try (MockedStatic<IrisModdedCommands> commands = fixture.commands()) {
assertEquals(1, ModdedLocateCommands.gotoRiver(fixture.source, "river"));
fixture.finishOnServerThread();
@@ -66,10 +67,24 @@ public class ModdedLocateRiverTest {
}
}
@Test
public void disabledTypeReportsItsReasonWithoutSearching() throws Exception {
Fixture fixture = new Fixture();
when(fixture.runtime.unavailable(HydrologyFeatureType.DAM)).thenReturn(Optional.of("hydrology.ponds.dams is disabled"));
try (MockedStatic<IrisModdedCommands> commands = fixture.commands()) {
assertEquals(1, ModdedLocateCommands.gotoRiver(fixture.source, "dam"));
fixture.finishOnServerThread();
commands.verify(() -> IrisModdedCommands.fail(fixture.source, "No dam forms in this dimension: hydrology.ponds.dams is disabled."));
verify(fixture.runtime, never()).nearestFeature(anyInt(), anyInt(), any(), anyInt(), any(), any());
verify(fixture.player, never()).teleport(any(), anyDouble(), anyDouble(), anyDouble());
}
}
@Test
public void plannerFailureIsReportedAsAnErrorNotAsNotFound() throws Exception {
Fixture fixture = new Fixture();
when(fixture.runtime.nearestFeature(anyInt(), anyInt(), any(), anyInt(), any()))
when(fixture.runtime.nearestFeature(anyInt(), anyInt(), any(), anyInt(), any(), any()))
.thenThrow(new IllegalStateException("window planner exploded"));
try (MockedStatic<IrisModdedCommands> commands = fixture.commands()) {
assertEquals(1, ModdedLocateCommands.gotoRiver(fixture.source, "major_river"));
@@ -86,7 +101,7 @@ public class ModdedLocateRiverTest {
@Test
public void foundFeatureTeleportsAboveItFromThePlayersPosition() throws Exception {
Fixture fixture = new Fixture();
when(fixture.runtime.nearestFeature(anyInt(), anyInt(), any(), anyInt(), any()))
when(fixture.runtime.nearestFeature(anyInt(), anyInt(), any(), anyInt(), any(), any()))
.thenReturn(Optional.of(new HydrologyFeatureRef(9L, HydrologyFeatureType.WATERFALL, 400, 130, -250)));
when(fixture.player.teleport(fixture.world, 400.5D, 68D, -249.5D)).thenReturn(true);
try (MockedStatic<IrisModdedCommands> commands = fixture.commands();
@@ -95,7 +110,7 @@ public class ModdedLocateRiverTest {
fixture.finishOnServerThread();
ArgumentCaptor<HydrologyFeatureQuery> query = ArgumentCaptor.forClass(HydrologyFeatureQuery.class);
verify(fixture.runtime).nearestFeature(eq(120), eq(-75), query.capture(), eq(DISTANCE), any());
verify(fixture.runtime).nearestFeature(eq(120), eq(-75), query.capture(), eq(DISTANCE), any(), any());
assertEquals(HydrologyFeatureQuery.of(HydrologyFeatureType.WATERFALL), query.getValue());
verify(queries.constructed().getFirst()).loadChunk(400 >> 4, -250 >> 4);
verify(fixture.player).teleport(fixture.world, 400.5D, 68D, -249.5D);
@@ -119,6 +134,7 @@ public class ModdedLocateRiverTest {
when(source.player()).thenReturn(player);
when(source.world()).thenReturn(world);
when(source.server()).thenReturn(server);
when(player.id()).thenReturn(UUID.randomUUID());
when(player.blockX()).thenReturn(120);
when(player.blockZ()).thenReturn(-75);
when(player.connected()).thenReturn(true);