Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slot.onCrafted is wrong #1656

Open
Juuxel opened this issue Aug 4, 2020 · 5 comments
Open

Slot.onCrafted is wrong #1656

Juuxel opened this issue Aug 4, 2020 · 5 comments
Assignees
Labels
bug Fixes or discusses a bug within the mappings discussion refactor A PR that renames existing names.

Comments

@Juuxel
Copy link
Member

Juuxel commented Aug 4, 2020

See #1656 (comment)

@Juuxel Juuxel added bug Fixes or discusses a bug within the mappings discussion refactor A PR that renames existing names. labels Aug 4, 2020
@Runemoro
Copy link
Contributor

Runemoro commented Aug 4, 2020

I think either onSizeChanged or onItemCountChanged would be better. It's the stack size, or item count, being changed, not the stack count (number of stacks).

@YanisBft YanisBft self-assigned this Mar 27, 2021
@liach
Copy link
Contributor

liach commented Apr 2, 2021

is this still applicable after mojang's recent revamp on screen handlers in like 21w11a?

@Juuxel
Copy link
Member Author

Juuxel commented Apr 3, 2021

Okay, the original analysis might not be 100% correct. Current behaviour:

  • Slot.onStackChanged is still not a general stack change handler.
    • It's called from transferSlot implementations for output slots of various crafting blocks, but also for brewing stand inputs.
    • The parameters are seemingly newStack, originalStack (swapped from how they're mapped currently).
    • What it does is checks if there have been items taken out of the slot and if so, calls onCrafted(ItemStack, int) with the originalStack (called newItem in current mappings) and the difference between the stack sizes.
    • I think this is more of a "on output slot item count changed".
  • Slot.onCrafted(ItemStack, int) is only called by onStackChanged.
    • Default impl: no-op
    • In CraftingResultSlot, FurnaceOutputSlot and TradeOutputSlot the implementation is always the same: it increments a private amount field by the int parameter, then calls onCrafted(ItemStack) with the item stack parameter.
  • Slot.onCrafted(ItemStack) is only called by onCrafted(ItemStack, int) and onTakeItem implementations in those three classes.
    • Default impl: no-op
    • Implementations in those three classes: resets the private amount field to 0 and runs finalising tasks (furnace dropping XP etc)

Conclusion (needs to be confirmed with a debugger or a closer look):

  • All these methods relate to the player taking items out of output slots (crafting or trading).
  • onStackChanged is called when the item count changes in the output slot, and onCrafted(ItemStack, int) when that count decreases (= items are taken out).
  • onCrafted(ItemStack) finalises the output process when there's either a partial decrease (onStackChanged) or a full stack taken out (onTakeItem).
  • These methods still need renames.

@YanisBft YanisBft assigned Juuxel and unassigned YanisBft Apr 3, 2021
@reoseah
Copy link
Contributor

reoseah commented Apr 24, 2021

Conclusion (needs to be confirmed with a debugger or a closer look):

  • All these methods relate to the player taking items out of output slots (crafting or trading).
  • onStackChanged is called when the item count changes in the output slot, and onCrafted(ItemStack, int) when that count decreases (= items are taken out).

The method that calls them, transferSlot, is only used for quick transfer a.k.a. shift clicking. So, onQuickTransfer seems the most accurate to me. Parameter names were indeed switched.

@Juuxel
Copy link
Member Author

Juuxel commented Apr 24, 2021

This still applies to onCrafted, so reopening.

@Juuxel Juuxel reopened this Apr 24, 2021
@Juuxel Juuxel changed the title Slot.onCrafted/onStackChanged are wrong Slot.onCrafted is wrong Apr 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes or discusses a bug within the mappings discussion refactor A PR that renames existing names.
Projects
None yet
Development

No branches or pull requests

5 participants