- Notifications
You must be signed in to change notification settings - Fork 519
Description
Summary
Mods need to modify existing loot pool entries during LootTableEvents.MODIFY—for example, to filter enchantments from EnchantRandomlyLootFunction or adjust other entry-level functions. Currently this requires reflection because the necessary APIs to iterate and modify pool entries are not exposed.
Use Case
Mods that rebalance loot need to edit vanilla pool entries (e.g. replace loot functions on existing entries) before adding their own pools, all within the same MODIFY callback. Without entry-level access, mods must use MODIFY_DROPS and workarounds that are more fragile.
Current Limitations
LootPool.Builderhas a privateentriesfield (ImmutableList.Builder<LootPoolEntry>) with no public accessor.- There's no way to create a builder from an existing
LootPoolEntry(e.g.ItemEntry) to clone it with modified functions. EnchantRandomlyLootFunctionhas no public way to create a copy with a filtered enchantment list.
Requested APIs
1. Expose pool entries for iteration
Add to FabricLootPoolBuilder (or equivalent):
/** * Returns the entries currently in this pool builder. * Useful for iterating and cloning entries with modifications. */ List<LootPoolEntryContainer> getEntries();2. Replace pool entries
Add to FabricLootPoolBuilder:
/** * Replaces all entries in this pool builder with the given entries. * Use with getEntries() to iterate, modify, and replace. */ LootPool.Builder setEntries(Collection<? extends LootPoolEntryContainer> entries);Or alternatively, a higher-level modifier:
/** * Applies a modifier to each entry; entries are replaced with the modifier's result. * Return null to remove an entry. */ LootPool.Builder modifyEntries(Function<LootPoolEntryContainer, LootPoolEntryContainer> modifier);3. Create a builder from an existing entry
Add to LeafEntry or ItemEntry (or a shared utility):
/** * Creates a builder pre-populated from an existing entry, for cloning with modifications. */ static LeafEntry.Builder<?, ?> copyOf(LeafEntry entry);4. (Optional) Filter enchantments in EnchantRandomlyLootFunction
Add to EnchantRandomlyLootFunction or its builder:
/** * Creates a copy of this function with the given enchantments excluded from the pool. * If options is empty (all enchantments), resolves from registry first. */ EnchantRandomlyLootFunction withExcludedEnchantments(RegistryEntryList<Enchantment> exclude, RegistryWrapper.WrapperLookup registries);Environment
- Minecraft: 1.21.10
- Fabric API: 0.138.3+1.21.10
- fabric-loot-api-v3