Skip to content

Add hooks for adding and removing entries from LootPool - #3731

Open
officialasishkumar wants to merge 1 commit into
neoforged:26.3.xfrom
officialasishkumar:feature/loot-pool-entry-hooks
Open

officialasishkumar wants to merge 1 commit into
neoforged:26.3.xfrom
officialasishkumar:feature/loot-pool-entry-hooks

Conversation

@officialasishkumar

Copy link
Copy Markdown

Closes #3174

LootTable already has hooks that allow LootTableLoadEvent listeners to add, remove and look up pools, but LootPool has nothing for its entries. This PR adds those hooks, as requested in the issue, with checkFrozen() calls instead of an access transformer on LootPool#entries:

  • getEntries(): an unmodifiable view of the pool's entries
  • addEntry(LootPoolEntryContainer)
  • removeEntry(LootPoolEntryContainer): returns whether the entry was present
  • removeEntriesIf(Predicate): useful because entries decoded from JSON have no handle or name to target

The entries list is now copied into a mutable list in the LootPool constructor. Before this it was the immutable list produced by the codec or builder. LootTable does the same for its pools.

The issue also mentions conditions and functions. I left those out, as the issue says they are harder (no clean removal, and the composite* fields would need updating), so they can be done separately.

Testing:

  • Added LootPoolTest#lootPoolEntriesModified. It adds an entry and removes another through LootTableLoadEvent, checks the drops, removeEntry, the unmodifiable view and the frozen behaviour.
  • gradlew :tests:runGameTestServer passes (all 213 required tests).
  • gradlew genPatches applyAllFormatting checkFormatting is clean.
  • I wrote test_loot_table_5.json by hand in the generated-resources format, because client datagen can't run on aarch64. Please regenerate it if you want the generated output to match exactly.

LootTable already exposes hooks that let LootTableLoadEvent listeners add,
remove and look up pools, but LootPool offered nothing for its entries, so
mods could only change the contents of an existing pool by replacing the
whole pool or the whole table.

Add the following to LootPool:
- getEntries(): an unmodifiable view of the pool's entries
- addEntry(entry): appends an entry
- removeEntry(entry): removes an entry, returning whether it was present
- removeEntriesIf(predicate): removes all matching entries

All mutators go through checkFrozen(), consistent with the existing
setRolls/setBonusRolls hooks. The entries list was previously whatever
immutable list the codec or builder produced, so the constructor now copies
it into a mutable list, mirroring what LootTable does for its pools.

Add a game test that adds and removes entries from a loaded pool through
LootTableLoadEvent and checks the resulting drops, the unmodifiable view and
the frozen behaviour.
@neoforged-automation neoforged-automation Bot added enhancement New (or improvement to existing) feature or request 26.3 Targeted at Minecraft 26.3 labels Nov 11, 2026
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@neoforged-pr-publishing

Copy link
Copy Markdown
  • Publish PR to GitHub Packages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

26.3 Targeted at Minecraft 26.3 enhancement New (or improvement to existing) feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add hooks for adding/removing entries from LootPool

2 participants