emilyploszaj / emi

A featureful and accessible item and recipe viewer
MIT License
249 stars 49 forks source link

[bug] 'Fill Recipe' Button Not Respecting Slot Max Count #47

Closed fzzyhmstrs closed 2 years ago

fzzyhmstrs commented 2 years ago

When a crafting block has a handler for auto-moving ingredients and you shift-click the [+] button, EMI will move items into slots beyond the slots stated maximum count via getMaxItemCount. As an example, I am integrating EMI into my mod, and the Imbuing Table crafting grid has a central slot with a maximum allowable item count of 1: image

But when I use the shift click, EMI transfers 8x melon slices into the middle slot in the below example: image

With this behavior, if the user were to press the craft button for "4x Imbued Quartz", 7 of the melon slices are going to be overwritten, as the middle slot is both an input and an output (because it is an enhanced enchanting table), like so: image (I'm in creative mode, so the other 12 ingredients didn't decrement on purpose)

Possible Solution: If EMI is using setStack in the Slot, instead using insertStack may resolve this. insertStack automatically splits the inserted stack based on the allowable count, and returns the remainder that couldn't fit.

emilyploszaj commented 2 years ago

Oh inventory max count and how it plagues us forever. I'll get this fixed.

emilyploszaj commented 2 years ago

Fixed in 0.3.1

fzzyhmstrs commented 2 years ago

Is the intended behavior after the update to simply not fill the restricted slot at all? (Pic below after shift-clicking the recipe in 0.3.1)

image

emilyploszaj commented 2 years ago

Nope, this isn't intended, rats, can I see your code?

fzzyhmstrs commented 2 years ago

Definitely. What part of the code are you looking for? Below is my init in the screenhandler; it uses a fairly typical addSlot implementation. ImbuingSlot is just a tweak of vanilla slots that lets me shunt setStack to the inventory itself rather than having to pass through the slot (does nothing but avoid a redundant markDirty() call). I only use that functionality with REI because it was causing a massive blast of "onContentChanged" every time you transferred something...

https://github.com/fzzyhmstrs/ai/blob/3e5842428bf292af033cbd852073ba9770ea2908/src/main/kotlin/me/fzzyhmstrs/amethyst_imbuement/screen/ImbuingTableScreenHandler.kt#L104

emilyploszaj commented 2 years ago

I found where I went wrong with this, it's good that it's not filling the restricted slot, but I missed a line that did restriction properly, should be in the next update

emilyploszaj commented 2 years ago

Fixed (properly, hopefully) in 0.3.2