mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Merge branch 'wave3b/6' into feat/irisapi-host
This commit is contained in:
commit
5d9f960a20
32 files changed
+917
-428
No files matched your search
@@ -21,7 +21,7 @@ package art.arcane.iris.modded;
|
||||
import art.arcane.iris.core.content.ContentLoot;
|
||||
import art.arcane.iris.core.content.ContentServices;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.LootResolver;
|
||||
import art.arcane.iris.builtin.loot.LootResolver;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.engine.framework.LootResolver;
|
||||
import art.arcane.iris.builtin.loot.LootResolver;
|
||||
import art.arcane.iris.engine.loot.LootTables;
|
||||
import art.arcane.iris.builtin.loot.LootMode;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.spawn.SpawnCooldowns;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
|
||||
import java.util.function.ToLongFunction;
|
||||
|
||||
/** The cooldowns of an engine's spawners, in the data the engine saves with its world. */
|
||||
final class EngineSpawnCooldowns implements SpawnCooldowns {
|
||||
private final Engine engine;
|
||||
|
||||
EngineSpawnCooldowns(Engine engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSpawn(String spawner, long intervalMilliseconds) {
|
||||
return engine.getEngineData().getCooldown(spawner).canSpawn(intervalMilliseconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawned(String spawner) {
|
||||
engine.getEngineData().getCooldown(spawner).spawn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSpawnInChunk(int chunkX, int chunkZ, String spawner, long intervalMilliseconds) {
|
||||
return engine.getEngineData().getChunk(chunkX, chunkZ).getCooldown(spawner).canSpawn(intervalMilliseconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnedInChunk(int chunkX, int chunkZ, String spawner) {
|
||||
engine.getEngineData().getChunk(chunkX, chunkZ).getCooldown(spawner).spawn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forgetExpired(ToLongFunction<String> intervalMilliseconds) {
|
||||
engine.getEngineData().cleanup(intervalMilliseconds);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* 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.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.LiveWorld;
|
||||
import art.arcane.iris.builtin.spawn.SpawnCooldowns;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.engine.object.value.IrisPosition;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.framework.PlacedObject;
|
||||
import art.arcane.iris.engine.object.world.biome.InferredType;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformWorld;
|
||||
import art.arcane.iris.util.common.scheduling.J;
|
||||
import art.arcane.volmlib.util.matter.slices.MarkerMatter;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.BlockPosition;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* An engine as {@link LiveWorld} shows it to the built-in services: the engine's own answers for a block, turned into pack
|
||||
* resource ids and values.
|
||||
*/
|
||||
final class IrisLiveWorld implements LiveWorld {
|
||||
private final Engine engine;
|
||||
private final IrisPackResources resources;
|
||||
private final SpawnCooldowns cooldowns;
|
||||
private volatile Set<String> platformLootTables;
|
||||
|
||||
IrisLiveWorld(Engine engine, IrisPackResources resources) {
|
||||
this.engine = engine;
|
||||
this.resources = resources;
|
||||
this.cooldowns = new EngineSpawnCooldowns(engine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int bottomY() {
|
||||
return engine.getMinHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceId surfaceBiome(int x, int z) {
|
||||
return idOf(engine.getSurfaceBiome(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceId caveBiome(int x, int y, int z) {
|
||||
IrisBiome cave = engine.getCaveBiome(x, y, z);
|
||||
return cave == null ? surfaceBiome(x, z) : idOf(cave);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeKind surfaceKind(int x, int z) {
|
||||
InferredType type = engine.getSurfaceBiome(x, z).getInferredType();
|
||||
return BiomeKind.valueOf(type.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public double terrainHeight(int x, int z) {
|
||||
return engine.getComplex().getHeightStream().get(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int highestBlock(int x, int z, boolean ignoreFluid) {
|
||||
return engine.getHeight(x, z, ignoreFluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <F extends IrisFeature> Optional<F> settings(Class<F> type, Level level, int x, int y, int z) {
|
||||
IrisRegistrant owner = switch (level) {
|
||||
case DIMENSION -> engine.getDimension();
|
||||
case REGION -> engine.getRegion(x, z);
|
||||
case SURFACE_BIOME -> engine.getSurfaceBiome(x, z);
|
||||
case BIOME -> engine.getBiome(x, y, z);
|
||||
case CAVE_BIOME -> engine.getCaveBiome(x, y, z);
|
||||
};
|
||||
return owner == null ? Optional.empty() : owner.getModuleSettings().find(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Sky> sky() {
|
||||
PlatformWorld world = engine.getWorld().platformWorld();
|
||||
if (world == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(new Sky(world.getTime(), world.isStorming(), world.isThundering()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean studio() {
|
||||
return engine.isStudio();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> platformLootTables() {
|
||||
Set<String> known = platformLootTables;
|
||||
if (known == null) {
|
||||
known = Set.copyOf(IrisPlatforms.get().registries().lootTableKeys());
|
||||
platformLootTables = known;
|
||||
}
|
||||
return known;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockPosition> caveFloors(int chunkX, int chunkZ) {
|
||||
if (J.isFolia()) {
|
||||
return List.of();
|
||||
}
|
||||
int bottom = engine.getMinHeight();
|
||||
return engine.getMantle().findMarkers(chunkX, chunkZ, MarkerMatter.CAVE_FLOOR).stream()
|
||||
.map(floor -> new BlockPosition(floor.getX(), floor.getY() - bottom, floor.getZ()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ObjectLoots> objectLoots(int x, int y, int z) {
|
||||
PlacedObject placed = engine.getObjectPlacement(x, y, z);
|
||||
IrisObjectPlacement placement = placed == null ? null : placed.getPlacement();
|
||||
if (placement == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(new ObjectLoots(placement.getLoot(), placement.getVanillaLoot(), placement.isOverrideGlobalLoot()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpawnCooldowns spawnCooldowns() {
|
||||
return cooldowns;
|
||||
}
|
||||
|
||||
private ResourceId idOf(IrisBiome biome) {
|
||||
return resources.idOf(biome.getLoadKey());
|
||||
}
|
||||
}
|
||||
@@ -21,9 +21,7 @@ package art.arcane.iris.core.modules;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.actuator.DecorantModule;
|
||||
import art.arcane.iris.engine.actuator.TerrainModule;
|
||||
import art.arcane.iris.engine.loot.LootModule;
|
||||
import art.arcane.iris.engine.mantle.components.ObjectModule;
|
||||
import art.arcane.iris.engine.spawn.SpawnModule;
|
||||
import art.arcane.iris.engine.mantle.components.StructureModule;
|
||||
import art.arcane.iris.engine.modifier.CarveModule;
|
||||
import art.arcane.iris.engine.modifier.DepositModule;
|
||||
@@ -63,7 +61,7 @@ public final class IrisModuleHost {
|
||||
* {@code IrisModule/builtin-modules.txt}) instead of being compiled into Iris. A pack loads them from its {@code modules}
|
||||
* folder, and {@link MissingBuiltInModules} warns when it loads none; a test keeps this equal to the jar's list.
|
||||
*/
|
||||
public static final List<String> JAR_MODULE_IDS = List.of("iris:post", "iris:perfection", "iris:matter");
|
||||
public static final List<String> JAR_MODULE_IDS = List.of("iris:post", "iris:perfection", "iris:matter", "iris:loot", "iris:spawn");
|
||||
/** Iris's pack object model: built-in settings may hold these classes, which Iris reads and describes itself. */
|
||||
public static final String HOST_TYPE_PACKAGE = "art.arcane.iris.engine.object";
|
||||
private static final String[] JAR_COPY_FOLDER = {"cache", "module-jars"};
|
||||
@@ -88,7 +86,7 @@ public final class IrisModuleHost {
|
||||
|
||||
private static List<IrisModule> generationModules() {
|
||||
return List.of(new TerrainModule(), new CarveModule(), new ObjectModule(), new StructureModule(),
|
||||
new FloatingModule(), new DepositModule(), new DecorantModule(), new LootModule(), new SpawnModule());
|
||||
new FloatingModule(), new DepositModule(), new DecorantModule());
|
||||
}
|
||||
|
||||
/** Iris's own log, labelled {@code [iris]}, for host code that calls module classes outside any module's stage, service or hook. */
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.LiveWorld;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import com.volmit.ModuleLog;
|
||||
@@ -35,12 +36,13 @@ import java.util.function.Function;
|
||||
* pack's resources reload under it. Iris's built-in modules reach the engine through {@link #of(PackWorld)}, as built-in
|
||||
* reaches do through {@link IrisPackSettings#of}.
|
||||
*/
|
||||
public final class IrisPackWorld implements PackWorld, IrisSeed.Source {
|
||||
public final class IrisPackWorld implements PackWorld, IrisSeed.Source, LiveWorld.Source {
|
||||
private final Engine engine;
|
||||
private final IrisPackResources resources;
|
||||
private final WorldStates states;
|
||||
private final ModuleLog log;
|
||||
private final Map<ModuleLog, IrisPackWorld> viewsByLog;
|
||||
private final LiveWorld liveWorld;
|
||||
|
||||
IrisPackWorld(Engine engine) {
|
||||
this(engine, engine.getData().getPackResources(), new WorldStates(), IrisApiLogger.hostLog(), new ConcurrentHashMap<>());
|
||||
@@ -53,6 +55,7 @@ public final class IrisPackWorld implements PackWorld, IrisSeed.Source {
|
||||
this.states = states;
|
||||
this.log = log;
|
||||
this.viewsByLog = viewsByLog;
|
||||
this.liveWorld = new IrisLiveWorld(engine, resources);
|
||||
}
|
||||
|
||||
/** Iris's own view of {@code world}, which Iris hands to every stage, service and lifecycle hook. */
|
||||
@@ -99,6 +102,11 @@ public final class IrisPackWorld implements PackWorld, IrisSeed.Source {
|
||||
return viewsByLog.computeIfAbsent(log, moduleLog -> new IrisPackWorld(engine, resources, states, moduleLog, viewsByLog));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiveWorld liveWorld() {
|
||||
return liveWorld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long seed(IrisSeed seed) {
|
||||
SeedManager seeds = engine.getSeedManager();
|
||||
|
||||
@@ -43,7 +43,8 @@ final class MissingBuiltInModules {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of("Pack " + packFolder.getName() + " loads without the built-in modules (" + JAR_NAME + "): its chunks get"
|
||||
+ " no objects or structures, no surface smoothing and no clean-up of floating decorations. Copy " + JAR_NAME
|
||||
+ " no objects or structures, no surface smoothing and no clean-up of floating decorations, and its world has no loot,"
|
||||
+ " block drops, entity spawns or ambient effects. Copy " + JAR_NAME
|
||||
+ " into " + new File(packFolder, PackModuleSet.MODULES_FOLDER).getPath() + " to fix it.");
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -58,7 +58,6 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
private final KList<Runnable> updateQueue = new KList<>();
|
||||
final ChronoLatch cl;
|
||||
private final ChronoLatch clw;
|
||||
private final ChronoLatch cln;
|
||||
private final ChronoLatch chunkUpdater;
|
||||
private final ChronoLatch chunkDiscovery;
|
||||
private final KMap<Long, Future<?>> cleanup = new KMap<>();
|
||||
@@ -89,7 +88,6 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
public IrisWorldManager() {
|
||||
super(null);
|
||||
cl = null;
|
||||
cln = null;
|
||||
clw = null;
|
||||
looper = null;
|
||||
chunkUpdater = null;
|
||||
@@ -101,7 +99,6 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
super(engine);
|
||||
chunkUpdater = new ChronoLatch(3000);
|
||||
chunkDiscovery = new ChronoLatch(5000);
|
||||
cln = new ChronoLatch(60000);
|
||||
cl = new ChronoLatch(3000);
|
||||
clw = new ChronoLatch(1000, true);
|
||||
cleanupService = createCleanupExecutor(getTarget().getWorld().name());
|
||||
@@ -157,10 +154,6 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
chunkMaintenance.discoverChunks();
|
||||
}
|
||||
|
||||
if (cln.flip()) {
|
||||
getEngine().getEngineData().cleanup(getEngine());
|
||||
}
|
||||
|
||||
if (!IrisSettings.get().getWorld().isMarkerEntitySpawningSystem()
|
||||
&& !IrisSettings.get().getWorld().isAmbientEntitySpawningSystem()) {
|
||||
return 3000L;
|
||||
|
||||
@@ -1,196 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit 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.framework;
|
||||
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.ToIntFunction;
|
||||
|
||||
public final class LootResolver {
|
||||
private static final int MAX_SCALED_SOURCE_COUNT = 256;
|
||||
private static final long CONTAINER_SALT = 0x632BE59BD9B4E019L;
|
||||
private static final long TABLE_SALT = 0x94D049BB133111EBL;
|
||||
private static final long ENTRY_SALT = 0x9E3779B97F4A7C15L;
|
||||
|
||||
private LootResolver() {
|
||||
}
|
||||
|
||||
public static RNG containerRng(long lootSeed, int x, int y, int z) {
|
||||
return new RNG(containerSeed(lootSeed, x, y, z));
|
||||
}
|
||||
|
||||
public static long containerSeed(long lootSeed, int x, int y, int z) {
|
||||
long seed = mix(lootSeed ^ CONTAINER_SALT);
|
||||
seed = mix(seed ^ ((long) x * 0xD6E8FEB86659FD93L));
|
||||
seed = mix(seed ^ ((long) y * 0xA5A3564E27F886A7L));
|
||||
return mix(seed ^ ((long) z * 0x8CB92BA72F3D8DD7L));
|
||||
}
|
||||
|
||||
/** The random stream of one loot table at one position; {@code tableIdentity} names the table (its key, else its name). */
|
||||
public static RNG tableRng(long lootSeed, String tableIdentity, int x, int y, int z) {
|
||||
return new RNG(tableSeed(lootSeed, tableIdentity, x, y, z));
|
||||
}
|
||||
|
||||
public static long tableSeed(long lootSeed, String tableIdentity, int x, int y, int z) {
|
||||
return mix(containerSeed(lootSeed, x, y, z) ^ stableHash(tableIdentity) ^ TABLE_SALT);
|
||||
}
|
||||
|
||||
public static boolean spatialOneIn(
|
||||
long lootSeed,
|
||||
String tableIdentity,
|
||||
int entryIndex,
|
||||
int x,
|
||||
int y,
|
||||
int z,
|
||||
long rarity
|
||||
) {
|
||||
if (rarity <= 1L) {
|
||||
return true;
|
||||
}
|
||||
long roll = mix(tableSeed(lootSeed, tableIdentity, x, y, z) ^ ((long) entryIndex * ENTRY_SALT));
|
||||
return new RNG(roll).nextLong(rarity) == 0L;
|
||||
}
|
||||
|
||||
public static long combinedRarity(int tableRarity, int entryRarity) {
|
||||
long table = Math.max(1, tableRarity);
|
||||
long entry = Math.max(1, entryRarity);
|
||||
if (table > Long.MAX_VALUE / entry) {
|
||||
return Long.MAX_VALUE;
|
||||
}
|
||||
return table * entry;
|
||||
}
|
||||
|
||||
public static boolean oneIn(RNG rng, int rarity) {
|
||||
int bound = Math.max(1, rarity);
|
||||
return bound == 1 || rng.nextInt(bound) == 0;
|
||||
}
|
||||
|
||||
public static int inclusive(RNG rng, int first, int second) {
|
||||
int lower = Math.min(first, second);
|
||||
int upper = Math.max(first, second);
|
||||
if (lower == upper) {
|
||||
return lower;
|
||||
}
|
||||
long span = (long) upper - lower + 1L;
|
||||
return (int) (lower + rng.nextLong(span));
|
||||
}
|
||||
|
||||
public static <T> T pickWeighted(List<T> choices, ToIntFunction<T> weight, RNG rng) {
|
||||
long total = 0L;
|
||||
for (T choice : choices) {
|
||||
int value = Math.max(0, weight.applyAsInt(choice));
|
||||
total = Long.MAX_VALUE - total < value ? Long.MAX_VALUE : total + value;
|
||||
}
|
||||
if (total <= 0L) {
|
||||
return null;
|
||||
}
|
||||
long pull = rng.nextLong(total);
|
||||
for (T choice : choices) {
|
||||
pull -= Math.max(0, weight.applyAsInt(choice));
|
||||
if (pull < 0L) {
|
||||
return choice;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T> void scaleSources(List<T> sources, double multiplier, RNG rng) {
|
||||
if (!Double.isFinite(multiplier) || multiplier < 0D) {
|
||||
throw new IllegalArgumentException("Effective loot source multiplier must be finite and non-negative, got "
|
||||
+ multiplier + ".");
|
||||
}
|
||||
if (sources.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (sources.size() > MAX_SCALED_SOURCE_COUNT) {
|
||||
throw new IllegalArgumentException("Loot source scaling starts above the maximum of "
|
||||
+ MAX_SCALED_SOURCE_COUNT + " sources: " + sources.size() + ".");
|
||||
}
|
||||
double scaledSize = sources.size() * multiplier;
|
||||
if (!Double.isFinite(scaledSize) || scaledSize > MAX_SCALED_SOURCE_COUNT) {
|
||||
throw new IllegalArgumentException("Loot source scaling exceeds the maximum of "
|
||||
+ MAX_SCALED_SOURCE_COUNT + " sources: " + sources.size() + " * " + multiplier + ".");
|
||||
}
|
||||
int target = (int) Math.round(scaledSize);
|
||||
if (target == sources.size()) {
|
||||
return;
|
||||
}
|
||||
List<T> original = new ArrayList<>(sources);
|
||||
int[] order = new int[original.size()];
|
||||
if (target < original.size()) {
|
||||
shrinkSources(sources, original, order, target, rng);
|
||||
return;
|
||||
}
|
||||
expandSources(sources, original, order, target, rng);
|
||||
}
|
||||
|
||||
private static <T> void shrinkSources(List<T> sources, List<T> original, int[] order, int target, RNG rng) {
|
||||
shuffleOrder(order, rng);
|
||||
boolean[] selected = new boolean[original.size()];
|
||||
for (int index = 0; index < target; index++) {
|
||||
selected[order[index]] = true;
|
||||
}
|
||||
sources.clear();
|
||||
for (int index = 0; index < original.size(); index++) {
|
||||
if (selected[index]) {
|
||||
sources.add(original.get(index));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> void expandSources(List<T> sources, List<T> original, int[] order, int target, RNG rng) {
|
||||
while (sources.size() < target) {
|
||||
shuffleOrder(order, rng);
|
||||
int additions = Math.min(target - sources.size(), original.size());
|
||||
for (int index = 0; index < additions; index++) {
|
||||
sources.add(original.get(order[index]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void shuffleOrder(int[] order, RNG rng) {
|
||||
for (int index = 0; index < order.length; index++) {
|
||||
order[index] = index;
|
||||
}
|
||||
for (int index = 0; index < order.length - 1; index++) {
|
||||
int selected = index + rng.nextInt(order.length - index);
|
||||
int previous = order[index];
|
||||
order[index] = order[selected];
|
||||
order[selected] = previous;
|
||||
}
|
||||
}
|
||||
|
||||
private static long stableHash(String value) {
|
||||
long hash = 0xCBF29CE484222325L;
|
||||
for (int i = 0; i < value.length(); i++) {
|
||||
hash ^= value.charAt(i);
|
||||
hash *= 0x100000001B3L;
|
||||
}
|
||||
return mix(hash);
|
||||
}
|
||||
|
||||
private static long mix(long value) {
|
||||
long mixed = value;
|
||||
mixed = (mixed ^ (mixed >>> 30)) * 0xBF58476D1CE4E5B9L;
|
||||
mixed = (mixed ^ (mixed >>> 27)) * 0x94D049BB133111EBL;
|
||||
return mixed ^ (mixed >>> 31);
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ import art.arcane.iris.engine.framework.GenerationSessionLease;
|
||||
import art.arcane.iris.engine.framework.Locator;
|
||||
import art.arcane.iris.core.modules.ModuleServices;
|
||||
import art.arcane.iris.core.modules.PlatformBlockStates;
|
||||
import art.arcane.iris.engine.framework.LootResolver;
|
||||
import art.arcane.iris.builtin.loot.LootResolver;
|
||||
import art.arcane.iris.platform.bukkit.BukkitItemStacks;
|
||||
import art.arcane.iris.engine.framework.WrongEngineBroException;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ package art.arcane.iris.util.common.director.specialhandlers;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.PackModulesException;
|
||||
import art.arcane.iris.core.pack.PackDirectoryResolver;
|
||||
import art.arcane.iris.engine.spawn.SpawnResources;
|
||||
import art.arcane.iris.builtin.spawn.EntityDefinition;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.util.common.director.DirectorParameterHandler;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
@@ -70,7 +70,7 @@ public final class EntityKeyHandler implements DirectorParameterHandler<String>
|
||||
/** A pack whose modules fail to load has no entities to offer; its failure was reported when it loaded. */
|
||||
private static void addEntityKeys(Set<String> keys, IrisData data) {
|
||||
try {
|
||||
keys.addAll(SpawnResources.entityKeys(data));
|
||||
data.getPackResources().ids(EntityDefinition.class).forEach(id -> keys.add(id.path()));
|
||||
} catch (PackModulesException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.util.stream.Stream;
|
||||
* every class {@code builtin-modules.txt} lists ({@code module} lines with their nested classes, {@code include} patterns)
|
||||
* and the entry points in order. Tests load it from a pack's {@code modules} folder without building IrisModule.
|
||||
*/
|
||||
final class BuiltInModulesJar {
|
||||
public final class BuiltInModulesJar {
|
||||
private static final String LIST_PROPERTY = "iris.builtinModulesList";
|
||||
private static final String SERVICE_ENTRY = "META-INF/services/com.volmit.IrisModule";
|
||||
private static final String JAR_NAME = "iris-builtins.jar";
|
||||
@@ -45,7 +45,7 @@ final class BuiltInModulesJar {
|
||||
}
|
||||
|
||||
/** Writes {@code <pack>/modules/iris-builtins.jar} and returns its entry classes. */
|
||||
static List<String> writeInto(Path pack) throws IOException {
|
||||
public static List<String> writeInto(Path pack) throws IOException {
|
||||
List<String> modules = new ArrayList<>();
|
||||
List<PathMatcher> classes = new ArrayList<>();
|
||||
for (String line : Files.readAllLines(Path.of(System.getProperty(LIST_PROPERTY)))) {
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* 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.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.loot.BlockDropSettings;
|
||||
import art.arcane.iris.builtin.loot.LootSettings;
|
||||
import art.arcane.iris.builtin.loot.LootTable;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
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.engine.loot.BlockDropping;
|
||||
import art.arcane.iris.engine.loot.LootResources;
|
||||
import art.arcane.iris.engine.modifier.ApiChunk;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.block.BlockSpec;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.host.ModuleHost;
|
||||
import com.volmit.service.BlockDrops;
|
||||
import com.volmit.service.Loot;
|
||||
import com.volmit.world.BlockPosition;
|
||||
import com.volmit.world.PackWorld;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** The services of the loot and spawn modules, loaded from the built-ins jar, answer about worlds Iris runs through the live view of the world. */
|
||||
public class BuiltInModulesJarServicesTest {
|
||||
private static final int X = 10;
|
||||
private static final int Y = 70;
|
||||
private static final int Z = -20;
|
||||
private static final BlockPosition AT = new BlockPosition(X, Y, Z);
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
private Engine engine;
|
||||
private IrisBiome biome;
|
||||
private IrisDimension dimension;
|
||||
private PackWorld world;
|
||||
private ModuleResourceFixture tables;
|
||||
|
||||
@Before
|
||||
public void buildWorld() {
|
||||
engine = mock(Engine.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
tables = ModuleResourceFixture.serve(data);
|
||||
BlockRegistry blocks = mock(BlockRegistry.class);
|
||||
when(blocks.resolve(any(BlockState.class))).thenAnswer(invocation -> invocation.getArgument(0));
|
||||
when(blocks.resolve(any(BlockSpec.class))).thenAnswer(invocation -> BlockState.parse("minecraft:" + invocation.<BlockSpec>getArgument(0).block()));
|
||||
when(data.getPackResources().blocks()).thenReturn(blocks);
|
||||
when(data.getPackResources().items()).thenReturn(item -> OptionalInt.of(0));
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getMinHeight()).thenReturn(-64);
|
||||
IrisComplex complex = mock(IrisComplex.class, RETURNS_DEEP_STUBS);
|
||||
when(complex.getHeightStream().get(X, Z)).thenReturn(64D);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
SeedManager seeds = mock(SeedManager.class);
|
||||
when(seeds.getLoot()).thenReturn(5L);
|
||||
when(engine.getSeedManager()).thenReturn(seeds);
|
||||
biome = bare(IrisBiome.class);
|
||||
dimension = bare(IrisDimension.class);
|
||||
when(engine.getBiome(X, Y, Z)).thenReturn(biome);
|
||||
when(engine.getSurfaceBiome(X, Z)).thenReturn(biome);
|
||||
IrisRegion region = bare(IrisRegion.class);
|
||||
when(engine.getRegion(X, Z)).thenReturn(region);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
world = new EngineGeneration(engine).world();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void blockDropsOfTheBiomeAtABrokenBlockComeFromTheJarsModule() throws IOException {
|
||||
when(biome.getModuleSettings()).thenReturn(BuiltInPack.settings(TestSettings.of(BlockDropSettings.class, """
|
||||
{"drops": [{"blocks": [{"block": "stone"}], "replaceVanillaDrops": true,
|
||||
"drops": [{"type": "gravel", "minAmount": 2, "maxAmount": 2}]}]}""")));
|
||||
|
||||
try (LoadedPack loaded = load()) {
|
||||
BlockDrops drops = loaded.catalog().services(BlockDrops.class).getFirst();
|
||||
|
||||
assertEquals(BlockDropping.class.getName(), drops.getClass().getName());
|
||||
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(2, result.drops().getFirst().amount());
|
||||
assertTrue(result.replacesVanillaDrops());
|
||||
assertEquals(BlockDrops.Result.NONE, drops.drops(world, new BlockDrops.Broken(AT, new BlockState("minecraft:dirt"))));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aContainersTablesAreThoseOfTheDimensionAtItsColumn() throws IOException {
|
||||
when(dimension.getModuleSettings()).thenReturn(BuiltInPack.settings(TestSettings.of(LootSettings.class, "{\"tables\": [\"dungeon/chest\"]}")));
|
||||
tables.resource(LootResources.TABLES, "dungeon/chest", TestSettings.of(LootTable.class, "{}"));
|
||||
|
||||
try (LoadedPack loaded = load()) {
|
||||
Loot loot = loaded.catalog().services(Loot.class).getFirst();
|
||||
|
||||
List<Loot.Source> tables = loot.tables(world, new Loot.Site(AT, null, false, false));
|
||||
|
||||
assertEquals(List.of(new Loot.Table("dungeon/chest")), tables);
|
||||
}
|
||||
}
|
||||
|
||||
private LoadedPack load() throws IOException {
|
||||
Path pack = BuiltInPack.newPackFolder(folder);
|
||||
BuiltInModulesJar.writeInto(pack);
|
||||
return LoadedPack.load(pack, ModuleHost.of(ApiChunk.standIns())
|
||||
.exposing(IrisModuleHost.EXPOSED_PACKAGES.toArray(String[]::new))
|
||||
.copyingJarsTo(folder.newFolder().toPath()));
|
||||
}
|
||||
|
||||
private static <T extends IrisRegistrant> T bare(Class<T> type) {
|
||||
T owner = mock(type);
|
||||
when(owner.getModuleSettings()).thenReturn(ModuleSettings.NONE);
|
||||
return owner;
|
||||
}
|
||||
}
|
||||
@@ -21,9 +21,11 @@ package art.arcane.iris.core.modules;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import art.arcane.iris.engine.loot.LootModule;
|
||||
import art.arcane.iris.engine.modifier.MatterModule;
|
||||
import art.arcane.iris.engine.modifier.PerfectionModule;
|
||||
import art.arcane.iris.engine.modifier.PostModule;
|
||||
import art.arcane.iris.engine.spawn.SpawnModule;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.host.LoadedPack;
|
||||
@@ -51,7 +53,7 @@ public final class BuiltInPack {
|
||||
* with Iris; {@code BuiltInModulesJarTest} loads the same modules from the jar instead.
|
||||
*/
|
||||
public static List<IrisModule> jarModules() {
|
||||
return List.of(new PostModule(), new PerfectionModule(), new MatterModule());
|
||||
return List.of(new PostModule(), new PerfectionModule(), new MatterModule(), new LootModule(), new SpawnModule());
|
||||
}
|
||||
|
||||
/** Every built-in module: Iris's own and the compiled-in copies of the jar's ({@link #jarModules()}). */
|
||||
|
||||
@@ -37,7 +37,7 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
/** The services and hooks Iris's built-in modules provide, which Iris core asks instead of their features. */
|
||||
public class BuiltInServicesTest {
|
||||
private static final FeatureCatalog BUILT_INS = ModuleResourceFixture.catalogOf(IrisModuleHost.builtInModules().toArray(IrisModule[]::new));
|
||||
private static final FeatureCatalog BUILT_INS = ModuleResourceFixture.catalogOf(BuiltInPack.allBuiltIns().toArray(IrisModule[]::new));
|
||||
|
||||
@Test
|
||||
public void objectsTellWhichObjectsAChunkGets() {
|
||||
|
||||
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
* 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.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.LiveWorld;
|
||||
import art.arcane.iris.builtin.LiveWorld.BiomeKind;
|
||||
import art.arcane.iris.builtin.LiveWorld.Level;
|
||||
import art.arcane.iris.builtin.LiveWorld.ObjectLoots;
|
||||
import art.arcane.iris.builtin.LiveWorld.Sky;
|
||||
import art.arcane.iris.builtin.loot.LootSettings;
|
||||
import art.arcane.iris.builtin.loot.ObjectLoot;
|
||||
import art.arcane.iris.builtin.spawn.SpawnCooldowns;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineGeneration;
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.framework.PlacedObject;
|
||||
import art.arcane.iris.engine.mantle.EngineMantle;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.engine.object.runtime.IrisEngineData;
|
||||
import art.arcane.iris.engine.object.value.IrisPosition;
|
||||
import art.arcane.iris.engine.object.world.IrisWorld;
|
||||
import art.arcane.iris.engine.object.world.biome.InferredType;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.spi.PlatformWorld;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.volmit.world.BlockPosition;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
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;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** What the built-in services ask a running world: the engine's answers for a block, as values. */
|
||||
public class IrisLiveWorldTest {
|
||||
private static final int X = 10;
|
||||
private static final int Y = 70;
|
||||
private static final int Z = -20;
|
||||
private static final int BOTTOM = -64;
|
||||
|
||||
private Engine engine;
|
||||
private LiveWorld live;
|
||||
|
||||
@BeforeClass
|
||||
public static void bindPlatform() {
|
||||
UsableBlockPlatform.bind();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void unbindPlatform() {
|
||||
UsableBlockPlatform.unbind();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void buildWorld() {
|
||||
engine = mock(Engine.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
ModuleResourceFixture.serve(data);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getMinHeight()).thenReturn(BOTTOM);
|
||||
live = LiveWorld.of(new EngineGeneration(engine).world());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyLevelReadsTheSettingsOfItsOwnerAtTheBlock() {
|
||||
IrisDimension dimension = owner(IrisDimension.class, "dimension");
|
||||
IrisRegion region = owner(IrisRegion.class, "region");
|
||||
IrisBiome surface = owner(IrisBiome.class, "surface");
|
||||
IrisBiome here = owner(IrisBiome.class, "here");
|
||||
IrisBiome cave = owner(IrisBiome.class, "cave");
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getRegion(X, Z)).thenReturn(region);
|
||||
when(engine.getSurfaceBiome(X, Z)).thenReturn(surface);
|
||||
when(engine.getBiome(X, Y, Z)).thenReturn(here);
|
||||
when(engine.getCaveBiome(X, Y, Z)).thenReturn(cave);
|
||||
|
||||
assertEquals(List.of("dimension", "region", "surface", "here", "cave"), List.of(
|
||||
tableAt(Level.DIMENSION), tableAt(Level.REGION), tableAt(Level.SURFACE_BIOME), tableAt(Level.BIOME), tableAt(Level.CAVE_BIOME)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aLevelWithoutSettingsOrOwnerHasNone() {
|
||||
IrisRegion bare = mock(IrisRegion.class);
|
||||
when(bare.getModuleSettings()).thenReturn(ModuleSettings.NONE);
|
||||
when(engine.getRegion(X, Z)).thenReturn(bare);
|
||||
|
||||
assertTrue(live.settings(LootSettings.class, Level.REGION, X, Y, Z).isEmpty());
|
||||
assertTrue(live.settings(LootSettings.class, Level.BIOME, X, Y, Z).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biomesAreAskedByTheIdsThePackGivesThem() {
|
||||
IrisBiome surface = mock(IrisBiome.class);
|
||||
when(surface.getLoadKey()).thenReturn("Plains/Meadow");
|
||||
when(surface.getInferredType()).thenReturn(InferredType.SHORE);
|
||||
when(engine.getSurfaceBiome(X, Z)).thenReturn(surface);
|
||||
when(engine.getCaveBiome(X, Y, Z)).thenReturn(null);
|
||||
|
||||
assertEquals(engine.getData().getPackResources().idOf("Plains/Meadow"), live.surfaceBiome(X, Z));
|
||||
assertEquals(live.surfaceBiome(X, Z), live.caveBiome(X, Y, Z));
|
||||
assertEquals(BiomeKind.SHORE, live.surfaceKind(X, Z));
|
||||
assertEquals(BOTTOM, live.bottomY());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theSkyIsTheWorldsTimeAndWeatherOnceThereIsAPlatformWorld() {
|
||||
IrisWorld world = mock(IrisWorld.class);
|
||||
when(engine.getWorld()).thenReturn(world);
|
||||
assertEquals(Optional.empty(), live.sky());
|
||||
|
||||
PlatformWorld platform = mock(PlatformWorld.class);
|
||||
when(platform.getTime()).thenReturn(18000L);
|
||||
when(platform.isThundering()).thenReturn(true);
|
||||
when(world.platformWorld()).thenReturn(platform);
|
||||
|
||||
assertEquals(Optional.of(new Sky(18000L, false, true)), live.sky());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void caveFloorsAreHeightsAboveTheBottom() {
|
||||
EngineMantle mantle = mock(EngineMantle.class);
|
||||
when(engine.getMantle()).thenReturn(mantle);
|
||||
when(mantle.findMarkers(2, 3, art.arcane.volmlib.util.matter.slices.MarkerMatter.CAVE_FLOOR))
|
||||
.thenReturn(new KList<>(new IrisPosition(40, 0, 50), new IrisPosition(41, 30, 51)));
|
||||
|
||||
assertEquals(List.of(new BlockPosition(40, 64, 50), new BlockPosition(41, 94, 51)), live.caveFloors(2, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anObjectsLootIsWhatItsPlacementDefines() {
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement();
|
||||
placement.getLoot().add(new ObjectLoot("chest", 2));
|
||||
placement.setOverrideGlobalLoot(true);
|
||||
when(engine.getObjectPlacement(X, Y, Z)).thenReturn(new PlacedObject(placement, null, 1, X, Z));
|
||||
when(engine.getObjectPlacement(X + 1, Y, Z)).thenReturn(new PlacedObject(null, null, 1, X + 1, Z));
|
||||
|
||||
ObjectLoots loots = live.objectLoots(X, Y, Z).orElseThrow();
|
||||
|
||||
assertEquals(1, loots.packTables().size());
|
||||
assertEquals("chest", loots.packTables().getFirst().name());
|
||||
assertTrue(loots.platformTables().isEmpty());
|
||||
assertTrue(loots.overridesGlobalLoot());
|
||||
assertTrue(loots.defined());
|
||||
assertTrue(live.objectLoots(X + 1, Y, Z).isEmpty());
|
||||
assertTrue(live.objectLoots(X + 2, Y, Z).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spawnCooldownsCountPerWorldAndPerChunkAndForgetWhatRanOut() {
|
||||
IrisEngineData saved = new IrisEngineData();
|
||||
when(engine.getEngineData()).thenReturn(saved);
|
||||
SpawnCooldowns cooldowns = live.spawnCooldowns();
|
||||
|
||||
assertTrue(cooldowns.canSpawn("wolves", 600_000L));
|
||||
cooldowns.spawned("wolves");
|
||||
cooldowns.spawnedInChunk(3, 4, "wolves");
|
||||
cooldowns.spawned("gone");
|
||||
|
||||
assertFalse(cooldowns.canSpawn("wolves", 600_000L));
|
||||
assertFalse(cooldowns.canSpawnInChunk(3, 4, "wolves", 600_000L));
|
||||
assertTrue(cooldowns.canSpawnInChunk(3, 5, "wolves", 600_000L));
|
||||
|
||||
cooldowns.forgetExpired(spawner -> spawner.equals("wolves") ? 600_000L : -1L);
|
||||
|
||||
assertFalse("a cooldown still running stays", cooldowns.canSpawn("wolves", 600_000L));
|
||||
assertFalse(cooldowns.canSpawnInChunk(3, 4, "wolves", 600_000L));
|
||||
assertTrue("a spawner the pack lacks is forgotten", cooldowns.canSpawn("gone", 600_000L));
|
||||
}
|
||||
|
||||
private <T extends IrisRegistrant> T owner(Class<T> type, String table) {
|
||||
T owner = mock(type);
|
||||
LootSettings loot = TestSettings.of(LootSettings.class, "{\"tables\": [\"" + table + "\"]}");
|
||||
when(owner.getModuleSettings()).thenReturn(BuiltInPack.settings(loot));
|
||||
return owner;
|
||||
}
|
||||
|
||||
private String tableAt(Level level) {
|
||||
return live.settings(LootSettings.class, level, X, Y, Z).orElseThrow().tables().getFirst();
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import art.arcane.iris.builtin.spawn.EntityDefinition;
|
||||
import art.arcane.iris.builtin.spawn.SpawnMarker;
|
||||
import art.arcane.iris.builtin.spawn.Spawner;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.BuiltInModulesJar;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
@@ -123,6 +124,7 @@ public class ModuleResourceClosureTest {
|
||||
write(pack, "entities/beta/sentinel.json", "{\"type\":\"minecraft:skeleton\"}");
|
||||
write(pack, "entities/cow.json", "{\"type\":\"minecraft:cow\"}");
|
||||
write(pack, "markers/camp.json", "{\"spawners\":[\"marker/spawner\"]}");
|
||||
BuiltInModulesJar.writeInto(pack.toPath());
|
||||
return pack.toPath();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import art.arcane.iris.core.modules.BuiltInPack;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineGeneration;
|
||||
import art.arcane.iris.builtin.loot.LootSettings;
|
||||
import art.arcane.iris.builtin.loot.LootTable;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
@@ -72,8 +73,8 @@ public class LootEnvironmentPinTest {
|
||||
surface = biome("surface");
|
||||
cave = biome("cave");
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(complex.getRegionStream().get(X, Z)).thenReturn(region);
|
||||
when(complex.getTrueBiomeStream().get(X, Z)).thenReturn(surface);
|
||||
when(engine.getRegion(X, Z)).thenReturn(region);
|
||||
when(engine.getSurfaceBiome(X, Z)).thenReturn(surface);
|
||||
when(complex.getHeightStream().get(X, Z)).thenReturn(64D);
|
||||
when(engine.getCaveBiome(X, CAVE_Y, Z)).thenReturn(cave);
|
||||
when(engine.getCaveBiome(X, SURFACE_Y, Z)).thenReturn(surface);
|
||||
@@ -112,7 +113,7 @@ public class LootEnvironmentPinTest {
|
||||
|
||||
private List<String> identities(boolean objectLootDefined, int y) {
|
||||
List<String> sources = new ArrayList<>();
|
||||
LootTables.resolveEnvironmentSources(sources, engine, new RNG(19L), X, y, Z, objectLootDefined, key -> key);
|
||||
LootTables.resolveEnvironmentSources(sources, new EngineGeneration(engine).world(), new RNG(19L), X, y, Z, objectLootDefined, key -> key);
|
||||
return sources;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package art.arcane.iris.engine.loot;
|
||||
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.LootResolver;
|
||||
import art.arcane.iris.engine.framework.EngineGeneration;
|
||||
import art.arcane.iris.builtin.loot.LootResolver;
|
||||
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
@@ -18,6 +19,7 @@ import com.volmit.config.Desc;
|
||||
import com.volmit.config.MaxNumber;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.item.ItemRegistry;
|
||||
import com.volmit.world.PackWorld;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -107,7 +109,7 @@ public class LootResolverTest {
|
||||
|
||||
LootTables.resolveEnvironmentSources(
|
||||
sources,
|
||||
fixture.engine,
|
||||
fixture.world,
|
||||
new RNG(19L),
|
||||
10,
|
||||
70,
|
||||
@@ -126,7 +128,7 @@ public class LootResolverTest {
|
||||
|
||||
LootTables.resolveEnvironmentSources(
|
||||
sources,
|
||||
fixture.engine,
|
||||
fixture.world,
|
||||
new RNG(19L),
|
||||
10,
|
||||
70,
|
||||
@@ -264,6 +266,7 @@ public class LootResolverTest {
|
||||
|
||||
private static final class ResolutionFixture {
|
||||
private final Engine engine = mock(Engine.class, RETURNS_DEEP_STUBS);
|
||||
private final PackWorld world;
|
||||
|
||||
private ResolutionFixture() {
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
@@ -282,10 +285,11 @@ public class LootResolverTest {
|
||||
when(region.getModuleSettings()).thenReturn(fallbackTo("region"));
|
||||
when(surface.getModuleSettings()).thenReturn(fallbackTo("surface"));
|
||||
when(surface.getLoadKey()).thenReturn("surface");
|
||||
when(complex.getRegionStream().get(10, 20)).thenReturn(region);
|
||||
when(complex.getTrueBiomeStream().get(10, 20)).thenReturn(surface);
|
||||
when(engine.getRegion(10, 20)).thenReturn(region);
|
||||
when(engine.getSurfaceBiome(10, 20)).thenReturn(surface);
|
||||
when(complex.getHeightStream().get(10, 20)).thenReturn(64D);
|
||||
when(engine.getCaveBiome(10, 70, 20)).thenReturn(surface);
|
||||
world = new EngineGeneration(engine).world();
|
||||
}
|
||||
|
||||
private static ModuleSettings fallbackTo(String table) {
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.engine.loot;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.BuiltInModulesJar;
|
||||
import art.arcane.iris.core.project.ModuleResourceSchemas;
|
||||
import art.arcane.iris.core.project.SchemaTestPlatform;
|
||||
import art.arcane.iris.builtin.loot.LootTable;
|
||||
@@ -52,7 +53,7 @@ public class LootResourcesTest {
|
||||
|
||||
assertEquals(List.of("iris:loot/table"), catalog.resourceKinds().stream().map(registration -> registration.kind().id().toString())
|
||||
.filter(id -> id.startsWith("iris:loot/")).toList());
|
||||
assertTrue(catalog.validators().stream().map(ValidatorRegistration::validator).anyMatch(LootValidator.class::isInstance));
|
||||
assertTrue(catalog.validators().stream().map(ValidatorRegistration::validator).anyMatch(validator -> validator.getClass().getName().equals(LootValidator.class.getName())));
|
||||
assertFalse(data.getLoaders().containsKey(LootTable.class));
|
||||
} finally {
|
||||
data.close();
|
||||
@@ -64,18 +65,18 @@ public class LootResourcesTest {
|
||||
Path pack = lootPack("tables");
|
||||
IrisData data = IrisData.openValidation(pack.toFile());
|
||||
try {
|
||||
LootTable table = LootResources.table(data, "dungeon/chest");
|
||||
LootTable table = LootResources.table(data.getPackResources(), "dungeon/chest");
|
||||
|
||||
assertEquals("Chest", table.name());
|
||||
assertEquals(1, table.loot().size());
|
||||
assertEquals("stick", table.loot().getFirst().type());
|
||||
assertEquals(List.of("dungeon/chest"), LootResources.tableKeys(data));
|
||||
assertNull(LootResources.table(data, "missing"));
|
||||
assertNull(LootResources.table(data, " "));
|
||||
assertEquals(List.of("dungeon/chest"), LootResources.tableKeys(data.getPackResources()));
|
||||
assertNull(LootResources.table(data.getPackResources(), "missing"));
|
||||
assertNull(LootResources.table(data.getPackResources(), " "));
|
||||
|
||||
write(pack, "loot/dungeon/chest.json", "{\"name\":\"Renamed\"}");
|
||||
data.dump();
|
||||
assertEquals("Renamed", LootResources.table(data, "dungeon/chest").name());
|
||||
assertEquals("Renamed", LootResources.table(data.getPackResources(), "dungeon/chest").name());
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
@@ -101,6 +102,7 @@ public class LootResourcesTest {
|
||||
write(pack.toPath(), "regions/region.json", "{\"landBiomes\":[\"biome\"]}");
|
||||
write(pack.toPath(), "biomes/biome.json", "{\"name\":\"Biome\"}");
|
||||
write(pack.toPath(), "loot/dungeon/chest.json", "{\"name\":\"Chest\",\"loot\":[{\"type\":\"stick\"}]}");
|
||||
BuiltInModulesJar.writeInto(pack.toPath());
|
||||
return pack.toPath();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,55 +1,68 @@
|
||||
package art.arcane.iris.engine.loot;
|
||||
|
||||
import art.arcane.iris.builtin.loot.LootEntry;
|
||||
import art.arcane.iris.builtin.loot.LootSettings;
|
||||
import art.arcane.iris.builtin.loot.LootTable;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import com.volmit.FeatureAttachment.Target;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.validation.Problem;
|
||||
import com.volmit.validation.Severity;
|
||||
import org.junit.Rule;
|
||||
import com.volmit.validation.ValidationContext;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class LootValidatorTest {
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
private ModuleResourceFixture tables;
|
||||
private PackResources resources;
|
||||
private final List<Entry<LootSettings>> references = new ArrayList<>();
|
||||
|
||||
@Before
|
||||
public void servePack() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
tables = ModuleResourceFixture.serve(data);
|
||||
resources = data.getPackResources();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void acceptsValidLootTableAndReference() throws Exception {
|
||||
File pack = temporaryFolder.newFolder("pack");
|
||||
write(pack, "loot/global/clutter.json", "{\"name\":\"Clutter\",\"minPicked\":1,\"maxPicked\":2,"
|
||||
public void acceptsValidLootTableAndReference() {
|
||||
table("global/clutter", "{\"name\":\"Clutter\",\"minPicked\":1,\"maxPicked\":2,"
|
||||
+ "\"loot\":[{\"type\":\"stick\",\"rarity\":2,\"minAmount\":1,\"maxAmount\":3}]}");
|
||||
write(pack, "dimensions/main.json", "{\"loot\":{\"mode\":\"FALLBACK\",\"multiplier\":0.5,"
|
||||
+ "\"tables\":[\"global/clutter\"]}}");
|
||||
reference(Target.DIMENSION, "main", "{\"mode\":\"FALLBACK\",\"multiplier\":0.5,\"tables\":[\"global/clutter\"]}");
|
||||
|
||||
assertTrue(errors(pack).isEmpty());
|
||||
assertTrue(errors().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsMissingLootReference() throws Exception {
|
||||
File pack = temporaryFolder.newFolder("pack");
|
||||
write(pack, "dimensions/main.json", "{\"loot\":{\"tables\":[\"missing\"]}}");
|
||||
public void rejectsMissingLootReference() {
|
||||
reference(Target.DIMENSION, "main", "{\"tables\":[\"missing\"]}");
|
||||
|
||||
assertEquals(List.of("Dimension 'main'.loot.tables[0] references missing loot table 'missing'."),
|
||||
errors(pack));
|
||||
assertEquals(List.of("Dimension 'main'.loot.tables[0] references missing loot table 'missing'."), errors());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsInvalidLootBoundsAndEmptyEntries() throws Exception {
|
||||
File pack = temporaryFolder.newFolder("pack");
|
||||
write(pack, "loot/broken.json", "{\"rarity\":0,\"minPicked\":4,\"maxPicked\":2,\"maxTries\":0,"
|
||||
public void rejectsInvalidLootBoundsAndEmptyEntries() {
|
||||
table("broken", "{\"rarity\":0,\"minPicked\":4,\"maxPicked\":2,\"maxTries\":0,"
|
||||
+ "\"loot\":[{\"type\":\"\",\"rarity\":0,\"minAmount\":3,\"maxAmount\":1,"
|
||||
+ "\"enchantments\":[{\"enchantment\":\"\",\"minLevel\":4,\"maxLevel\":2,\"chance\":2}]}]}");
|
||||
|
||||
List<String> errors = errors(pack);
|
||||
List<String> errors = errors();
|
||||
|
||||
assertTrue(errors.stream().anyMatch(error -> error.contains(".rarity must be at least 1")));
|
||||
assertTrue(errors.stream().anyMatch(error -> error.contains(".minPicked must not exceed")));
|
||||
@@ -61,45 +74,42 @@ public class LootValidatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsInvalidReferenceModeAndMultiplier() throws Exception {
|
||||
File pack = temporaryFolder.newFolder("pack");
|
||||
write(pack, "dimensions/main.json", "{\"loot\":{\"mode\":\"MERGE\",\"multiplier\":-1,\"tables\":[]}}");
|
||||
public void aTableWithoutEntriesIsRejected() {
|
||||
table("empty", "{\"name\":\"Empty\"}");
|
||||
|
||||
List<String> errors = errors(pack);
|
||||
|
||||
assertEquals(2, errors.size());
|
||||
assertTrue(errors.get(0).contains(".mode must be"));
|
||||
assertTrue(errors.get(1).contains(".multiplier must be"));
|
||||
assertEquals(List.of("Loot table 'empty'.loot must be a non-empty array."), errors());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enforcesPublishedLootMultiplierCap() throws Exception {
|
||||
File acceptedPack = temporaryFolder.newFolder("accepted-pack");
|
||||
write(acceptedPack, "dimensions/main.json", "{\"loot\":{\"multiplier\":16,\"tables\":[]}}");
|
||||
assertTrue(errors(acceptedPack).isEmpty());
|
||||
public void rejectsInvalidReferenceMultiplier() {
|
||||
reference(Target.DIMENSION, "main", "{\"multiplier\":-1,\"tables\":[]}");
|
||||
|
||||
File rejectedPack = temporaryFolder.newFolder("rejected-pack");
|
||||
write(rejectedPack, "dimensions/main.json", "{\"loot\":{\"multiplier\":16.01,\"tables\":[]}}");
|
||||
assertEquals(List.of("Dimension 'main'.loot.multiplier must be a finite number from 0 to 16."),
|
||||
errors(rejectedPack));
|
||||
assertEquals(List.of("Dimension 'main'.loot.multiplier must be a finite number from 0 to 16."), errors());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void acceptsPublishedLootWorkBounds() throws Exception {
|
||||
File pack = temporaryFolder.newFolder("pack");
|
||||
write(pack, "loot/boundary.json", "{\"minPicked\":64,\"maxPicked\":64,\"maxTries\":256,"
|
||||
public void enforcesPublishedLootMultiplierCap() {
|
||||
reference(Target.DIMENSION, "accepted", "{\"multiplier\":16,\"tables\":[]}");
|
||||
assertTrue(errors().isEmpty());
|
||||
|
||||
reference(Target.DIMENSION, "rejected", "{\"multiplier\":16.01,\"tables\":[]}");
|
||||
assertEquals(List.of("Dimension 'rejected'.loot.multiplier must be a finite number from 0 to 16."), errors());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void acceptsPublishedLootWorkBounds() {
|
||||
table("boundary", "{\"minPicked\":64,\"maxPicked\":64,\"maxTries\":256,"
|
||||
+ "\"loot\":[{\"type\":\"stone\",\"minAmount\":64,\"maxAmount\":64}]}");
|
||||
|
||||
assertTrue(errors(pack).isEmpty());
|
||||
assertTrue(errors().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsLootWorkBoundsAbovePublishedCaps() throws Exception {
|
||||
File pack = temporaryFolder.newFolder("pack");
|
||||
write(pack, "loot/excessive.json", "{\"minPicked\":65,\"maxPicked\":65,\"maxTries\":257,"
|
||||
public void rejectsLootWorkBoundsAbovePublishedCaps() {
|
||||
table("excessive", "{\"minPicked\":65,\"maxPicked\":65,\"maxTries\":257,"
|
||||
+ "\"loot\":[{\"type\":\"stone\",\"minAmount\":65,\"maxAmount\":65}]}");
|
||||
|
||||
List<String> errors = errors(pack);
|
||||
List<String> errors = errors();
|
||||
|
||||
assertTrue(errors.contains("Loot table 'excessive'.minPicked must be at most 64."));
|
||||
assertTrue(errors.contains("Loot table 'excessive'.maxPicked must be at most 64."));
|
||||
@@ -124,43 +134,89 @@ public class LootValidatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearModeWithTablesWarnsWithoutBlocking() throws Exception {
|
||||
File pack = temporaryFolder.newFolder("clear-warn");
|
||||
write(pack, "loot/t.json", "{\"loot\":[{\"type\":\"minecraft:stone\"}]}");
|
||||
write(pack, "biomes/x.json", "{\"loot\":{\"mode\":\"CLEAR\",\"tables\":[\"t\"]}}");
|
||||
public void clearModeWithTablesWarnsWithoutBlocking() {
|
||||
table("t", "{\"loot\":[{\"type\":\"minecraft:stone\"}]}");
|
||||
reference(Target.BIOME, "x", "{\"mode\":\"CLEAR\",\"tables\":[\"t\"]}");
|
||||
|
||||
|
||||
assertTrue(errors(pack).isEmpty());
|
||||
assertTrue(errors().isEmpty());
|
||||
assertEquals(List.of("Biome 'x'.loot uses mode CLEAR and lists 1 table(s); CLEAR clears parent tables"
|
||||
+ " and contributes no tables of its own, so these entries are dead. Use REPLACE to substitute them."),
|
||||
warnings(pack));
|
||||
warnings());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearModeWithMissingTableStillBlocksOnTheDanglingKey() throws Exception {
|
||||
File pack = temporaryFolder.newFolder("clear-dangling");
|
||||
write(pack, "biomes/x.json", "{\"loot\":{\"mode\":\"CLEAR\",\"tables\":[\"missing\"]}}");
|
||||
public void clearModeWithMissingTableStillBlocksOnTheDanglingKey() {
|
||||
reference(Target.BIOME, "x", "{\"mode\":\"CLEAR\",\"tables\":[\"missing\"]}");
|
||||
|
||||
|
||||
assertTrue(errors(pack).contains(
|
||||
"Biome 'x'.loot.tables[0] references missing loot table 'missing'."));
|
||||
assertTrue(errors().contains("Biome 'x'.loot.tables[0] references missing loot table 'missing'."));
|
||||
}
|
||||
|
||||
private static List<String> errors(File pack) {
|
||||
return messages(pack, Severity.ERROR);
|
||||
@Test
|
||||
public void aTableThatFailsToLoadIsReportedWithoutStoppingTheCheck() {
|
||||
table("fine", "{\"loot\":[{\"type\":\"stone\"}]}");
|
||||
table("broken", "{\"loot\":[{\"type\":\"stone\"}]}");
|
||||
when(resources.find(LootResources.TABLES.key(new ResourceId("test", "broken")))).thenThrow(new IllegalStateException("unreadable"));
|
||||
|
||||
assertEquals(List.of("Loot table 'broken' cannot be read; the log says what is wrong with the file."), errors());
|
||||
}
|
||||
|
||||
private static List<String> warnings(File pack) {
|
||||
return messages(pack, Severity.WARNING);
|
||||
@Test
|
||||
public void referencesAreFoundByTheIdThePackGivesTheirKey() {
|
||||
table("Global/Clutter", "{\"loot\":[{\"type\":\"stick\"}]}");
|
||||
reference(Target.REGION, "plains", "{\"tables\":[\"Global/Clutter\"]}");
|
||||
|
||||
assertTrue(errors().isEmpty());
|
||||
}
|
||||
|
||||
private static List<String> messages(File pack, Severity severity) {
|
||||
return LootValidator.check(pack).stream().filter(problem -> problem.severity() == severity).map(Problem::message).toList();
|
||||
private void table(String key, String json) {
|
||||
tables.resource(LootResources.TABLES, key, TestSettings.of(LootTable.class, json));
|
||||
}
|
||||
|
||||
private void write(File root, String relative, String content) throws Exception {
|
||||
File file = new File(root, relative);
|
||||
Files.createDirectories(file.toPath().getParent());
|
||||
Files.writeString(file.toPath(), content, StandardCharsets.UTF_8);
|
||||
private void reference(Target level, String key, String json) {
|
||||
String folder = switch (level) {
|
||||
case DIMENSION -> "dimension";
|
||||
case REGION -> "region";
|
||||
default -> "biome";
|
||||
};
|
||||
references.add(new Entry<>(level, new ResourceId("test", folder + "/" + key), TestSettings.of(LootSettings.class, json)));
|
||||
}
|
||||
|
||||
private List<String> errors() {
|
||||
return messages(Severity.ERROR);
|
||||
}
|
||||
|
||||
private List<String> warnings() {
|
||||
return messages(Severity.WARNING);
|
||||
}
|
||||
|
||||
private List<String> messages(Severity severity) {
|
||||
List<Problem> problems = new ArrayList<>();
|
||||
new LootValidator().validate(context(problems));
|
||||
return problems.stream().filter(problem -> problem.severity() == severity).map(Problem::message).toList();
|
||||
}
|
||||
|
||||
private ValidationContext context(List<Problem> problems) {
|
||||
return new ValidationContext() {
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
return resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackSettings settings() {
|
||||
return new PackSettings() {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <F extends IrisFeature> List<Entry<F>> declared(Class<F> featureType) {
|
||||
return featureType == LootSettings.class ? (List<Entry<F>>) (List<?>) List.copyOf(references) : List.of();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void report(Problem problem) {
|
||||
problems.add(problem);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -21,24 +21,27 @@ package art.arcane.iris.engine.loot;
|
||||
import art.arcane.iris.builtin.loot.LootTable;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import art.arcane.iris.engine.object.loot.IObjectLoot;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.iris.builtin.loot.ObjectLoot;
|
||||
import art.arcane.iris.builtin.loot.ObjectLootEntry;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.host.ModuleLogs;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.block.BlockSpec;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.service.Loot;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -53,16 +56,6 @@ public class PlacementLootTest {
|
||||
|
||||
private PlacementLoot placement;
|
||||
|
||||
@BeforeClass
|
||||
public static void bindPlatform() {
|
||||
UsableBlockPlatform.bind();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void unbindPlatform() {
|
||||
UsableBlockPlatform.unbind();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void servePackTables() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
@@ -70,12 +63,17 @@ public class PlacementLootTest {
|
||||
for (String key : List.of("everywhere", "chests", "this-chest", "other")) {
|
||||
fixture.resource(LootResources.TABLES, key, TestSettings.of(LootTable.class, "{\"name\": \"" + key + "\"}"));
|
||||
}
|
||||
placement = new PlacementLoot(data, () -> Set.of("minecraft:chests/simple_dungeon"), LOOT_SEED, ModuleLogs.discarding());
|
||||
PackResources resources = data.getPackResources();
|
||||
BlockRegistry blocks = mock(BlockRegistry.class);
|
||||
when(resources.blocks()).thenReturn(blocks);
|
||||
when(blocks.resolve(any(BlockState.class))).thenAnswer(invocation -> invocation.getArgument(0));
|
||||
when(blocks.resolve(any(BlockSpec.class))).thenAnswer(invocation -> BlockState.parse(invocation.<BlockSpec>getArgument(0).block()));
|
||||
placement = new PlacementLoot(resources, () -> Set.of("minecraft:chests/simple_dungeon"), LOOT_SEED, ModuleLogs.discarding());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aTableThatNamesTheExactStateBeatsOneThatNamesTheKindOfBlock() {
|
||||
List<IObjectLoot> pack = List.of(entry("everywhere", 1, false), entry("chests", 1, false, CHEST), entry("this-chest", 1, true, CHEST));
|
||||
List<ObjectLootEntry> pack = List.of(entry("everywhere", 1, false), entry("chests", 1, false, CHEST), entry("this-chest", 1, true, CHEST));
|
||||
|
||||
assertEquals(new Loot.Table("this-chest"), pick(List.of(), pack, CHEST));
|
||||
assertEquals(new Loot.Table("chests"), pick(List.of(), pack, EAST_CHEST));
|
||||
@@ -83,26 +81,26 @@ public class PlacementLootTest {
|
||||
|
||||
@Test
|
||||
public void aTableThatNamesNoBlockServesChestsNothingElseNames() {
|
||||
List<IObjectLoot> pack = List.of(entry("everywhere", 1, false), entry("other", 1, false, "minecraft:barrel"));
|
||||
List<ObjectLootEntry> pack = List.of(entry("everywhere", 1, false), entry("other", 1, false, "minecraft:barrel"));
|
||||
|
||||
assertEquals(new Loot.Table("everywhere"), pick(List.of(), pack, CHEST));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exactEntriesDoNotApplyToOtherStatesAndNothingMatchingGivesNothing() {
|
||||
List<IObjectLoot> pack = List.of(entry("this-chest", 1, true, CHEST), entry("other", 1, false, "minecraft:barrel"));
|
||||
List<ObjectLootEntry> pack = List.of(entry("this-chest", 1, true, CHEST), entry("other", 1, false, "minecraft:barrel"));
|
||||
|
||||
assertNull(pick(List.of(), pack, EAST_CHEST));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void weightsPickAmongEqualsAndZeroWeightsAreIgnored() {
|
||||
List<IObjectLoot> pack = List.of(entry("everywhere", 3, false), entry("chests", 1, false), entry("other", 0, false));
|
||||
List<ObjectLootEntry> pack = List.of(entry("everywhere", 3, false), entry("chests", 1, false), entry("other", 0, false));
|
||||
int everywhere = 0;
|
||||
RNG rng = new RNG(5L);
|
||||
|
||||
for (int i = 0; i < 4000; i++) {
|
||||
Loot.Source picked = placement.pick(List.of(), pack, block(CHEST), rng, 0, 64, 0);
|
||||
Loot.Source picked = placement.pick(List.of(), pack, BlockState.parse(CHEST), rng, 0, 64, 0);
|
||||
if (picked.equals(new Loot.Table("everywhere"))) {
|
||||
everywhere++;
|
||||
} else {
|
||||
@@ -115,7 +113,7 @@ public class PlacementLootTest {
|
||||
|
||||
@Test
|
||||
public void aPlatformTableWithAnythingThePlatformHasIsASourceWithTheSeedOfItsIdentity() {
|
||||
List<IObjectLoot> platform = List.of(entry("chests/simple_dungeon", 1, false), entry("chests/missing", 1, false));
|
||||
List<ObjectLootEntry> platform = List.of(entry("chests/simple_dungeon", 1, false), entry("chests/missing", 1, false));
|
||||
|
||||
Loot.Source picked = pick(platform, List.of(), CHEST);
|
||||
|
||||
@@ -128,24 +126,13 @@ public class PlacementLootTest {
|
||||
assertNull(pick(List.of(entry("chests/missing", 1, false)), List.of(entry("not-a-table", 1, false)), CHEST));
|
||||
}
|
||||
|
||||
private Loot.Source pick(List<IObjectLoot> platform, List<IObjectLoot> pack, String container) {
|
||||
return placement.pick(platform, pack, block(container), new RNG(1L), 0, 64, 0);
|
||||
private Loot.Source pick(List<ObjectLootEntry> platform, List<ObjectLootEntry> pack, String container) {
|
||||
return placement.pick(platform, pack, BlockState.parse(container), new RNG(1L), 0, 64, 0);
|
||||
}
|
||||
|
||||
private static PlatformBlockState block(String key) {
|
||||
return UsableBlockPlatform.block(key);
|
||||
}
|
||||
|
||||
private static IObjectLoot entry(String name, int weight, boolean exact, String... filter) {
|
||||
IObjectLoot loot = mock(IObjectLoot.class);
|
||||
when(loot.getName()).thenReturn(name);
|
||||
when(loot.getWeight()).thenReturn(weight);
|
||||
when(loot.isExact()).thenReturn(exact);
|
||||
KList<PlatformBlockState> filterStates = new KList<>();
|
||||
for (String key : filter) {
|
||||
filterStates.add(block(key));
|
||||
}
|
||||
when(loot.getFilter(org.mockito.ArgumentMatchers.any())).thenReturn(filterStates);
|
||||
return loot;
|
||||
private static ObjectLootEntry entry(String name, int weight, boolean exact, String... filter) {
|
||||
String blocks = Arrays.stream(filter).map(key -> "{\"block\": \"" + key + "\"}").collect(Collectors.joining(", "));
|
||||
return TestSettings.of(ObjectLoot.class, "{\"name\": \"" + name + "\", \"weight\": " + weight + ", \"exact\": " + exact
|
||||
+ ", \"filter\": [" + blocks + "]}");
|
||||
}
|
||||
}
|
||||
+9
-9
@@ -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");
|
||||
|
||||
+42
@@ -19,6 +19,9 @@
|
||||
package art.arcane.iris.engine.object.placement;
|
||||
|
||||
import art.arcane.iris.builtin.blocks.ObjectReplace;
|
||||
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.builtin.prepare.AxisRotationClamp;
|
||||
import art.arcane.iris.builtin.prepare.SlopeClip;
|
||||
import art.arcane.iris.builtin.stilt.StiltSettings;
|
||||
@@ -91,6 +94,14 @@ public class PlacementSettingsDecodingTest {
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
private static final String LOOT_AND_MARKERS = """
|
||||
{"place": ["huts/camp"], "overrideGlobalLoot": true,
|
||||
"loot": [{"name": "camp/chest", "weight": 3, "exact": true, "filter": [{"block": "chest", "data": {"facing": "north"}}]},
|
||||
{"name": "camp/barrel"}],
|
||||
"vanillaLoot": [{"name": "chests/simple_dungeon", "weight": 2, "filter": [{"block": "minecraft:barrel"}]}],
|
||||
"markers": [{"marker": "camp", "maximumMarkers": 4, "exact": true, "mark": [{"block": "campfire", "data": {"lit": true}}]}]}
|
||||
""";
|
||||
|
||||
private Gson gson;
|
||||
|
||||
@Before
|
||||
@@ -235,4 +246,35 @@ public class PlacementSettingsDecodingTest {
|
||||
assertEquals(90, defaults.interval(), 0);
|
||||
assertFalse(placement("{}").getRotation().getXAxis().enabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lootAndMarkersReadTheFieldsTheyAlwaysHad() {
|
||||
IrisObjectPlacement placement = placement(LOOT_AND_MARKERS);
|
||||
|
||||
assertTrue(placement.isOverrideGlobalLoot());
|
||||
ObjectLoot chest = placement.getLoot().get(0);
|
||||
assertEquals("camp/chest", chest.name());
|
||||
assertEquals(3, chest.weight());
|
||||
assertTrue(chest.exact());
|
||||
assertEquals("chest", chest.filter().getFirst().block());
|
||||
assertEquals("north", chest.filter().getFirst().data().get("facing"));
|
||||
ObjectLoot barrel = placement.getLoot().get(1);
|
||||
assertEquals(1, barrel.weight());
|
||||
assertFalse(barrel.exact());
|
||||
assertTrue(barrel.filter().isEmpty());
|
||||
|
||||
ObjectVanillaLoot dungeon = placement.getVanillaLoot().getFirst();
|
||||
assertEquals("chests/simple_dungeon", dungeon.name());
|
||||
assertEquals(2, dungeon.weight());
|
||||
assertEquals("minecraft:barrel", dungeon.filter().getFirst().block());
|
||||
|
||||
PlacementMarker marker = placement.getMarkers().getFirst();
|
||||
assertEquals("camp", marker.marker());
|
||||
assertEquals(4, marker.maximumMarkers());
|
||||
assertTrue(marker.exact());
|
||||
assertEquals("true", marker.mark().getFirst().data().get("lit"));
|
||||
|
||||
assertTrue(placement("{}").getLoot().isEmpty());
|
||||
assertEquals(8, new PlacementMarker().maximumMarkers());
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -20,13 +20,14 @@ package art.arcane.iris.engine.spawn;
|
||||
|
||||
import art.arcane.iris.engine.loot.LootItems;
|
||||
import art.arcane.iris.builtin.spawn.EntityDefinition;
|
||||
import art.arcane.iris.spi.PlatformWorld;
|
||||
import art.arcane.iris.builtin.LiveWorld.Sky;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.entity.EntitySpec;
|
||||
import com.volmit.item.ItemRegistry;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -63,10 +64,10 @@ public class EntityResolutionPinTest {
|
||||
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));
|
||||
PlatformWorld world = mock(PlatformWorld.class);
|
||||
Optional<Sky> sky = Optional.of(new Sky(0L, false, false));
|
||||
EntityDefinition entity = new Gson().fromJson(ENTITY, EntityDefinition.class);
|
||||
|
||||
EntitySpec spec = new EntityResolution(new LootItems(registry, false), world, new EffectTimers()).resolve(entity, new RNG(STREAM_SEED));
|
||||
EntitySpec spec = new EntityResolution(new LootItems(registry, false), sky, new EffectTimers()).resolve(entity, new RNG(STREAM_SEED));
|
||||
|
||||
assertEquals(-819231818, spec.toString().hashCode());
|
||||
}
|
||||
|
||||
@@ -18,20 +18,20 @@
|
||||
|
||||
package art.arcane.iris.engine.spawn;
|
||||
|
||||
import art.arcane.iris.builtin.LiveWorld;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
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.engine.mantle.EngineMantle;
|
||||
import art.arcane.iris.builtin.spawn.EntityDefinition;
|
||||
import art.arcane.iris.builtin.spawn.SpawnMarker;
|
||||
import art.arcane.iris.builtin.spawn.Spawner;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import art.arcane.iris.engine.object.runtime.IrisEngineData;
|
||||
import art.arcane.iris.engine.object.world.IrisWorld;
|
||||
import art.arcane.iris.spi.PlatformWorld;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.volmit.entity.EntitySpec;
|
||||
import com.volmit.item.ItemRegistry;
|
||||
import com.volmit.service.EntitySpawns;
|
||||
@@ -80,6 +80,7 @@ public class EntitySpawningTest {
|
||||
IrisWorld engineWorld = mock(IrisWorld.class);
|
||||
when(engineWorld.platformWorld()).thenReturn(mock(PlatformWorld.class));
|
||||
when(engine.getWorld()).thenReturn(engineWorld);
|
||||
when(engine.getEngineData()).thenReturn(new IrisEngineData());
|
||||
SeedManager seeds = mock(SeedManager.class);
|
||||
when(seeds.getEntity()).thenReturn(11L);
|
||||
when(engine.getSeedManager()).thenReturn(seeds);
|
||||
@@ -88,11 +89,10 @@ public class EntitySpawningTest {
|
||||
|
||||
@Test
|
||||
public void aCaveWithoutFloorMarkersHasNowhereToSpawn() {
|
||||
EngineMantle mantle = mock(EngineMantle.class);
|
||||
when(engine.getMantle()).thenReturn(mantle);
|
||||
when(mantle.findMarkers(2, 3, art.arcane.volmlib.util.matter.slices.MarkerMatter.CAVE_FLOOR)).thenReturn(new KList<>());
|
||||
LiveWorld live = mock(LiveWorld.class);
|
||||
when(live.caveFloors(2, 3)).thenReturn(List.of());
|
||||
|
||||
assertNull(EntitySpawning.caveSpawnPosition(engine, 2, 3));
|
||||
assertNull(EntitySpawning.caveSpawnPosition(live, 2, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+15
-13
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.value;
|
||||
package art.arcane.iris.engine.spawn;
|
||||
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.junit.Test;
|
||||
@@ -25,13 +25,9 @@ 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;
|
||||
}
|
||||
/** Rarity weights a pool exactly once: a spawner's spawns are picked from the expanded pool. */
|
||||
public class RarityWeightingTest {
|
||||
private record Spawn(int rarity) {
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -39,7 +35,7 @@ public class IRareWeightingTest {
|
||||
Spawn common = new Spawn(1);
|
||||
Spawn rare = new Spawn(4);
|
||||
|
||||
KList<Spawn> expanded = IRare.expandWeighted(List.of(common, rare));
|
||||
KList<Spawn> expanded = RarityWeighting.expand(List.of(common, rare), Spawn::rarity);
|
||||
|
||||
// totalRarity 5 -> common appears 5/1 = 5 times, rare 5/4 = 1 time.
|
||||
assertEquals(6, expanded.size());
|
||||
@@ -48,9 +44,15 @@ public class IRareWeightingTest {
|
||||
}
|
||||
|
||||
@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)));
|
||||
public void rarityZeroAndNegativeCountAsOne() {
|
||||
Spawn zero = new Spawn(0);
|
||||
Spawn negative = new Spawn(-5);
|
||||
|
||||
KList<Spawn> expanded = RarityWeighting.expand(List.of(zero, negative, new Spawn(3)), Spawn::rarity);
|
||||
|
||||
// totalRarity 1 + 1 + 3 = 5 -> 5, 5 and 1 entries.
|
||||
assertEquals(11, expanded.size());
|
||||
assertEquals(5, expanded.stream().filter(entry -> entry == zero).count());
|
||||
assertEquals(5, expanded.stream().filter(entry -> entry == negative).count());
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.engine.spawn;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.BuiltInModulesJar;
|
||||
import art.arcane.iris.core.project.ModuleResourceSchemas;
|
||||
import art.arcane.iris.core.project.SchemaTestPlatform;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
@@ -68,21 +69,21 @@ public class SpawnResourcesTest {
|
||||
Path pack = spawnPack("spawns");
|
||||
IrisData data = IrisData.openValidation(pack.toFile());
|
||||
try {
|
||||
Spawner spawner = SpawnResources.spawner(data, "camp/zombies");
|
||||
Spawner spawner = SpawnResources.spawner(data.getPackResources(), "camp/zombies");
|
||||
|
||||
assertEquals("zombie", spawner.spawns().getFirst().entity());
|
||||
assertEquals("minecraft:zombie", SpawnResources.entity(data, "zombie").type());
|
||||
assertEquals(List.of("camp/zombies"), SpawnResources.marker(data, "camp").spawners());
|
||||
assertEquals(List.of(new SpawnResources.KeyedSpawner("camp/zombies", spawner)), SpawnResources.spawners(data, List.of("camp/zombies", "missing")));
|
||||
assertEquals(List.of("zombie"), SpawnResources.entityKeys(data));
|
||||
assertEquals(List.of("camp"), SpawnResources.markerKeys(data));
|
||||
assertEquals(List.of("camp/zombies"), SpawnResources.spawnerKeys(data));
|
||||
assertNull(SpawnResources.spawner(data, "missing"));
|
||||
assertNull(SpawnResources.entity(data, " "));
|
||||
assertEquals("minecraft:zombie", SpawnResources.entity(data.getPackResources(), "zombie").type());
|
||||
assertEquals(List.of("camp/zombies"), SpawnResources.marker(data.getPackResources(), "camp").spawners());
|
||||
assertEquals(List.of(new SpawnResources.KeyedSpawner("camp/zombies", spawner)), SpawnResources.spawners(data.getPackResources(), List.of("camp/zombies", "missing")));
|
||||
assertEquals(List.of("zombie"), SpawnResources.entityKeys(data.getPackResources()));
|
||||
assertEquals(List.of("camp"), SpawnResources.markerKeys(data.getPackResources()));
|
||||
assertEquals(List.of("camp/zombies"), SpawnResources.spawnerKeys(data.getPackResources()));
|
||||
assertNull(SpawnResources.spawner(data.getPackResources(), "missing"));
|
||||
assertNull(SpawnResources.entity(data.getPackResources(), " "));
|
||||
|
||||
write(pack, "entities/zombie.json", "{\"type\":\"minecraft:husk\"}");
|
||||
data.dump();
|
||||
assertEquals("minecraft:husk", SpawnResources.entity(data, "zombie").type());
|
||||
assertEquals("minecraft:husk", SpawnResources.entity(data.getPackResources(), "zombie").type());
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
@@ -115,6 +116,7 @@ public class SpawnResourcesTest {
|
||||
write(pack.toPath(), "entities/zombie.json", "{\"type\":\"minecraft:zombie\"}");
|
||||
write(pack.toPath(), "spawners/camp/zombies.json", "{\"spawns\":[{\"entity\":\"zombie\"}]}");
|
||||
write(pack.toPath(), "markers/camp.json", "{\"spawners\":[\"camp/zombies\"]}");
|
||||
BuiltInModulesJar.writeInto(pack.toPath());
|
||||
return pack.toPath();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,13 +18,16 @@
|
||||
|
||||
package art.arcane.iris.engine.spawn;
|
||||
|
||||
import art.arcane.iris.builtin.LiveWorld;
|
||||
import art.arcane.iris.builtin.LiveWorld.BiomeKind;
|
||||
import art.arcane.iris.builtin.LiveWorld.Sky;
|
||||
import art.arcane.iris.builtin.spawn.Spawner;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineGeneration;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import art.arcane.iris.engine.object.runtime.IrisEngineData;
|
||||
import art.arcane.iris.engine.object.world.IrisWorld;
|
||||
import art.arcane.iris.engine.object.world.biome.InferredType;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.spi.PlatformWorld;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -36,17 +39,19 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
/** Whether a spawner may fire: the biome kind its group wants, the world's time and weather, and its rates in the engine's data. */
|
||||
public class SpawnerGateTest {
|
||||
private Engine engine;
|
||||
private PlatformWorld world;
|
||||
private LiveWorld live;
|
||||
|
||||
@Before
|
||||
public void buildEngine() {
|
||||
engine = mock(Engine.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisWorld engineWorld = mock(IrisWorld.class);
|
||||
world = mock(PlatformWorld.class);
|
||||
when(engineWorld.platformWorld()).thenReturn(world);
|
||||
PlatformWorld platformWorld = mock(PlatformWorld.class);
|
||||
when(platformWorld.getTime()).thenReturn(6000L);
|
||||
when(engineWorld.platformWorld()).thenReturn(platformWorld);
|
||||
when(engine.getWorld()).thenReturn(engineWorld);
|
||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||
when(engine.getEngineData()).thenReturn(new IrisEngineData());
|
||||
live = LiveWorld.of(new EngineGeneration(engine).world());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,58 +61,54 @@ public class SpawnerGateTest {
|
||||
Spawner beach = spawner("{\"group\": \"BEACH\"}");
|
||||
Spawner cave = spawner("{\"group\": \"CAVE\"}");
|
||||
|
||||
assertTrue(SpawnerGate.suits(normal, biome(InferredType.LAND)));
|
||||
assertFalse(SpawnerGate.suits(normal, biome(InferredType.SEA)));
|
||||
assertTrue(SpawnerGate.suits(underwater, biome(InferredType.SEA)));
|
||||
assertFalse(SpawnerGate.suits(underwater, biome(InferredType.LAND)));
|
||||
assertTrue(SpawnerGate.suits(beach, biome(InferredType.SHORE)));
|
||||
assertFalse(SpawnerGate.suits(beach, biome(InferredType.CAVE)));
|
||||
assertTrue(SpawnerGate.suits(cave, biome(InferredType.SEA)));
|
||||
assertTrue(SpawnerGate.suits(normal, BiomeKind.LAND));
|
||||
assertFalse(SpawnerGate.suits(normal, BiomeKind.SEA));
|
||||
assertTrue(SpawnerGate.suits(underwater, BiomeKind.SEA));
|
||||
assertFalse(SpawnerGate.suits(underwater, BiomeKind.LAND));
|
||||
assertTrue(SpawnerGate.suits(beach, BiomeKind.SHORE));
|
||||
assertFalse(SpawnerGate.suits(beach, BiomeKind.CAVE));
|
||||
assertTrue(SpawnerGate.suits(cave, BiomeKind.SEA));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timeAndWeatherMustMatch() {
|
||||
Spawner daytimeRain = spawner("{\"timeBlock\": {\"startHour\": 8, \"endHour\": 18}, \"weather\": \"DOWNFALL\"}");
|
||||
when(world.getTime()).thenReturn(6000L);
|
||||
when(world.isStorming()).thenReturn(true);
|
||||
assertTrue(SpawnerGate.suits(daytimeRain, world));
|
||||
|
||||
when(world.isStorming()).thenReturn(false);
|
||||
assertFalse(SpawnerGate.suits(daytimeRain, world));
|
||||
|
||||
when(world.isStorming()).thenReturn(true);
|
||||
when(world.getTime()).thenReturn(20000L);
|
||||
assertFalse(SpawnerGate.suits(daytimeRain, world));
|
||||
assertTrue(SpawnerGate.suits(daytimeRain, new Sky(6000L, true, false)));
|
||||
assertFalse(SpawnerGate.suits(daytimeRain, new Sky(6000L, false, false)));
|
||||
assertFalse(SpawnerGate.suits(daytimeRain, new Sky(20000L, true, false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aSpawnerWithoutRatesAlwaysMayFire() {
|
||||
Spawner free = spawner("{}");
|
||||
|
||||
SpawnerGate.spawned("free", free, engine, 3, 4);
|
||||
SpawnerGate.spawned("free", free, live, 3, 4);
|
||||
|
||||
assertTrue(SpawnerGate.canSpawn("free", free, engine, 3, 4));
|
||||
assertTrue(SpawnerGate.canSpawn("free", free, live, 3, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aRateHoldsTheSpawnerBackForItsIntervalPerWorldAndPerChunk() {
|
||||
Spawner limited = spawner("{\"maximumRate\": {\"amount\": 1, \"per\": {\"minutes\": 10}}, \"maximumRatePerChunk\": {\"amount\": 1, \"per\": {\"minutes\": 10}}}");
|
||||
|
||||
assertTrue(SpawnerGate.canSpawn("limited", limited, engine, 3, 4));
|
||||
SpawnerGate.spawned("limited", limited, engine, 3, 4);
|
||||
assertTrue(SpawnerGate.canSpawn("limited", limited, live, 3, 4));
|
||||
SpawnerGate.spawned("limited", limited, live, 3, 4);
|
||||
|
||||
assertFalse(SpawnerGate.canSpawn("limited", limited, engine, 3, 4));
|
||||
assertFalse(SpawnerGate.canSpawn("limited", limited, engine, 9, 9));
|
||||
assertTrue(SpawnerGate.canSpawn("other", limited, engine, 9, 9));
|
||||
assertFalse(SpawnerGate.canSpawn("limited", limited, live, 3, 4));
|
||||
assertFalse(SpawnerGate.canSpawn("limited", limited, live, 9, 9));
|
||||
assertTrue(SpawnerGate.canSpawn("other", limited, live, 9, 9));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aWorldWithoutAPlatformWorldLetsNothingFire() {
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||
when(engine.getWorld()).thenReturn(mock(IrisWorld.class));
|
||||
|
||||
assertFalse(SpawnerGate.canSpawn("any", spawner("{}"), LiveWorld.of(new EngineGeneration(engine).world()), 0, 0));
|
||||
}
|
||||
|
||||
private static Spawner spawner(String json) {
|
||||
return TestSettings.of(Spawner.class, json);
|
||||
}
|
||||
|
||||
private static IrisBiome biome(InferredType type) {
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
when(biome.getInferredType()).thenReturn(type);
|
||||
return biome;
|
||||
}
|
||||
}
|
||||
@@ -129,7 +129,7 @@ public final class DeserializationProbe {
|
||||
}
|
||||
|
||||
private static void assertEntity(IrisData data) {
|
||||
EntityDefinition entity = SpawnResources.entity(data, ENTITY_KEY);
|
||||
EntityDefinition entity = SpawnResources.entity(data.getPackResources(), ENTITY_KEY);
|
||||
require(entity != null, "entity deserialized");
|
||||
require("minecraft:panda".equals(entity.type()), "type round-trips as authored namespaced string");
|
||||
require("COMMAND".equals(entity.reason()), "reason retained as string");
|
||||
@@ -158,7 +158,7 @@ public final class DeserializationProbe {
|
||||
}
|
||||
|
||||
private static void assertSpawner(IrisData data) {
|
||||
Spawner spawner = SpawnResources.spawner(data, SPAWNER_KEY);
|
||||
Spawner spawner = SpawnResources.spawner(data.getPackResources(), SPAWNER_KEY);
|
||||
require(spawner != null, "spawner deserialized");
|
||||
List<EntitySpawn> spawns = spawner.spawns();
|
||||
require(spawns.size() == 1, "single entity spawn deserialized");
|
||||
@@ -168,7 +168,7 @@ public final class DeserializationProbe {
|
||||
}
|
||||
|
||||
private static void assertLoot(IrisData data) {
|
||||
LootTable table = LootResources.table(data, LOOT_KEY);
|
||||
LootTable table = LootResources.table(data.getPackResources(), LOOT_KEY);
|
||||
require(table != null, "loot table deserialized");
|
||||
require(LOOT_KEY.equals(table.name()), "loot table name retained");
|
||||
require(table.rarity() == 4, "loot table rarity retained");
|
||||
|
||||
Reference in new issue
Block a user