mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Added modded worldgen catalog
- Captured the worldgen catalog after server start, scanning registries on the server thread and encoding and writing on a worker into config/irisworldgen/catalog/worldgen-catalog.json - Added WorldgenCatalogFingerprint over namespace versions and registry keys - Added /iris catalog [namespace|refresh] and /iris ingest mods <source> <target> with keyed dimension, namespaces and replace options - Added catalog messages and help entries for every shipped locale - Added tests for catalog assembly, namespace summaries, ingest arguments, the registry scan and command registration
This commit is contained in:
1 parent
8afb445b1d
commit
f6f381f6e4
36 files changed
+2150
No files matched your search
+7
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeModMetadata;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeModdedLoader;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeWorld;
|
||||
|
||||
@@ -20,6 +21,7 @@ import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -45,6 +47,11 @@ public class ModdedPlatformPathsTest {
|
||||
return "0.0.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NativeModMetadata> mods() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeModdedServer currentServer() {
|
||||
return null;
|
||||
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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.catalog;
|
||||
|
||||
import art.arcane.iris.pack.ingest.catalog.CatalogBiome;
|
||||
import art.arcane.iris.pack.ingest.catalog.CatalogLevelStem;
|
||||
import art.arcane.iris.pack.ingest.catalog.CatalogNamespace;
|
||||
import art.arcane.iris.pack.ingest.catalog.CatalogPlacedFeature;
|
||||
import art.arcane.iris.pack.ingest.catalog.WorldgenCatalog;
|
||||
import art.arcane.iris.pack.ingest.catalog.WorldgenCatalogFingerprint;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeModMetadata;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeWorldgenSnapshot;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeWorldgenSnapshot.EncodeFailures;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeWorldgenSnapshot.WorldgenBiome;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeWorldgenSnapshot.WorldgenDimensionType;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeWorldgenSnapshot.WorldgenLevelStem;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeWorldgenSnapshot.WorldgenPlacedFeature;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeWorldgenSnapshot.WorldgenSpawn;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeWorldgenSnapshot.WorldgenStructure;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
public class WorldgenCatalogAssemblerTest {
|
||||
private static final CatalogCaptureContext CONTEXT = new CatalogCaptureContext("26.3", "neoforge", 1234L, List.of(
|
||||
new NativeModMetadata("minecraft", "Minecraft", "26.3"),
|
||||
new NativeModMetadata("examplemod", "Example Mod", "1.0.0"),
|
||||
new NativeModMetadata("quietmod", "Quiet Mod", "2.0.0")));
|
||||
|
||||
@Test
|
||||
public void namespacesCombineLoaderModsWithRegistryKeyNamespaces() {
|
||||
WorldgenCatalog catalog = WorldgenCatalogAssembler.assemble(snapshot(), CONTEXT);
|
||||
|
||||
assertEquals(List.of(
|
||||
new CatalogNamespace("datapack", "datapack", ""),
|
||||
new CatalogNamespace("examplemod", "Example Mod", "1.0.0"),
|
||||
new CatalogNamespace("minecraft", "Minecraft", "26.3"),
|
||||
new CatalogNamespace("quietmod", "Quiet Mod", "2.0.0")), catalog.namespaces());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void minecraftNamespaceFallsBackToTheRunningVersion() {
|
||||
CatalogCaptureContext context = new CatalogCaptureContext("26.3", "forge", 1L, List.of());
|
||||
|
||||
WorldgenCatalog catalog = WorldgenCatalogAssembler.assemble(snapshot(), context);
|
||||
|
||||
assertEquals(new CatalogNamespace("minecraft", "Minecraft", "26.3"), catalog.namespaces().get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recordsAreCopiedWithTheirJson() {
|
||||
NativeWorldgenSnapshot snapshot = snapshot();
|
||||
|
||||
WorldgenCatalog catalog = WorldgenCatalogAssembler.assemble(snapshot, CONTEXT);
|
||||
|
||||
assertEquals(WorldgenCatalog.FORMAT, catalog.format());
|
||||
assertEquals("26.3", catalog.minecraftVersion());
|
||||
assertEquals("neoforge", catalog.platform());
|
||||
assertEquals(1234L, catalog.capturedAtEpochMillis());
|
||||
CatalogBiome glade = catalog.biomes().getFirst();
|
||||
assertEquals("examplemod:glade", glade.key());
|
||||
assertEquals(0.7F, glade.temperature(), 0F);
|
||||
assertEquals(0.4F, glade.downfall(), 0F);
|
||||
assertEquals(List.of(List.of(), List.of("examplemod:ore_glimmer")), glade.featureSteps());
|
||||
assertEquals("creature", glade.spawns().getFirst().category());
|
||||
assertSame(snapshot.biomes().getFirst().definition(), glade.definition());
|
||||
CatalogPlacedFeature ore = catalog.placedFeatures().getFirst();
|
||||
assertEquals("minecraft:ore", ore.featureType());
|
||||
assertSame(snapshot.placedFeatures().getFirst().config(), ore.config());
|
||||
CatalogLevelStem stem = catalog.levelStems().getFirst();
|
||||
assertEquals("minecraft:multi_noise", stem.biomeSourceType());
|
||||
assertEquals("examplemod:towers", catalog.structures().getFirst().structureSets().getFirst());
|
||||
assertEquals(384, catalog.dimensionTypes().getFirst().height());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fingerprintCoversNamespacesAndEveryRegistryKey() {
|
||||
WorldgenCatalog catalog = WorldgenCatalogAssembler.assemble(snapshot(), CONTEXT);
|
||||
|
||||
String expected = WorldgenCatalogFingerprint.of(catalog.namespaces(), Map.of(
|
||||
"biome", List.of("datapack:dunes", "examplemod:glade"),
|
||||
"placed_feature", List.of("examplemod:ore_glimmer"),
|
||||
"structure", List.of("examplemod:tower"),
|
||||
"dimension_type", List.of("minecraft:overworld"),
|
||||
"level_stem", List.of("minecraft:overworld")));
|
||||
assertEquals(expected, catalog.contentFingerprint());
|
||||
}
|
||||
|
||||
static NativeWorldgenSnapshot snapshot() {
|
||||
JsonObject definition = new JsonObject();
|
||||
definition.add("downfall", new JsonPrimitive(0.4F));
|
||||
JsonObject config = new JsonObject();
|
||||
config.add("type", new JsonPrimitive("minecraft:ore"));
|
||||
return new NativeWorldgenSnapshot(
|
||||
List.of(new WorldgenBiome("examplemod:glade", 0.7F, 0.4F, true, List.of("minecraft:is_overworld"),
|
||||
List.of(List.of(), List.of("examplemod:ore_glimmer")),
|
||||
List.of(new WorldgenSpawn("creature", "minecraft:sheep", 12, 2, 4)), definition),
|
||||
new WorldgenBiome("datapack:dunes", 2.0F, 0F, false, List.of(), List.of(), List.of(), null)),
|
||||
List.of(new WorldgenPlacedFeature("examplemod:ore_glimmer", "examplemod:ore_glimmer", "minecraft:ore", config, null)),
|
||||
List.of(new WorldgenStructure("examplemod:tower", "minecraft:jigsaw", "surface_structures", "beard_thin",
|
||||
"examplemod:has_tower", List.of("examplemod:glade"), List.of("examplemod:towers"))),
|
||||
List.of(new WorldgenDimensionType("minecraft:overworld", -64, 384, 384, null)),
|
||||
List.of(new WorldgenLevelStem("minecraft:overworld", "minecraft:overworld", "minecraft:noise",
|
||||
"minecraft:multi_noise", null)),
|
||||
new EncodeFailures(0, List.of(), null));
|
||||
}
|
||||
}
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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.catalog;
|
||||
|
||||
import art.arcane.iris.modded.catalog.WorldgenCatalogSummary.NamespaceSummary;
|
||||
import art.arcane.iris.modded.catalog.WorldgenCatalogSummary.TypeCount;
|
||||
import art.arcane.iris.pack.ingest.catalog.CatalogBiome;
|
||||
import art.arcane.iris.pack.ingest.catalog.CatalogDimensionType;
|
||||
import art.arcane.iris.pack.ingest.catalog.CatalogLevelStem;
|
||||
import art.arcane.iris.pack.ingest.catalog.CatalogNamespace;
|
||||
import art.arcane.iris.pack.ingest.catalog.CatalogPlacedFeature;
|
||||
import art.arcane.iris.pack.ingest.catalog.CatalogStructure;
|
||||
import art.arcane.iris.pack.ingest.catalog.WorldgenCatalog;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class WorldgenCatalogSummaryTest {
|
||||
@Test
|
||||
public void summariesCountEveryRegistryPerNamespace() {
|
||||
List<NamespaceSummary> summaries = WorldgenCatalogSummary.namespaces(catalog());
|
||||
|
||||
assertEquals(List.of("examplemod", "minecraft", "quietmod"),
|
||||
summaries.stream().map((NamespaceSummary summary) -> summary.namespace().namespace()).toList());
|
||||
NamespaceSummary example = summaries.getFirst();
|
||||
assertEquals(List.of("examplemod:glade", "examplemod:marsh"), example.biomes());
|
||||
assertEquals(6, example.placedFeatures().size());
|
||||
assertEquals(List.of("examplemod:tower"), example.structures());
|
||||
assertEquals(List.of("examplemod:sky"), example.dimensionTypes());
|
||||
assertEquals(List.of("examplemod:sky"), example.levelStems());
|
||||
assertTrue(example.hasContent());
|
||||
assertFalse(summaries.get(2).hasContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void featureTypesAreRankedByCountThenName() {
|
||||
NamespaceSummary example = WorldgenCatalogSummary.namespace(catalog(), "examplemod").orElseThrow();
|
||||
|
||||
assertEquals(List.of(new TypeCount("minecraft:ore", 3), new TypeCount("minecraft:random_patch", 2),
|
||||
new TypeCount("examplemod:big_tree", 1)), example.featureTypes());
|
||||
assertEquals("ore 3, random_patch 2 (+1 more)", WorldgenCatalogSummary.featureTypes(example.featureTypes(), 2));
|
||||
assertEquals("ore 3, random_patch 2, examplemod:big_tree 1",
|
||||
WorldgenCatalogSummary.featureTypes(example.featureTypes(), 5));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unknownNamespaceHasNoSummary() {
|
||||
Optional<NamespaceSummary> missing = WorldgenCatalogSummary.namespace(catalog(), "missingmod");
|
||||
|
||||
assertTrue(missing.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void keyNamespacesWithoutModMetadataStillSummarize() {
|
||||
WorldgenCatalog catalog = new WorldgenCatalog(WorldgenCatalog.FORMAT, "26.3", "fabric", 1L, "x",
|
||||
List.of(), List.of(biome("datapack:dunes")), List.of(), List.of(), List.of(), List.of());
|
||||
|
||||
NamespaceSummary summary = WorldgenCatalogSummary.namespace(catalog, "datapack").orElseThrow();
|
||||
|
||||
assertEquals(new CatalogNamespace("datapack", "datapack", ""), summary.namespace());
|
||||
assertEquals(List.of("datapack:dunes"), summary.biomes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void limitedListsShortenOwnKeysAndCountTheRest() {
|
||||
assertEquals("glade, marsh (+1 more)",
|
||||
WorldgenCatalogSummary.limited(List.of("examplemod:glade", "examplemod:marsh", "examplemod:moor"), "examplemod", 2));
|
||||
assertEquals("glade, minecraft:plains",
|
||||
WorldgenCatalogSummary.limited(List.of("examplemod:glade", "minecraft:plains"), "examplemod", 5));
|
||||
assertEquals("", WorldgenCatalogSummary.limited(List.of(), "examplemod", 5));
|
||||
}
|
||||
|
||||
private static WorldgenCatalog catalog() {
|
||||
return new WorldgenCatalog(WorldgenCatalog.FORMAT, "26.3", "neoforge", 1L, "x",
|
||||
List.of(new CatalogNamespace("examplemod", "Example Mod", "1.0.0"),
|
||||
new CatalogNamespace("minecraft", "Minecraft", "26.3"),
|
||||
new CatalogNamespace("quietmod", "Quiet Mod", "2.0.0")),
|
||||
List.of(biome("examplemod:marsh"), biome("examplemod:glade"), biome("minecraft:plains")),
|
||||
List.of(feature("examplemod:ore_a", "minecraft:ore"), feature("examplemod:ore_b", "minecraft:ore"),
|
||||
feature("examplemod:ore_c", "minecraft:ore"), feature("examplemod:patch_a", "minecraft:random_patch"),
|
||||
feature("examplemod:patch_b", "minecraft:random_patch"), feature("examplemod:tree", "examplemod:big_tree"),
|
||||
feature("minecraft:ore_iron", "minecraft:ore")),
|
||||
List.of(new CatalogStructure("examplemod:tower", "minecraft:jigsaw", "surface_structures", "none", "",
|
||||
List.of(), List.of())),
|
||||
List.of(new CatalogDimensionType("examplemod:sky", 0, 256, 256, null)),
|
||||
List.of(new CatalogLevelStem("examplemod:sky", "examplemod:sky", "minecraft:noise", "minecraft:fixed", null)));
|
||||
}
|
||||
|
||||
private static CatalogBiome biome(String key) {
|
||||
return new CatalogBiome(key, 0.5F, 0.5F, true, List.of(), List.of(), List.of(), null);
|
||||
}
|
||||
|
||||
private static CatalogPlacedFeature feature(String key, String type) {
|
||||
return new CatalogPlacedFeature(key, key, type, null, null);
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.command;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ModIngestArgumentsTest {
|
||||
@Test
|
||||
public void requiredPacksBindPositionallyAndOptionalsDefault() {
|
||||
ModIngestArguments arguments = ModIngestArguments.parse("overworld modded_overworld");
|
||||
|
||||
assertEquals("overworld", arguments.sourcePack());
|
||||
assertEquals("modded_overworld", arguments.targetPack());
|
||||
assertEquals("overworld", arguments.dimension());
|
||||
assertEquals(Set.of(), arguments.namespaces());
|
||||
assertFalse(arguments.replace());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void keyedOptionalsAreParsedInAnyOrder() {
|
||||
ModIngestArguments arguments = ModIngestArguments.parse(
|
||||
" overworld modded replace=true namespaces=biomesoplenty,terralith dimension=overworld_alt ");
|
||||
|
||||
assertEquals("overworld_alt", arguments.dimension());
|
||||
assertEquals(Set.of("biomesoplenty", "terralith"), arguments.namespaces());
|
||||
assertTrue(arguments.replace());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingTargetIsRejected() {
|
||||
IllegalArgumentException failure = assertThrows(IllegalArgumentException.class,
|
||||
() -> ModIngestArguments.parse("overworld"));
|
||||
|
||||
assertEquals("missing target pack", failure.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void strayPositionalsAndUnknownKeysAreRejected() {
|
||||
assertEquals("unexpected argument 'extra'", reason("overworld modded extra"));
|
||||
assertEquals("unknown option 'seed'", reason("overworld modded seed=1"));
|
||||
assertEquals("option 'replace' given twice", reason("overworld modded replace=true replace=false"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valuesAreValidated() {
|
||||
assertEquals("replace must be true or false", reason("overworld modded replace=yes"));
|
||||
assertEquals("invalid pack name '../evil'", reason("../evil modded"));
|
||||
assertEquals("invalid dimension key 'a..b'", reason("overworld modded dimension=a..b"));
|
||||
assertEquals("invalid namespace 'Bad'", reason("overworld modded namespaces=ok,Bad"));
|
||||
assertEquals("namespaces must not be empty", reason("overworld modded namespaces=,"));
|
||||
assertEquals("source and target must be different packs", reason("overworld overworld"));
|
||||
}
|
||||
|
||||
private static String reason(String raw) {
|
||||
return assertThrows(IllegalArgumentException.class, () -> ModIngestArguments.parse(raw)).getMessage();
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.command;
|
||||
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeCommandRegistration;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.server.Bootstrap;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ModdedCatalogCommandsTest {
|
||||
@BeforeClass
|
||||
public static void bootstrap() {
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void catalogAndIngestCommandsAreRegistered() {
|
||||
CommandDispatcher<CommandSourceStack> dispatcher = new CommandDispatcher<>();
|
||||
IrisModdedCommands.register(new NativeCommandRegistration(dispatcher));
|
||||
|
||||
CommandNode<CommandSourceStack> iris = child(dispatcher.getRoot(), "iris");
|
||||
CommandNode<CommandSourceStack> catalog = child(iris, "catalog");
|
||||
assertNotNull(catalog.getCommand());
|
||||
assertNotNull(child(catalog, "refresh").getCommand());
|
||||
assertNotNull(child(catalog, "namespace").getCommand());
|
||||
CommandNode<CommandSourceStack> ingest = child(iris, "ingest");
|
||||
assertNotNull(ingest.getCommand());
|
||||
CommandNode<CommandSourceStack> mods = child(ingest, "mods");
|
||||
assertNotNull(child(mods, "arguments").getCommand());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void helpDocumentsCatalogAndIngest() {
|
||||
assertTrue(ModdedCommandHelp.documents("", "catalog"));
|
||||
assertTrue(ModdedCommandHelp.documents("", "ingest"));
|
||||
assertTrue(ModdedCommandHelp.documents("ingest", "mods"));
|
||||
List<String> lines = ModdedCommandHelp.consoleLines("ingest");
|
||||
assertTrue(lines.stream().anyMatch((String line) ->
|
||||
line.startsWith("/iris ingest mods <source> <target> [dimension=<key>] [namespaces=<a,b>] [replace=true] - ")));
|
||||
}
|
||||
|
||||
private static CommandNode<CommandSourceStack> child(CommandNode<CommandSourceStack> parent, String name) {
|
||||
CommandNode<CommandSourceStack> child = parent.getChild(name);
|
||||
assertNotNull(name, child);
|
||||
return child;
|
||||
}
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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.volmlib.nativelib.minecraft26_2.modded;
|
||||
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeWorldgenSnapshot.WorldgenBiome;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeWorldgenSnapshot.WorldgenPlacedFeature;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.MappedRegistry;
|
||||
import net.minecraft.core.RegistrationInfo;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.Bootstrap;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.levelgen.GenerationStep;
|
||||
import net.minecraft.world.level.levelgen.carver.WorldCarver;
|
||||
import net.minecraft.world.level.levelgen.feature.Feature;
|
||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureSet;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class NativeWorldgenScanTest {
|
||||
private static final String BIOME_JSON = "{\"has_precipitation\":true,\"temperature\":0.8,\"downfall\":0.4,"
|
||||
+ "\"effects\":{\"water_color\":\"#3f76e4\"},\"carvers\":[],"
|
||||
+ "\"features\":[[],[],[],[],[],[],[\"examplemod:ore_glimmer\"]]}";
|
||||
|
||||
@BeforeClass
|
||||
public static void bootstrap() {
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scanReadsLiveFeatureStepsAndEncodesDefinitions() {
|
||||
NativeWorldgenSnapshot snapshot = NativeWorldgenScan.scan(server(), loader()).encode();
|
||||
|
||||
WorldgenBiome biome = snapshot.biomes().getFirst();
|
||||
assertEquals("examplemod:glade", biome.key());
|
||||
assertEquals(0.8F, biome.temperature(), 0F);
|
||||
assertEquals(0.4F, biome.downfall(), 0.0001F);
|
||||
assertTrue(biome.hasPrecipitation());
|
||||
assertEquals(GenerationStep.Decoration.values().length, biome.featureSteps().size());
|
||||
assertEquals(List.of("examplemod:ore_glimmer"),
|
||||
biome.featureSteps().get(GenerationStep.Decoration.UNDERGROUND_ORES.ordinal()));
|
||||
assertNotNull(biome.definition());
|
||||
assertEquals(0.4F, biome.definition().getAsJsonObject().get("downfall").getAsFloat(), 0.0001F);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unencodableFeaturesStayInTheCatalogWithoutJson() {
|
||||
NativeWorldgenSnapshot snapshot = NativeWorldgenScan.scan(server(), loader()).encode();
|
||||
|
||||
WorldgenPlacedFeature feature = snapshot.placedFeatures().getFirst();
|
||||
assertEquals("examplemod:ore_glimmer", feature.key());
|
||||
assertEquals("", feature.feature());
|
||||
assertNull(feature.config());
|
||||
assertTrue(feature.placement().isJsonArray());
|
||||
assertEquals(1, snapshot.failures().count());
|
||||
assertTrue(snapshot.failures().samples().getFirst().startsWith("feature of examplemod:ore_glimmer"));
|
||||
assertTrue(snapshot.levelStems().isEmpty());
|
||||
}
|
||||
|
||||
private static NativeModdedServer server() {
|
||||
MappedRegistry<PlacedFeature> features = new MappedRegistry<>(Registries.PLACED_FEATURE, Lifecycle.stable());
|
||||
features.register(ResourceKey.create(Registries.PLACED_FEATURE, Identifier.parse("examplemod:ore_glimmer")),
|
||||
new PlacedFeature(Holder.direct(mock(Feature.class)), List.of()), RegistrationInfo.BUILT_IN);
|
||||
features.freeze();
|
||||
MappedRegistry<WorldCarver> carvers = new MappedRegistry<>(Registries.CARVER, Lifecycle.stable());
|
||||
carvers.freeze();
|
||||
MappedRegistry<Biome> biomes = new MappedRegistry<>(Registries.BIOME, Lifecycle.stable());
|
||||
MappedRegistry<Structure> structures = new MappedRegistry<>(Registries.STRUCTURE, Lifecycle.stable());
|
||||
structures.freeze();
|
||||
MappedRegistry<StructureSet> structureSets = new MappedRegistry<>(Registries.STRUCTURE_SET, Lifecycle.stable());
|
||||
structureSets.freeze();
|
||||
MappedRegistry<DimensionType> dimensionTypes = new MappedRegistry<>(Registries.DIMENSION_TYPE, Lifecycle.stable());
|
||||
dimensionTypes.freeze();
|
||||
RegistryAccess access = new RegistryAccess.ImmutableRegistryAccess(
|
||||
List.of(biomes, features, carvers, structures, structureSets, dimensionTypes));
|
||||
Biome biome = Biome.DIRECT_CODEC.parse(RegistryOps.create(JsonOps.INSTANCE, access),
|
||||
JsonParser.parseString(BIOME_JSON)).getOrThrow();
|
||||
biomes.register(ResourceKey.create(Registries.BIOME, Identifier.parse("examplemod:glade")), biome, RegistrationInfo.BUILT_IN);
|
||||
biomes.freeze();
|
||||
MinecraftServer server = mock(MinecraftServer.class);
|
||||
when(server.registryAccess()).thenReturn(access.freeze());
|
||||
return NativeModdedServer.fromHandle(server);
|
||||
}
|
||||
|
||||
private static NativeModdedLoader loader() {
|
||||
NativeModdedLoader loader = mock(NativeModdedLoader.class);
|
||||
when(loader.unmodifiedBiome(any())).thenAnswer(invocation -> invocation.getArgument(0));
|
||||
return loader;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user