Repository navigation
Add hooks for adding and removing entries from LootPool - #3731
Open
officialasishkumar wants to merge 1 commit into
Open
officialasishkumar wants to merge 1 commit into
officialasishkumar wants to merge 1 commit into
Conversation
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.
|
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3174
LootTablealready has hooks that allowLootTableLoadEventlisteners to add, remove and look up pools, butLootPoolhas nothing for its entries. This PR adds those hooks, as requested in the issue, withcheckFrozen()calls instead of an access transformer onLootPool#entries:getEntries(): an unmodifiable view of the pool's entriesaddEntry(LootPoolEntryContainer)removeEntry(LootPoolEntryContainer): returns whether the entry was presentremoveEntriesIf(Predicate): useful because entries decoded from JSON have no handle or name to targetThe entries list is now copied into a mutable list in the
LootPoolconstructor. Before this it was the immutable list produced by the codec or builder.LootTabledoes 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:
LootPoolTest#lootPoolEntriesModified. It adds an entry and removes another throughLootTableLoadEvent, checks the drops,removeEntry, the unmodifiable view and the frozen behaviour.gradlew :tests:runGameTestServerpasses (all 213 required tests).gradlew genPatches applyAllFormatting checkFormattingis clean.test_loot_table_5.jsonby 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.