Apply IrisApi's typed keys, grouped values and @Ref(kind)

Batch 6, findings 41 and 42.

- Bukkit items, attributes, ambient effects and entities read ResourceIds,
  ContentKeys and the grouped ItemDrop and EntitySpec; Iris-only entity
  knobs come from the IrisEntityExtras extension.
- Iris serves the host kinds EXPRESSIONS and IMAGE_MAPS; noise styles map
  their ids back to the exact pack keys of the snapshot.
- Studio completes @Ref(kind = ...) of host kinds through Iris's loaders
  and @IrisStructureRef with the structure-model keys.
- Markers, sapling species, upper dimensions and jigsaw start pools are ids.
- Modded attribute lookup strips the minecraft namespace before the legacy
  generic prefixes, now that keys arrive namespaced.
- Loot and entity pins retaken: printed the old way, the new values still
  hash to the old numbers (recorded in the tests).
This commit is contained in:
piexel committed 2026-10-24 06:06:59 +02:00
1 parent ca07b8ce0b
commit dc0d61ce63
39 files changed
+523 -320

No files matched your search

@@ -35,6 +35,7 @@ import art.arcane.iris.engine.spawn.SpawnModule;
import art.arcane.iris.engine.spawn.SpawnResources;
import art.arcane.iris.spi.PlatformWorld;
import com.volmit.item.ItemRegistry;
import com.volmit.resource.ContentKey;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -46,7 +47,7 @@ import java.util.OptionalInt;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -71,7 +72,7 @@ public class ContentServicesTest {
ModuleResourceFixture fixture = ModuleResourceFixture.serve(data);
ModuleResourceFixture.serveModules(data, new SpawnModule(), new LootModule());
ItemRegistry items = mock(ItemRegistry.class);
when(items.maxDurability(anyString())).thenReturn(OptionalInt.of(0));
when(items.maxDurability(any(ContentKey.class))).thenReturn(OptionalInt.of(0));
when(data.getPackResources().items()).thenReturn(items);
when(engine.getData()).thenReturn(data);
IrisWorld engineWorld = mock(IrisWorld.class);
@@ -103,8 +104,8 @@ public class ContentServicesTest {
assertTrue(guard.flags().baby());
assertTrue(guard.flags().glowing());
assertFalse(guard.isSpecial());
assertEquals("iron_helmet", guard.equipment().helmet().item());
assertEquals(List.of(new ContentItem.Enchantment("protection", 3)), guard.equipment().helmet().enchantments());
assertEquals("minecraft:iron_helmet", guard.equipment().helmet().item());
assertEquals(List.of(new ContentItem.Enchantment("minecraft:protection", 3)), guard.equipment().helmet().enchantments());
assertEquals(List.of("guard/drops"), guard.lootTables());
assertEquals(List.of(new ContentEntity.Command(List.of("say hi {x}"), 4, true, 20)), guard.commands());
assertTrue(ContentServices.entity(engine, "nobody").isEmpty());
@@ -125,7 +126,7 @@ public class ContentServicesTest {
List<ContentItem> items = ContentServices.tableItems(engine, 10, 64, -3, "guard/drops");
assertEquals(1, items.size());
assertEquals("bread", items.getFirst().item());
assertEquals("minecraft:bread", items.getFirst().item());
assertEquals(3, items.getFirst().amount());
assertEquals(items, ContentServices.tableItems(engine, 10, 64, -3, "guard/drops"));
assertTrue(ContentServices.tableItems(engine, 10, 64, -3, "missing").isEmpty());
@@ -119,7 +119,7 @@ public class BuiltInModulesJarServicesTest {
assertNotSame(BlockDropping.class, drops.getClass());
BlockDrops.Result result = drops.drops(world, new BlockDrops.Broken(AT, new BlockState("minecraft:stone")));
assertEquals(1, result.drops().size());
assertEquals("gravel", result.drops().getFirst().item());
assertEquals("minecraft:gravel", result.drops().getFirst().item().toString());
assertEquals(2, result.drops().getFirst().amount());
assertTrue(result.replacesVanillaDrops());
assertEquals(BlockDrops.Result.NONE, drops.drops(world, new BlockDrops.Broken(AT, new BlockState("minecraft:dirt"))));
@@ -160,12 +160,13 @@ public final class CarveTestWorld implements PackWorld {
IrisData pack = mock(IrisData.class);
ResourceLoader<IrisBlockData> blocks = mock(ResourceLoader.class);
when(pack.getBlockLoader()).thenReturn(blocks);
when(pack.getDataFolder()).thenReturn(new java.io.File(NAMESPACE));
return pack;
}
private final class Resources implements PackResources {
private final UUID snapshot = UUID.randomUUID();
private final NoiseFactory noise = new IrisNoiseFactory(data);
private final NoiseFactory noise = new IrisNoiseFactory(data, new IrisPackResources(data, java.util.List::of));
@Override
public ResourceId packId() {
@@ -27,7 +27,7 @@ import static org.mockito.Mockito.when;
/** IrisApi's blocks are the bound platform's, through their keys, and so are its traits, tags and face support. */
public class IrisBlockRegistryTest {
private final IrisBlockRegistry blocks = new IrisBlockRegistry(mock(art.arcane.iris.core.loader.IrisData.class));
private final IrisBlockRegistry blocks = new IrisBlockRegistry(mock(art.arcane.iris.core.loader.IrisData.class), mock(IrisPackResources.class));
private PlatformRegistries registries;
private PlatformBlockState stone;
private PlatformBlockState sand;
@@ -67,7 +67,7 @@ public class IrisValuesTest {
@Test
public void blockSpecsResolveThroughThePlatformWithTheirProperties() {
UsableBlockPlatform.bind();
IrisBlockRegistry blocks = new IrisBlockRegistry(packWithoutCustomBlocks());
IrisBlockRegistry blocks = blocksOf(packWithoutCustomBlocks());
assertEquals(BlockState.parse("minecraft:iron_ore"), blocks.resolve(BlockSpec.of("iron_ore")));
assertEquals(BlockState.parse("minecraft:oak_log[axis=y]"), blocks.resolve(BlockSpec.of("minecraft:oak_log").withProperty("axis", "y")));
@@ -84,7 +84,7 @@ public class IrisValuesTest {
bind(registries);
IrisData data = packWithoutCustomBlocks();
when(data.getBlockLoader().load("glowing_stone", false)).thenReturn(new IrisBlockData("minecraft:stone").setData(new KMap<String, Object>().qput("lit", true)));
IrisBlockRegistry blocks = new IrisBlockRegistry(data);
IrisBlockRegistry blocks = blocksOf(data);
assertEquals(BlockState.parse("minecraft:stone[lit=true]"), blocks.resolve(BlockSpec.of("glowing_stone")));
assertEquals(BlockState.parse("minecraft:cobblestone"), blocks.resolve(BlockSpec.of("mod:missing").withBackup(BlockSpec.of("cobblestone"))));
@@ -95,7 +95,7 @@ public class IrisValuesTest {
UsableBlockPlatform.bind();
TileData.TileFactory previous = TileData.bindPlatformFactory((state, properties) -> new TileData(state.key(), properties));
try {
IrisBlockRegistry blocks = new IrisBlockRegistry(packWithoutCustomBlocks());
IrisBlockRegistry blocks = blocksOf(packWithoutCustomBlocks());
BlockSpec spawner = BlockSpec.of("spawner").withTileData(Map.of("Delay", 20.0));
assertEquals(Optional.empty(), blocks.blockEntity(BlockSpec.of("stone")));
@@ -105,7 +105,7 @@ public class IrisValuesTest {
PlatformRegistries registries = mock(PlatformRegistries.class);
when(registries.block(anyString())).thenReturn(withEntity);
bind(registries);
BlockEntityData entity = new IrisBlockRegistry(packWithoutCustomBlocks()).blockEntity(BlockSpec.of("chest").withTileData(Map.of("Lock", "key")))
BlockEntityData entity = blocksOf(packWithoutCustomBlocks()).blockEntity(BlockSpec.of("chest").withTileData(Map.of("Lock", "key")))
.orElseThrow();
assertEquals(BlockEntities.TILE_FORMAT, entity.format());
} finally {
@@ -120,7 +120,7 @@ public class IrisValuesTest {
IrisData data = packWithoutCustomBlocks();
NoiseStyle style = new Gson().fromJson(json, NoiseStyle.class);
CNG iris = new Gson().fromJson(json, IrisGeneratorStyle.class).create(new RNG(1337), data);
NoiseSampler sampler = new IrisNoiseFactory(data).sampler(style, 1337);
NoiseSampler sampler = noiseOf(data).sampler(style, 1337);
for (double[] column : COLUMNS) {
assertEquals(iris.noise(column[0], column[1]), sampler.sample(column[0], column[1]), 0);
@@ -133,7 +133,7 @@ public class IrisValuesTest {
String json = "{\"style\": \"SIMPLEX\", \"zoom\": 4, \"exponent\": 1.5, \"fracture\": {\"style\": \"PERLIN\", \"zoom\": 2, \"multiplier\": 3}}";
IrisData data = packWithoutCustomBlocks();
CNG iris = new Gson().fromJson(json, IrisGeneratorStyle.class).create(new RNG(1337), data);
NoiseSampler sampler = new IrisNoiseFactory(data).sampler(new Gson().fromJson(json, NoiseStyle.class), 1337);
NoiseSampler sampler = noiseOf(data).sampler(new Gson().fromJson(json, NoiseStyle.class), 1337);
for (double[] column : COLUMNS) {
assertEquals(iris.noiseFastSigned2D(column[0], column[1]), sampler.signed(column[0], column[1]), 0);
@@ -148,7 +148,7 @@ public class IrisValuesTest {
IrisData data = packWithoutCustomBlocks();
double scale = 1.5D;
CNG baked = new Gson().fromJson(json, IrisGeneratorStyle.class).createNoCache(new RNG(4242), data).bake().scale(scale).bake();
NoiseSampler plain = new IrisNoiseFactory(data).sampler(new Gson().fromJson(json, NoiseStyle.class), 4242);
NoiseSampler plain = noiseOf(data).sampler(new Gson().fromJson(json, NoiseStyle.class), 4242);
NoiseSampler scaled = plain.scaled(scale);
for (int x = -30; x <= 30; x += 3) {
@@ -160,7 +160,7 @@ public class IrisValuesTest {
@Test
public void theIrisStyleIsTheSignatureNoiseOfTheSeedThatSetsTheThicknessOfBiomeLayers() {
IrisNoiseFactory factory = new IrisNoiseFactory(packWithoutCustomBlocks());
IrisNoiseFactory factory = noiseOf(packWithoutCustomBlocks());
long mismatches = 0;
for (long seed : new long[]{1, 7235, -3999281L, 1337L * 31, 987654321987L}) {
CNG signature = CNG.signature(new RNG(seed));
@@ -178,7 +178,7 @@ public class IrisValuesTest {
@Test
public void aStyleNameIrisDoesNotKnowIsFlat() {
IrisData data = packWithoutCustomBlocks();
IrisNoiseFactory noise = new IrisNoiseFactory(data);
IrisNoiseFactory noise = noiseOf(data);
NoiseSampler unknown = noise.sampler(NoiseStyle.of("NOT_A_STYLE"), 7);
NoiseSampler flat = noise.sampler(NoiseStyle.of(NoiseStyle.FLAT), 7);
@@ -194,7 +194,7 @@ public class IrisValuesTest {
+ "{\"block\": \"stone\"}, {\"block\": \"andesite\", \"weight\": 2}, {\"block\": \"granite\", \"weight\": 3}]}";
IrisData data = packWithoutCustomBlocks();
IrisMaterialPalette iris = new Gson().fromJson(json, IrisMaterialPalette.class);
PaletteSampler sampler = new IrisBlockRegistry(data).palette(new Gson().fromJson(json, PaletteSpec.class), 1337);
PaletteSampler sampler = blocksOf(data).palette(new Gson().fromJson(json, PaletteSpec.class), 1337);
assertTrue("the positions cover several blocks", picksLike(iris, sampler, data, 1337).size() > 1);
}
@@ -203,7 +203,7 @@ public class IrisValuesTest {
public void aPaletteWithoutOptionsIsOneStoneEverywhereLikeIris() {
UsableBlockPlatform.bind();
IrisData data = packWithoutCustomBlocks();
PaletteSampler sampler = new IrisBlockRegistry(data).palette(new Gson().fromJson("{}", PaletteSpec.class), 7);
PaletteSampler sampler = blocksOf(data).palette(new Gson().fromJson("{}", PaletteSpec.class), 7);
picksLike(new Gson().fromJson("{}", IrisMaterialPalette.class), sampler, data, 7);
assertEquals(BlockState.parse("minecraft:stone"), sampler.at(3, 4, 5));
@@ -212,7 +212,7 @@ public class IrisValuesTest {
@Test
public void palettesAreBuiltOncePerSpecAndSeed() {
UsableBlockPlatform.bind();
IrisBlockRegistry blocks = new IrisBlockRegistry(packWithoutCustomBlocks());
IrisBlockRegistry blocks = blocksOf(packWithoutCustomBlocks());
PaletteSpec spec = PaletteSpec.of(List.of(BlockSpec.of("stone"), BlockSpec.of("dirt")));
assertSame(blocks.palette(spec, 1), blocks.palette(PaletteSpec.of(spec.palette()), 1));
@@ -222,7 +222,7 @@ public class IrisValuesTest {
@Test
public void aPaletteWithNoBlockToPickIsRefused() {
UsableBlockPlatform.bind();
IrisBlockRegistry blocks = new IrisBlockRegistry(packWithoutCustomBlocks());
IrisBlockRegistry blocks = blocksOf(packWithoutCustomBlocks());
assertThrows(IllegalArgumentException.class, () -> blocks.palette(PaletteSpec.of(List.of()), 1));
assertThrows(IllegalArgumentException.class, () -> blocks.palette(PaletteSpec.of(List.of(BlockSpec.of("stone").withWeight(0))), 1));
@@ -245,9 +245,18 @@ public class IrisValuesTest {
@SuppressWarnings("unchecked")
ResourceLoader<IrisBlockData> blocks = mock(ResourceLoader.class);
when(data.getBlockLoader()).thenReturn(blocks);
when(data.getDataFolder()).thenReturn(new java.io.File("test-pack"));
return data;
}
private static IrisBlockRegistry blocksOf(IrisData data) {
return new IrisBlockRegistry(data, new IrisPackResources(data, List::of));
}
private static IrisNoiseFactory noiseOf(IrisData data) {
return new IrisNoiseFactory(data, new IrisPackResources(data, List::of));
}
private static void bind(PlatformRegistries registries) {
UsableBlockPlatform.unbind();
IrisPlatform platform = mock(IrisPlatform.class);
@@ -56,7 +56,7 @@ public class PackModuleResourceKindTest {
public final class Keep {
@Desc("Towers on the walls") @MinNumber(1)
private int towers = 4;
@ResourceRef(Keep.class)
@Ref(kind = Keep.class)
private String next = "";
public int towers() { return towers; }
@@ -20,6 +20,7 @@ package art.arcane.iris.core.project;
import art.arcane.iris.builtin.structure.StructureSettings;
import art.arcane.iris.core.modules.StructureModelModule;
import art.arcane.iris.engine.framework.structure.StructureResources;
import art.arcane.iris.engine.mantle.components.StructureModule;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
import art.arcane.iris.core.loader.IrisData;
@@ -213,6 +214,11 @@ public class SchemaBuilderParityTest {
assertEquals(4064, maxDepth.getInt("maximum"));
assertFalse(properties.has("rotation"));
assertFalse(properties.has("translate"));
assertEquals("@IrisStructureRef completes the keys of Iris's structure model",
"#/definitions/erz" + StructureResources.STRUCTURES.folder(),
properties.getJSONObject("structures").getJSONObject("items").getString("$ref"));
assertEquals("@Ref(kind = PackBiome.class) completes the pack's biome keys", "#/definitions/erzbiomes",
properties.getJSONObject("caveBiomes").getJSONObject("items").getString("$ref"));
assertFalse(properties.has("scale"));
}
@@ -518,8 +524,13 @@ public class SchemaBuilderParityTest {
ModuleResourceFixture.serve(data);
ResourceLoader<IrisExpression> expressionLoader = mock(ResourceLoader.class);
ResourceLoader<IrisBlockData> blockLoader = mock(ResourceLoader.class);
ResourceLoader<IrisBiome> biomeLoader = mock(ResourceLoader.class);
KMap<Class<? extends IrisRegistrant>, ResourceLoader<? extends IrisRegistrant>> loaders = new KMap<>();
loaders.put(IrisExpression.class, expressionLoader);
loaders.put(IrisBiome.class, biomeLoader);
when(biomeLoader.getPossibleKeys()).thenReturn(new String[]{"plains"});
when(biomeLoader.getFolderName()).thenReturn("biomes");
when(biomeLoader.getResourceTypeName()).thenReturn("Biome");
when(data.getBlockLoader()).thenReturn(blockLoader);
when(data.getLoaders()).thenReturn(loaders);
when(data.getPossibleSnippets(anyString())).thenReturn(new KList<>());
@@ -11,6 +11,7 @@ import art.arcane.iris.engine.terrain.TerrainTestSettings;
import art.arcane.iris.engine.terrain.TestPackWorld;
import com.volmit.config.FeatureSettings;
import com.volmit.resource.PackResources;
import com.volmit.resource.ResourceId;
import com.volmit.world.UpperDimension;
import org.junit.After;
import org.junit.Before;
@@ -117,8 +118,8 @@ public class TerrainPalettesPinTest {
}
@Override
public String key() {
return UPPER_DIMENSION_KEY;
public ResourceId id() {
return resources.idOf(UPPER_DIMENSION_KEY);
}
@Override
@@ -12,6 +12,7 @@ import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.volmlib.util.collection.KList;
import com.google.gson.Gson;
import com.volmit.host.LoadedPack;
import com.volmit.resource.ResourceId;
import com.volmit.vanilla.JigsawOverrides;
import org.junit.After;
import org.junit.Rule;
@@ -137,7 +138,7 @@ public class NativeStructureStartsTest {
+ "{\"block\":\"minecraft:tuff\"}]}}", StructureTerrain.class);
StructureStilts stilt = GSON.fromJson("{\"maxDepth\":40,\"spacing\":2,"
+ "\"palette\":{\"palette\":[{\"block\":\"minecraft:stone_bricks\"}]}}", StructureStilts.class);
JigsawOverrides jigsaw = JigsawOverrides.none().withStartPool("minecraft:village/plains/town_centers")
JigsawOverrides jigsaw = JigsawOverrides.none().withStartPool(ResourceId.parse("minecraft:village/plains/town_centers"))
.withMaxDepth(5).withHeightmap(JigsawOverrides.Heightmap.OCEAN_FLOOR_WG).withExpansionHack(false);
StructurePlacement fitted = TestSettings.with(placement("fitted", true, -40, -20, 1D,
TestSettings.with(source("minecraft:ancient_city", 1), "jigsaw", jigsaw)), "terrain", terrain, "stilt", stilt);
@@ -21,7 +21,10 @@ package art.arcane.iris.engine.loot;
import art.arcane.iris.builtin.loot.LootTable;
import com.google.gson.Gson;
import com.volmit.item.ItemDrop;
import com.volmit.host.ModuleLogs;
import com.volmit.item.ItemRegistry;
import com.volmit.resource.ContentKey;
import com.volmit.resource.ResourceId;
import org.junit.Before;
import org.junit.Test;
@@ -30,7 +33,7 @@ import java.util.List;
import java.util.OptionalInt;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -39,6 +42,9 @@ import static org.mockito.Mockito.when;
* before the loot classes became settings of the loot module; a change in them changes the loot of existing worlds.
* They were retaken once when an item's absent values became {@code Optional}s: the items printed the old way (absent
* values as {@code null}) still hashed to the old numbers, -492887340, -92432338, -1096436977, -1436497629 and -1714085578.
* They were retaken again when item, enchantment and attribute keys became ids and colours typed values: the items
* printed the old way (keys by path, operations by Bukkit name, colours as written) still hashed to -1656514080,
* 672855254, -359051997, -717275247 and 1936773406.
*/
public class LootDrawPinTest {
private static final long LOOT_SEED = 8123456789L;
@@ -62,17 +68,21 @@ public class LootDrawPinTest {
@Before
public void knowTheItems() {
registry = mock(ItemRegistry.class);
when(registry.maxDurability(anyString())).thenReturn(OptionalInt.empty());
when(registry.maxDurability("diamond_sword")).thenReturn(OptionalInt.of(1561));
when(registry.maxDurability("diamond")).thenReturn(OptionalInt.of(0));
when(registry.maxDurability("bread")).thenReturn(OptionalInt.of(0));
when(registry.maxDurability("stick")).thenReturn(OptionalInt.of(0));
when(registry.maxDurability(any(ContentKey.class))).thenReturn(OptionalInt.empty());
when(registry.maxDurability(platformItem("diamond_sword"))).thenReturn(OptionalInt.of(1561));
when(registry.maxDurability(platformItem("diamond"))).thenReturn(OptionalInt.of(0));
when(registry.maxDurability(platformItem("bread"))).thenReturn(OptionalInt.of(0));
when(registry.maxDurability(platformItem("stick"))).thenReturn(OptionalInt.of(0));
}
private static ContentKey platformItem(String name) {
return new ContentKey.Registered(ResourceId.ofPlatformKey(name));
}
@Test
public void aTableGivesThePinnedItemsAtEachSpot() {
LootTable table = new Gson().fromJson(TABLE, LootTable.class);
LootItems items = new LootItems(registry, false);
LootItems items = new LootItems(registry, false, ModuleLogs.discarding());
List<Integer> hashes = new ArrayList<>();
for (int[] spot : SPOTS) {
@@ -80,6 +90,6 @@ public class LootDrawPinTest {
hashes.add(drops.toString().hashCode());
}
assertEquals(List.of(-1656514080, 672855254, -359051997, -717275247, 1936773406), hashes);
assertEquals(List.of(532699340, 1454887894, -1673240838, 1965175800, 1414053514), hashes);
}
}
@@ -4,8 +4,13 @@ import art.arcane.iris.builtin.loot.LootEntry;
import art.arcane.iris.builtin.loot.LootTable;
import art.arcane.iris.engine.object.TestSettings;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.host.ModuleLogs;
import com.volmit.item.DyeColor;
import com.volmit.item.ItemAttribute;
import com.volmit.item.ItemDrop;
import com.volmit.item.ItemRegistry;
import com.volmit.resource.ContentKey;
import com.volmit.resource.ResourceId;
import org.junit.Before;
import org.junit.Test;
@@ -16,7 +21,7 @@ import java.util.OptionalInt;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -29,9 +34,9 @@ public class LootItemsTest {
@Before
public void knowTheItems() {
registry = mock(ItemRegistry.class);
when(registry.maxDurability(anyString())).thenReturn(OptionalInt.empty());
when(registry.maxDurability("diamond_sword")).thenReturn(OptionalInt.of(1561));
when(registry.maxDurability("diamond")).thenReturn(OptionalInt.of(0));
when(registry.maxDurability(any(ContentKey.class))).thenReturn(OptionalInt.empty());
when(registry.maxDurability(swordKey())).thenReturn(OptionalInt.of(1561));
when(registry.maxDurability(new ContentKey.Registered(ResourceId.parse("minecraft:diamond")))).thenReturn(OptionalInt.of(0));
}
@Test
@@ -48,12 +53,51 @@ public class LootItemsTest {
double bonus = expected.d(2, 6);
double damage = 1D - expected.d(0.25, 0.75);
ItemDrop drop = new LootItems(registry, false).give(entry, new RNG(5L));
ItemDrop drop = new LootItems(registry, false, ModuleLogs.discarding()).give(entry, new RNG(5L));
assertEquals(amount, drop.amount());
assertEquals(level, drop.enchantments().getFirst().level());
assertEquals(bonus, drop.attributes().getFirst().amount(), 0D);
assertEquals(damage, drop.damage().orElseThrow(), 0D);
assertEquals(damage, drop.wear().damage().orElseThrow(), 0D);
}
@Test
public void packKeysReachTheHostAsNamespacedTypedValues() {
LootEntry entry = entry("""
{"type": "Diamond_Sword", "leatherColor": "#FF8000", "dyeColor": "red",
"enchantments": [{"enchantment": "SHARPNESS", "chance": 1}],
"attributes": [{"attribute": "max_health", "operation": "MULTIPLY_SCALAR_1", "chance": 1}]}""");
ItemDrop drop = new LootItems(registry, false, ModuleLogs.discarding()).give(entry, new RNG(5L));
assertEquals(swordKey(), drop.item());
assertEquals(ResourceId.parse("minecraft:sharpness"), drop.enchantments().getFirst().key());
assertEquals(ResourceId.parse("minecraft:max_health"), drop.attributes().getFirst().attribute());
assertEquals(ItemAttribute.Operation.ADD_MULTIPLIED_TOTAL, drop.attributes().getFirst().operation());
assertEquals(OptionalInt.of(0xFF8000), drop.look().leatherColor());
assertEquals(Optional.of(DyeColor.RED), drop.look().dyeColor());
}
@Test
public void aColourThatDoesNotReadIsLeftOutInsteadOfLosingTheItem() {
ItemDrop drop = new LootItems(registry, false, ModuleLogs.discarding())
.give(entry("{\"type\": \"diamond\", \"leatherColor\": \"orange\", \"dyeColor\": \"mauve\"}"), new RNG(5L));
assertTrue(drop.look().leatherColor().isEmpty());
assertTrue(drop.look().dyeColor().isEmpty());
}
@Test
public void anItemOfAnotherProviderIsProvidedByName() {
when(registry.maxDurability(new ContentKey.Provided("Nexo", "Ruby Sword"))).thenReturn(OptionalInt.of(0));
ItemDrop drop = new LootItems(registry, false, ModuleLogs.discarding()).give(entry("{\"type\": \"Nexo:Ruby Sword\"}"), new RNG(5L));
assertEquals(new ContentKey.Provided("Nexo", "Ruby Sword"), drop.item());
}
private static ContentKey swordKey() {
return new ContentKey.Registered(ResourceId.parse("minecraft:diamond_sword"));
}
@Test
@@ -62,10 +106,10 @@ public class LootItemsTest {
RNG rng = new RNG(9L);
RNG untouched = new RNG(9L);
ItemDrop drop = new LootItems(registry, false).give(entry, rng);
ItemDrop drop = new LootItems(registry, false, ModuleLogs.discarding()).give(entry, rng);
assertEquals(2, drop.amount());
assertTrue(drop.damage().isEmpty());
assertTrue(drop.wear().damage().isEmpty());
assertEquals(untouched.nextLong(), rng.nextLong());
}
@@ -74,8 +118,8 @@ public class LootItemsTest {
RNG rng = new RNG(9L);
RNG untouched = new RNG(9L);
assertNull(new LootItems(registry, false).give(entry("{\"type\": \"not_an_item\"}"), rng));
assertNull(new LootItems(registry, false).give(entry("{\"type\": \"air\"}"), rng));
assertNull(new LootItems(registry, false, ModuleLogs.discarding()).give(entry("{\"type\": \"not_an_item\"}"), rng));
assertNull(new LootItems(registry, false, ModuleLogs.discarding()).give(entry("{\"type\": \"air\"}"), rng));
assertEquals(untouched.nextLong(), rng.nextLong());
}
@@ -83,19 +127,19 @@ public class LootItemsTest {
public void debugItemsSayWhereTheyCameFrom() {
LootTable table = table("{\"name\": \"dungeon\", \"rarity\": 4, \"minPicked\": 1, \"maxPicked\": 1, \"loot\": [{\"type\": \"diamond\", \"rarity\": 3}]}");
List<ItemDrop> drops = new LootItems(registry, true).draw("dungeon", table, LOOT_SEED, 0, 64, 0);
List<ItemDrop> drops = new LootItems(registry, true, ModuleLogs.discarding()).draw("dungeon", table, LOOT_SEED, 0, 64, 0);
for (ItemDrop drop : drops) {
assertEquals(Optional.of(new ItemDrop.Source(Optional.of("dungeon"), 4, 3)), drop.source());
}
assertTrue(new LootItems(registry, false).draw("dungeon", table, LOOT_SEED, 0, 64, 0).stream().allMatch(drop -> drop.source().isEmpty()));
assertTrue(new LootItems(registry, false, ModuleLogs.discarding()).draw("dungeon", table, LOOT_SEED, 0, 64, 0).stream().allMatch(drop -> drop.source().isEmpty()));
}
@Test
public void aTableGivesTheSameItemsAtTheSameSpotAndSeed() {
LootTable table = table("{\"name\": \"tools\", \"minPicked\": 2, \"maxPicked\": 4, \"loot\": [{\"type\": \"diamond\", \"maxAmount\": 5}, {\"type\": \"diamond_sword\"}]}");
LootItems items = new LootItems(registry, false);
LootItems items = new LootItems(registry, false, ModuleLogs.discarding());
assertEquals(items.draw("tools", table, LOOT_SEED, 10, 64, -30), items.draw("tools", table, LOOT_SEED, 10, 64, -30));
}
@@ -18,6 +18,7 @@ import art.arcane.iris.engine.object.world.region.IrisRegion;
import com.volmit.config.Desc;
import com.volmit.config.MaxNumber;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.host.ModuleLogs;
import com.volmit.item.ItemRegistry;
import com.volmit.world.PackWorld;
import org.junit.Test;
@@ -252,7 +253,7 @@ public class LootResolverTest {
public void emptyLootTableReturnsNoItems() {
LootTable table = TestSettings.of(LootTable.class, "{\"name\": \"empty\"}");
assertTrue(new LootItems(mock(ItemRegistry.class), false).draw("empty", table, 7L, 0, 64, 0).isEmpty());
assertTrue(new LootItems(mock(ItemRegistry.class), false, ModuleLogs.discarding()).draw("empty", table, 7L, 0, 64, 0).isEmpty());
}
@Test
@@ -30,6 +30,7 @@ import com.volmit.block.BlockRegistry;
import com.volmit.block.BlockSpec;
import com.volmit.block.BlockState;
import com.volmit.resource.PackResources;
import com.volmit.resource.ResourceId;
import com.volmit.service.Loot;
import org.junit.Before;
import org.junit.Test;
@@ -122,7 +123,7 @@ public class PlacementLootTest {
Loot.Source picked = pick(platform, List.of(), CHEST);
assertEquals(new Loot.PlatformTable("minecraft:chests/simple_dungeon",
assertEquals(new Loot.PlatformTable(ResourceId.parse("minecraft:chests/simple_dungeon"),
LootTables.seed(LOOT_SEED, "Vanilla minecraft:chests/simple_dungeon", 0, 64, 0)), picked);
}
@@ -48,7 +48,7 @@ import static org.mockito.Mockito.when;
/** Trees only replace the platform's growth when the dimension asks for it and a placement of the area grows that species. */
public class TreeGrowingTest {
private static final SaplingGrowth.Sapling OAK_SAPLING = new SaplingGrowth.Sapling(
new BlockPosition(10, 70, 20), new BlockPosition(10, 70, 20), "TREE");
new BlockPosition(10, 70, 20), new BlockPosition(10, 70, 20), ResourceId.ofPlatformKey("TREE"));
private static final ResourceId SOURCE = ResourceId.parse("test:dimension/overworld");
private static final ResourceId BIOME = ResourceId.parse("test:plains");
private static final ResourceId REGION = ResourceId.parse("test:overworld");
@@ -378,8 +378,8 @@ public final class ApiChunk implements GenerationContext {
}
@Override
public String key() {
return "overworld";
public ResourceId id() {
return ResourceId.parse("test:overworld");
}
@Override
@@ -5,6 +5,7 @@ import art.arcane.iris.builtin.IrisSeeds;
import art.arcane.iris.builtin.carve.CarvingEntry;
import art.arcane.iris.builtin.carve.CarvingSettings;
import art.arcane.iris.core.modules.CarveTestWorld;
import art.arcane.iris.core.modules.IrisPackResources;
import art.arcane.iris.core.modules.IrisValues;
import art.arcane.iris.engine.object.value.IRare;
import art.arcane.iris.util.project.noise.CNG;
@@ -281,7 +282,7 @@ public class CarvingResolverParityTest {
long generatorSeed = seed ^ (idHash << 32) ^ CHILD_GENERATOR_SALT;
double scale = Math.max(MIN_CHILD_SCALE, settings.childShrinkFactor());
RNG random = new RNG(generatorSeed);
return IrisValues.generatorStyle(settings.childStyle()).createNoCache(random.nextParallelRNG(CHILD_GENERATOR_SIGNATURE), world.data())
return IrisValues.generatorStyle(settings.childStyle(), new IrisPackResources(world.data())).createNoCache(random.nextParallelRNG(CHILD_GENERATOR_SIGNATURE), world.data())
.bake().scale(scale).bake();
}
}
@@ -28,6 +28,7 @@ import art.arcane.iris.engine.object.world.region.IrisRegion;
import art.arcane.iris.engine.object.world.IrisWorld;
import art.arcane.iris.builtin.spawn.EffectSettings;
import art.arcane.iris.spi.PlatformWorld;
import com.volmit.resource.ResourceId;
import com.volmit.service.AmbientEffects;
import com.volmit.geometry.BlockPosition;
import com.volmit.world.PackWorld;
@@ -93,11 +94,11 @@ public class AmbientEffectingTest {
assertEquals(1, due.size());
AmbientEffects.Sound sound = due.getFirst().sound().orElseThrow();
assertEquals("ambient.cave", sound.key());
assertEquals(ResourceId.parse("minecraft:ambient.cave"), sound.key());
assertTrue(Math.abs(sound.offsetX()) <= 4 && Math.abs(sound.offsetY()) <= 4 && Math.abs(sound.offsetZ()) <= 4);
assertEquals(2F, sound.volume(), 0);
assertEquals(0.5F, sound.pitch(), 0);
assertEquals(Optional.of(new AmbientEffects.Potion("luck", 1, 100)), due.getFirst().potion());
assertEquals(Optional.of(new AmbientEffects.Potion(ResourceId.parse("minecraft:luck"), 1, 100)), due.getFirst().potion());
assertTrue(due.getFirst().particles().isEmpty());
assertTrue(due.getFirst().commands().isEmpty());
}
@@ -110,10 +111,10 @@ public class AmbientEffectingTest {
AmbientEffects.Effect effect = new AmbientEffecting().due(world, AT).getFirst();
AmbientEffects.Particles particles = effect.particles().orElseThrow();
assertEquals("flame", particles.key());
assertEquals(5, particles.forward(), 0);
assertEquals(0, particles.sideways(), 0);
assertEquals(0.5, particles.altX(), 0);
assertEquals(ResourceId.parse("minecraft:flame"), particles.key());
assertEquals(5, particles.spot().forward(), 0);
assertEquals(0, particles.spot().sideways(), 0);
assertEquals(0.5, particles.spread().x(), 0);
assertEquals(0.25, particles.extra(), 0);
assertEquals(2, particles.count());
assertEquals(1, effect.commands().size());
@@ -23,8 +23,11 @@ import art.arcane.iris.builtin.spawn.EntityDefinition;
import art.arcane.iris.builtin.LiveWorld.Sky;
import art.arcane.volmlib.util.math.RNG;
import com.google.gson.Gson;
import com.volmit.ModuleLog;
import com.volmit.entity.EntitySpec;
import com.volmit.host.ModuleLogs;
import com.volmit.item.ItemRegistry;
import com.volmit.resource.ContentKey;
import com.volmit.resource.PackResources;
import com.volmit.resource.ResourceId;
import org.junit.Test;
@@ -33,6 +36,7 @@ import java.util.Optional;
import java.util.OptionalInt;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -42,6 +46,8 @@ import static org.mockito.Mockito.when;
* classes became settings of the spawn module; a change in it changes the equipment, attributes and passengers worlds spawn.
* It was retaken once when absent values became {@code Optional}s and loot tables ids: the spec printed the old way (empty
* texts as {@code ""}, other absent values as {@code null}, tables by key) still hashed to the old number, -819231818.
* It was retaken again when the spec was grouped, its keys became ids and content keys and the Iris-only knobs an
* extension: the spec printed the old way (flat fields, keys as written, operations by Bukkit name) still hashed to 1441930785.
*/
public class EntityResolutionPinTest {
private static final long STREAM_SEED = 4321L;
@@ -65,17 +71,23 @@ public class EntityResolutionPinTest {
@Test
public void anEntityResolvesToThePinnedSpec() {
ItemRegistry registry = mock(ItemRegistry.class);
when(registry.maxDurability(anyString())).thenReturn(OptionalInt.of(0));
when(registry.maxDurability("iron_helmet")).thenReturn(OptionalInt.of(165));
when(registry.maxDurability("diamond_sword")).thenReturn(OptionalInt.of(1561));
when(registry.maxDurability(any(ContentKey.class))).thenReturn(OptionalInt.of(0));
when(registry.maxDurability(platformItem("iron_helmet"))).thenReturn(OptionalInt.of(165));
when(registry.maxDurability(platformItem("diamond_sword"))).thenReturn(OptionalInt.of(1561));
Optional<Sky> sky = Optional.of(new Sky(0L, false, false));
EntityDefinition entity = new Gson().fromJson(ENTITY, EntityDefinition.class);
PackResources resources = mock(PackResources.class);
when(resources.idOf(anyString())).thenAnswer(invocation -> new ResourceId("test", invocation.getArgument(0)));
EntitySpec spec = new EntityResolution(resources, new LootItems(registry, false), sky, new EffectTimers()).resolve(entity, new RNG(STREAM_SEED));
ModuleLog log = ModuleLogs.discarding();
EntitySpec spec = new EntityResolution(resources, new LootItems(registry, false, log), sky, new EffectTimers(), log)
.resolve(entity, new RNG(STREAM_SEED)).orElseThrow();
assertEquals(1441930785, spec.toString().hashCode());
assertEquals(-847596166, spec.toString().hashCode());
}
private static ContentKey platformItem(String name) {
return new ContentKey.Registered(ResourceId.ofPlatformKey(name));
}
}
@@ -26,6 +26,7 @@ import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.EngineGeneration;
import art.arcane.iris.engine.framework.SeedManager;
import art.arcane.iris.builtin.spawn.EntityDefinition;
import art.arcane.iris.builtin.spawn.IrisEntityExtras;
import art.arcane.iris.builtin.spawn.SpawnMarker;
import art.arcane.iris.builtin.spawn.Spawner;
import art.arcane.iris.engine.object.TestSettings;
@@ -34,6 +35,8 @@ import art.arcane.iris.engine.object.world.IrisWorld;
import art.arcane.iris.spi.PlatformWorld;
import com.volmit.entity.EntitySpec;
import com.volmit.item.ItemRegistry;
import com.volmit.resource.ContentKey;
import com.volmit.resource.ResourceId;
import com.volmit.service.EntitySpawns;
import com.volmit.geometry.BlockPosition;
import com.volmit.world.PackWorld;
@@ -101,7 +104,7 @@ public class EntitySpawningTest {
fixture.resource(SpawnResources.MARKERS, "camp", marker);
fixture.resource(SpawnResources.SPAWNERS, "zombies", new Spawner());
EntitySpawns.MarkerRule rule = new EntitySpawning().marker(world, "camp").orElseThrow();
EntitySpawns.MarkerRule rule = new EntitySpawning().marker(world, world.resources().idOf("camp")).orElseThrow();
assertEquals("a spawner the pack lacks is left out", List.of(world.resources().idOf("zombies")), rule.spawners());
assertTrue(rule.emptyAbove());
@@ -110,8 +113,8 @@ public class EntitySpawningTest {
@Test
public void markersNoModuleKnowsAndTheCaveMarkersMeanNothing() {
assertTrue(new EntitySpawning().marker(world, "unknown").isEmpty());
assertTrue(new EntitySpawning().marker(world, "cave_floor").isEmpty());
assertTrue(new EntitySpawning().marker(world, world.resources().idOf("unknown")).isEmpty());
assertTrue(new EntitySpawning().marker(world, world.resources().idOf("cave_floor")).isEmpty());
}
@Test
@@ -123,7 +126,7 @@ public class EntitySpawningTest {
when(engine.getMinHeight()).thenReturn(-64);
EntitySpawns.Plan plan = new EntitySpawning()
.plan(world, new EntitySpawns.Marker(MARKER_BLOCK, "camp", world.resources().idOf("camp/zombies"), false))
.plan(world, new EntitySpawns.Marker(MARKER_BLOCK, world.resources().idOf("camp"), world.resources().idOf("camp/zombies"), false))
.orElseThrow();
assertEquals(world.resources().idOf("camp/zombies"), plan.spawner());
@@ -132,7 +135,7 @@ public class EntitySpawningTest {
for (EntitySpawns.Attempt attempt : plan.attempts()) {
assertEquals(new BlockPosition(40, 71, -12), attempt.at());
assertFalse(attempt.checkSurface());
assertEquals(Optional.of("minecraft:zombie"), attempt.entity().type());
assertEquals(vanilla("zombie"), attempt.entity().type());
}
}
@@ -140,7 +143,7 @@ public class EntitySpawningTest {
public void aSpawnerThatCannotFireOrHasNoEntitiesPlansNothing() {
fixture.resource(SpawnResources.SPAWNERS, "empty", new Spawner());
Optional<EntitySpawns.Plan> plan = new EntitySpawning().plan(world, new EntitySpawns.Marker(MARKER_BLOCK, "camp", world.resources().idOf("empty"), false));
Optional<EntitySpawns.Plan> plan = new EntitySpawning().plan(world, new EntitySpawns.Marker(MARKER_BLOCK, world.resources().idOf("camp"), world.resources().idOf("empty"), false));
assertTrue(plan.isEmpty());
}
@@ -152,9 +155,31 @@ public class EntitySpawningTest {
EntitySpec spec = new EntitySpawning().entity(world, world.resources().idOf("cow")).orElseThrow();
assertEquals(Optional.of("minecraft:cow"), spec.type());
assertEquals(Optional.of("&6Bessie"), spec.customName());
assertTrue(spec.flags().baby());
assertEquals(vanilla("cow"), spec.type());
assertEquals(Optional.of("&6Bessie"), spec.appearance().customName());
assertTrue(spec.appearance().baby());
assertTrue(new EntitySpawning().entity(world, world.resources().idOf("nothing")).isEmpty());
}
@Test
public void aMobOfAnotherProviderIsProvidedByNameWithItsIrisExtras() {
fixture.resource(SpawnResources.ENTITIES, "king", TestSettings.of(EntityDefinition.class,
"{\"type\": \"minecraft:zombie\", \"specialType\": \"MythicMobs:Skeleton King\", \"reason\": \"CUSTOM\"}"));
EntitySpec spec = new EntitySpawning().entity(world, world.resources().idOf("king")).orElseThrow();
assertEquals(new ContentKey.Provided("MythicMobs", "Skeleton King"), spec.type());
assertEquals(Optional.of("CUSTOM"), spec.extension(IrisEntityExtras.class).orElseThrow().reason());
}
@Test
public void anEntityWithoutAValidTypeIsNotSpawned() {
fixture.resource(SpawnResources.ENTITIES, "broken", TestSettings.of(EntityDefinition.class, "{\"type\": \"not a key!\"}"));
assertTrue(new EntitySpawning().entity(world, world.resources().idOf("broken")).isEmpty());
}
private static ContentKey vanilla(String name) {
return new ContentKey.Registered(ResourceId.parse("minecraft:" + name));
}
}