feat(invcleaner): keep the fullest block stack in the block slot#8450
Open
m1trenv0 wants to merge 3 commits into
Open
feat(invcleaner): keep the fullest block stack in the block slot#8450m1trenv0 wants to merge 3 commits into
m1trenv0 wants to merge 3 commits into
Conversation
InventoryCleaner used the scaffold inventory comparator for blocks, which prefers the SMALLER stack (PreferStackSize.PREFER_FEWER). As a result the block slot would end up holding a near-empty stack while a full stack sat in the inventory. Give BlockItemFacet its own comparator that, among equally good blocks, keeps the stack with MORE blocks. A small hysteresis (counts within 1 are treated as equal, tie broken by hotbar preference) prevents pointless swaps between two near-equal stacks (e.g. 63 vs 64), while a clearly larger inventory stack will still replace a nearly empty one in hand. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1zun4
approved these changes
Jun 8, 2026
1zun4
left a comment
Member
There was a problem hiding this comment.
The code seems alright so far and makes sense, however, have you actually tested it in action?
1zun4
reviewed
Jun 8, 2026
Comment on lines
+35
to
+50
| /** | ||
| * Stack counts within this many blocks of each other are treated as equal, so the cleaner | ||
| * does not keep swapping between two near-equal stacks (e.g. 63 vs 64). The tie is then | ||
| * broken by [PREFER_ITEMS_IN_HOTBAR], i.e. the stack already in the hotbar is kept. | ||
| */ | ||
| private const val COUNT_HYSTERESIS = 1 | ||
|
|
||
| /** | ||
| * Prefers the block with MORE items, but only when the difference is meaningful (greater than | ||
| * [COUNT_HYSTERESIS]). This keeps the fullest stack in the block slot while avoiding pointless | ||
| * swaps over a one-block difference. | ||
| */ | ||
| private val PREFER_MORE_BLOCKS_FUZZY: Comparator<ItemStack> = Comparator { a, b -> | ||
| val diff = a.count - b.count | ||
| if (diff in -COUNT_HYSTERESIS..COUNT_HYSTERESIS) 0 else diff | ||
| } |
Member
There was a problem hiding this comment.
Does not belong into BlockItemFacet. Should go into a new file, the way "PreferFullCubeBlocks" etc do it.
1zun4
requested changes
Jun 8, 2026
…temFacet Addresses review feedback: the count comparator does not belong inside BlockItemFacet. Extracted it to ItemStackComparators.kt as a reusable PreferMoreBlocksFuzzy(hysteresis) class, alongside PreferFullCubeBlocks and the other block comparators. BlockItemFacet now just references it; the comparator chain and behaviour are unchanged. Co-authored-by: Claude <noreply@anthropic.com>
…ss stacks win A glass stack with 2x the count was ignored in favour of a tiny stack of a 'nicer' block (esp. stained glass), even though the glass was in neither the disallowed nor unfavorable list. Cause: the comparator put all soft quality preferences (solid/redstone-conductor, walkable, hardness) before count, so glass (not a redstone conductor) always lost to a full opaque block regardless of stack size. Reordered: usability gates first (favourable + full-cube), then count, then the soft quality tiebreakers. Among usable full-cube blocks the fullest stack now wins. Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Author
yes, it works, tested with own compiled build |
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.
What
Makes InventoryCleaner keep the fullest block stack in the block slot, instead of a near-empty one.
Problem
BlockItemFacetusedModuleScaffold.BLOCK_COMPARATOR_FOR_INVENTORY, which prefers the smaller stack (PreferStackSize.PREFER_FEWER). So the cleaner could leave a nearly empty stack in the block slot while a full stack sat elsewhere in the inventory, and the choice between similar stacks felt random.How
BlockItemFacetnow has its own comparator chain:Scaffold's own comparators are left untouched.
🤖 Generated with Claude Code