Studio completes a platform loot table option (Reference.LOOT_TABLE); tests follow the object placement's loot and marker types

This commit is contained in:
piexel committed 2026-10-10 18:21:37 +02:00
1 parent 7aa06e58f2
commit 540b4beaed
4 files changed
+21 -71

No files matched your search

@@ -91,6 +91,7 @@ public class SchemaBuilder {
private static final String MINECRAFT_NAMESPACE = "minecraft:";
/** Namespaced key or family/namespace prefix: "minecraft:village_plains", "minecraft:village", "nova_structures:". */
private static final String VANILLA_STRUCTURE_PREFIX_PATTERN = "^[a-z0-9_.-]+:[a-z0-9_./-]*$";
private static final String LOOT_TABLE_DEFINITION = "loot-table-key";
private static volatile JSONArray fontTypes;
private final KMap<String, JSONObject> definitions;
private final Class<?> root;
@@ -223,6 +224,10 @@ public class SchemaBuilder {
return keysAsArray(IrisPlatforms.get().registries().entityKeys());
}
private JSONArray lootTableKeys() {
return keysAsArray(IrisPlatforms.get().registries().lootTableKeys());
}
private JSONArray specialEntityTypes() {
return keysAsArray(IrisPlatforms.get().registries().specialEntityKeys());
}
@@ -448,6 +453,7 @@ public class SchemaBuilder {
case TEMPLATE_POOL -> putRegistryEnumRef(property, "enum-native-jigsaw-pool", this::nativeJigsawPools);
case POTION_EFFECT -> putRegistryEnumRef(property, "enum-potion-effect-type", this::potionTypes);
case ENCHANTMENT -> putRegistryEnumRef(property, "enum-enchantment", this::enchantTypes);
case LOOT_TABLE -> putRegistryEnumRef(property, LOOT_TABLE_DEFINITION, this::lootTableKeys);
case PACK_BIOME -> putPackResourceRef(property, IrisBiome.class);
case PACK_REGION -> putPackResourceRef(property, IrisRegion.class);
case PACK_OBJECT -> putPackResourceRef(property, IrisObject.class);
@@ -7,9 +7,9 @@ import art.arcane.iris.builtin.blocks.ObjectReplace;
import art.arcane.iris.builtin.stilt.StiltSettings;
import art.arcane.iris.builtin.prepare.SlopeClip;
import art.arcane.iris.builtin.validate.ObjectLimit;
import art.arcane.iris.engine.object.loot.IrisObjectLoot;
import art.arcane.iris.engine.object.loot.IrisObjectVanillaLoot;
import art.arcane.iris.engine.object.marker.IrisObjectMarker;
import art.arcane.iris.builtin.loot.ObjectLoot;
import art.arcane.iris.builtin.loot.ObjectVanillaLoot;
import art.arcane.iris.builtin.spawn.PlacementMarker;
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
import art.arcane.iris.engine.object.noise.IrisNoiseGenerator;
import art.arcane.iris.engine.object.noise.IrisStyledRange;
@@ -37,23 +37,23 @@ public class IrisObjectPlacementToPlacementTest {
densityStyle.setMin(7D);
densityStyle.setMax(7D);
StiltSettings stiltSettings = new StiltSettings();
KList<IrisObjectMarker> markers = new KList<>();
KList<PlacementMarker> markers = new KList<>();
IrisNoiseGenerator heightmap = new IrisNoiseGenerator(false);
IrisGeneratorStyle warp = NoiseStyle.SIMPLEX.style();
KList<ObjectReplace> edit = new KList<>();
IrisObjectTranslate translate = new IrisObjectTranslate();
IrisObjectScale scale = new IrisObjectScale();
KList<IrisObjectLoot> loot = new KList<>();
KList<IrisObjectVanillaLoot> vanillaLoot = new KList<>();
KList<ObjectLoot> loot = new KList<>();
KList<ObjectVanillaLoot> vanillaLoot = new KList<>();
KList<IrisTree> trees = new KList<>();
KList<String> allowedCollisions = new KList<>();
KList<String> forbiddenCollisions = new KList<>();
SlopeClip slopeCondition = new SlopeClip();
markers.add(new IrisObjectMarker());
markers.add(new PlacementMarker());
edit.add(new ObjectReplace());
loot.add(new IrisObjectLoot());
vanillaLoot.add(new IrisObjectVanillaLoot());
loot.add(new ObjectLoot());
vanillaLoot.add(new ObjectVanillaLoot());
trees.add(new IrisTree());
allowedCollisions.add("objects/allowed");
forbiddenCollisions.add("objects/forbidden");
@@ -20,12 +20,12 @@ public class IrisStructureLootPlacementTest {
assertEquals(1, placement.getPlace().size());
assertEquals("pieces/village_house", placement.getPlace().get(0));
assertEquals(2, placement.getLoot().size());
assertEquals("village_common", placement.getLoot().get(0).getName());
assertEquals(1, placement.getLoot().get(0).getWeight());
assertTrue(placement.getLoot().get(0).getFilter().isEmpty());
assertEquals("village_rare", placement.getLoot().get(1).getName());
assertEquals(1, placement.getLoot().get(1).getWeight());
assertTrue(placement.getLoot().get(1).getFilter().isEmpty());
assertEquals("village_common", placement.getLoot().get(0).name());
assertEquals(1, placement.getLoot().get(0).weight());
assertTrue(placement.getLoot().get(0).filter().isEmpty());
assertEquals("village_rare", placement.getLoot().get(1).name());
assertEquals(1, placement.getLoot().get(1).weight());
assertTrue(placement.getLoot().get(1).filter().isEmpty());
assertFalse(placement.isOverrideGlobalLoot());
}
@@ -1,56 +0,0 @@
/*
* 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.engine.object.value;
import art.arcane.volmlib.util.collection.KList;
import org.junit.Test;
import java.util.List;
import static org.junit.Assert.assertEquals;
/** Rarity weights a pool exactly once: the entity spawners of both platforms pick a spawn from the expanded pool. */
public class IRareWeightingTest {
private record Spawn(int rarity) implements IRare {
@Override
public int getRarity() {
return rarity;
}
}
@Test
public void rarityIsAppliedOnceAsPoolWeightOnly() {
Spawn common = new Spawn(1);
Spawn rare = new Spawn(4);
KList<Spawn> expanded = IRare.expandWeighted(List.of(common, rare));
// totalRarity 5 -> common appears 5/1 = 5 times, rare 5/4 = 1 time.
assertEquals(6, expanded.size());
assertEquals(5, expanded.stream().filter(entry -> entry == common).count());
assertEquals(1, expanded.stream().filter(entry -> entry == rare).count());
}
@Test
public void rarityZeroAndNegativeAreClampedToOne() {
assertEquals(1, IRare.get(new Spawn(0)));
assertEquals(1, IRare.get(new Spawn(-5)));
assertEquals(3, IRare.get(new Spawn(3)));
}
}