Tech Reborn

Tech Reborn

30M Downloads

item output logic flawed

rapus95 opened this issue ยท 5 comments

commented

Describe the bug
Machines always place their output into the first slot that's available. Thus, if at some later place there's half a stack it will never first fill that stack up but instead start a new stack.

Environment (please complete the following information with the version):

  • Minecraft: 1.19
  • Mod Loader: fabric

Additional context
back when I was modding myself, there was a helper function, that returned the first non-full stack or the first empty slot if no such stack existed

commented

@Technici4n @modmuss50 It looks like this belongs to FAPI and not to TR

commented

Vanilla hopper behavior is to not stack the items in chests. So FAPI follows this by default.

commented

EDIT: damn, looks like this is part of the experimental transaction/transfer API :/
EDIT2: OTOH you already use the experimental API anyway

@drcrazy @Technici4n but there nevertheless seems to be some logic right in the API which actually is

..., trying to "stack" first, i.e. prioritizing slots that already contain the resource.

https://github.com/FabricMC/fabric/blob/653223279f55f79898402b8463a03c95ef5f79f0/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/storage/StorageUtil.java#L124-L148

commented

It only works for List<SingleSlotStorage<T>>, which wrappers around vanilla inventories contain under the hood, but we don't really know what exactly is a vanilla wrapper. ;)

We could add an instanceof check for InventoryStorage, however I believe this would still be a problem with double chests because they use a CombinedStorage for the two parts.

A clean way to handle this in the transfer API would be nice. BTW the API is experimental but it's still safe to use.

commented

Implementation of a separate item transfer instead of FAPI doesn't worth efforts.