From 3ac971c0d92f1c4efc1fa365e90e62041b27230e Mon Sep 17 00:00:00 2001 From: piexel Date: Wed, 28 Oct 2026 04:16:10 +0100 Subject: [PATCH] Name the pack table an item came from by its id --- .../arcane/iris/engine/loot/LootGiving.java | 2 +- .../arcane/iris/engine/loot/LootItems.java | 26 +++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main/java/art/arcane/iris/engine/loot/LootGiving.java b/src/main/java/art/arcane/iris/engine/loot/LootGiving.java index 940a0e871..32c715e73 100644 --- a/src/main/java/art/arcane/iris/engine/loot/LootGiving.java +++ b/src/main/java/art/arcane/iris/engine/loot/LootGiving.java @@ -76,7 +76,7 @@ public final class LootGiving implements Loot { } int worldY = site.position().y() + world.minWorldY(); return new LootItems(world.resources().items(), site.debug(), world.log()) - .draw(tableId.path(), table, lootSeed(world), site.position().x(), worldY, site.position().z()); + .draw(tableId, table, lootSeed(world), site.position().x(), worldY, site.position().z()); } @Override diff --git a/src/main/java/art/arcane/iris/engine/loot/LootItems.java b/src/main/java/art/arcane/iris/engine/loot/LootItems.java index 815c5280c..c83373b2d 100644 --- a/src/main/java/art/arcane/iris/engine/loot/LootItems.java +++ b/src/main/java/art/arcane/iris/engine/loot/LootItems.java @@ -70,6 +70,15 @@ public final class LootItems { * asks for or runs out of tries. */ public List draw(String tableKey, LootTable table, long lootSeed, int x, int y, int z) { + return draw(tableKey, Optional.empty(), table, lootSeed, x, y, z); + } + + /** As {@link #draw(String, LootTable, long, int, int, int)} for the pack table {@code tableId}, which the items name as their source. */ + public List draw(ResourceId tableId, LootTable table, long lootSeed, int x, int y, int z) { + return draw(tableId.path(), Optional.of(tableId), table, lootSeed, x, y, z); + } + + private List draw(String tableKey, Optional tableId, LootTable table, long lootSeed, int x, int y, int z) { List drops = new ArrayList<>(); List entries = table.loot(); if (entries.isEmpty() || table.maxTries() <= 0) { @@ -86,7 +95,7 @@ public final class LootItems { if (entry == null || entry.slotTypes() != LootSlot.STORAGE) { continue; } - ItemDrop drop = drawEntry(entry, table, identity, rng, lootSeed, index, x, y, z); + ItemDrop drop = drawEntry(entry, table, tableId, identity, rng, lootSeed, index, x, y, z); if (drop != null) { drops.add(drop); } @@ -96,7 +105,7 @@ public final class LootItems { /** The item {@code entry} gives when nothing else decides whether it does, such as a block's drop or a mob's equipment; null for no item. */ public ItemDrop give(LootEntry entry, RNG rng) { - return resolve(entry, rng, null); + return resolve(entry, rng, null, Optional.empty()); } /** The attribute modifiers that pass their chances, with their amounts drawn, as for an item or an entity. */ @@ -117,15 +126,16 @@ public final class LootItems { return attributes; } - private ItemDrop drawEntry(LootEntry entry, LootTable table, String identity, RNG rng, long lootSeed, int index, int x, int y, int z) { + private ItemDrop drawEntry(LootEntry entry, LootTable table, Optional tableId, String identity, RNG rng, long lootSeed, + int index, int x, int y, int z) { long combinedRarity = LootResolver.combinedRarity(entry.rarity(), table.rarity()); if (!LootTables.spatialOneIn(lootSeed, identity, index, x, y, z, combinedRarity)) { return null; } - return resolve(entry, rng, table); + return resolve(entry, rng, table, tableId); } - private ItemDrop resolve(LootEntry entry, RNG rng, LootTable table) { + private ItemDrop resolve(LootEntry entry, RNG rng, LootTable table, Optional tableId) { Optional item = PlatformKeys.item(entry.type(), log); if (item.isEmpty() || item.get().equals(AIR)) { return null; @@ -143,7 +153,7 @@ public final class LootItems { : OptionalDouble.empty(); return new ItemDrop(item.get(), amount, lookOf(entry), enchantments, attributes, new ItemDrop.Wear(entry.unbreakable(), damage), new ItemDrop.PlatformExtras(entry.itemFlags(), Objects.requireNonNullElse(entry.customNbt(), Map.of())), - debug ? Optional.of(sourceOf(entry, table)) : Optional.empty()); + debug ? Optional.of(sourceOf(entry, table, tableId)) : Optional.empty()); } private ItemDrop.Look lookOf(LootEntry entry) { @@ -166,10 +176,10 @@ public final class LootItems { return enchantments; } - private static ItemDrop.Source sourceOf(LootEntry entry, LootTable table) { + private static ItemDrop.Source sourceOf(LootEntry entry, LootTable table, Optional tableId) { if (table == null) { return new ItemDrop.Source(Optional.empty(), 0, entry.rarity()); } - return new ItemDrop.Source(Optional.ofNullable(table.name()), table.rarity(), entry.rarity()); + return new ItemDrop.Source(tableId, table.rarity(), entry.rarity()); } }