Skip to content

[Feature Request] Loot Pool Entry Iteration and Modification for modifyPools #5236

@spicato-spicato

Description

@spicato-spicato

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.Builder has a private entries field (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.
  • EnchantRandomlyLootFunction has 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions