From 7aa06e58f2907c75c5b6e607ec4a8626eb1bc297 Mon Sep 17 00:00:00 2001 From: piexel Date: Sat, 10 Oct 2026 18:02:53 +0200 Subject: [PATCH] Mechanical: LootResolver moves to IrisModule's art.arcane.iris.builtin.loot (imports) --- .../arcane/iris/modded/ModdedLootApplier.java | 2 +- .../iris/modded/ModdedLootApplierTest.java | 2 +- .../iris/engine/framework/LootResolver.java | 196 ------------------ .../iris/engine/platform/EngineBukkitOps.java | 2 +- .../iris/engine/loot/LootResolverTest.java | 2 +- 5 files changed, 4 insertions(+), 200 deletions(-) delete mode 100644 core/src/main/java/art/arcane/iris/engine/framework/LootResolver.java diff --git a/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedLootApplier.java b/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedLootApplier.java index f81f51935..3bd841040 100644 --- a/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedLootApplier.java +++ b/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedLootApplier.java @@ -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; diff --git a/adapters/modded-common/src/test/java/art/arcane/iris/modded/ModdedLootApplierTest.java b/adapters/modded-common/src/test/java/art/arcane/iris/modded/ModdedLootApplierTest.java index 001e84ec7..538fac26e 100644 --- a/adapters/modded-common/src/test/java/art/arcane/iris/modded/ModdedLootApplierTest.java +++ b/adapters/modded-common/src/test/java/art/arcane/iris/modded/ModdedLootApplierTest.java @@ -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; diff --git a/core/src/main/java/art/arcane/iris/engine/framework/LootResolver.java b/core/src/main/java/art/arcane/iris/engine/framework/LootResolver.java deleted file mode 100644 index 560e8e314..000000000 --- a/core/src/main/java/art/arcane/iris/engine/framework/LootResolver.java +++ /dev/null @@ -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 . - */ - -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 pickWeighted(List choices, ToIntFunction 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 void scaleSources(List 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 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 void shrinkSources(List sources, List 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 void expandSources(List sources, List 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); - } -} diff --git a/core/src/main/java/art/arcane/iris/engine/platform/EngineBukkitOps.java b/core/src/main/java/art/arcane/iris/engine/platform/EngineBukkitOps.java index 04b649f9a..47de91f2b 100644 --- a/core/src/main/java/art/arcane/iris/engine/platform/EngineBukkitOps.java +++ b/core/src/main/java/art/arcane/iris/engine/platform/EngineBukkitOps.java @@ -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; diff --git a/core/src/test/java/art/arcane/iris/engine/loot/LootResolverTest.java b/core/src/test/java/art/arcane/iris/engine/loot/LootResolverTest.java index b264d5312..7bec795d0 100644 --- a/core/src/test/java/art/arcane/iris/engine/loot/LootResolverTest.java +++ b/core/src/test/java/art/arcane/iris/engine/loot/LootResolverTest.java @@ -1,7 +1,7 @@ package art.arcane.iris.engine.loot; 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.engine.IrisComplex; import art.arcane.iris.engine.object.world.biome.IrisBiome;