Skip to content

Transfer Analysis

gniftygnome edited this page Mar 8, 2022 · 3 revisions

Design Analysis a.k.a. what does vanilla actually do?

Note about lastTickTime

When we reach the transfer method via serverTick, the local hopper will have a lastTickTime equal to the current time. In order for the target to have lastTickTime >= the source, either both have now ticked in the current cycle OR the local hopper is the target and the source has not yet ticked in the current cycle. If the local hopper is the target, its transferCooldown will be updated to 8 as the last thing insertAndExtract does. So the 8 - k thing only matters when inserting ... or when a third-party is calling extract ... which I suspect exists for the hopper minecart...

Full run-down

TICK -> IF insert() OR extract() set THIS cooldown 8

insert() AND extract() AND transfer() ALL call private transfer()

private transfer():
  IF moved items TO empty non-disabled hopper
    IF FROM hopper
      IF TO ticked as recently as FROM
        reduce TO cooldown by 1 tick
      set TO cooldown (8 or 7)

successful hopper -> hopper item movement IN tick() via insertAndExtract():
  INSERT:   ALWAYS set FROM cooldown 8,  IFF TO was EMPTY (IF TO ticked as recently as FROM, set TO cooldown 7;  ELSE set TO cooldown 8)
  EXTRACT:  NEVER set FROM cooldown,     ALWAYS set TO cooldown 8

successful hopper -> hopper item movement OUTSIDE tick() via transfer() OR either public extract():
  INSERT:   NEVER set FROM cooldown,     IFF TO was EMPTY (IF TO ticked as recently as FROM, set TO cooldown 7;  ELSE set TO cooldown 8)
  EXTRACT:  NEVER set FROM cooldown,     IFF TO was EMPTY (IF TO ticked as recently as FROM, set TO cooldown 7;  ELSE set TO cooldown 8)

Practically speaking we only care about in-tick movement, so:

  • If you pull an item from something, set your own cooldown to (your default cooldown).
  • If you push an item to something, set your own cooldown to (your default cooldown) and notify the destination if it was previously empty.
  • When notified, compare your last tick time to world.getTime() and if your last tick time is as recent, set your cooldown to (your default cooldown - 1), otherwise set it to (your default cooldown).
Clone this wiki locally