Skip to content

Fixed factory gauge unlinking from display links when moved#10168

Open
LIUKRAST wants to merge 1 commit intoCreators-of-Create:mc1.21.1/devfrom
LIUKRAST:display_link_fix
Open

Fixed factory gauge unlinking from display links when moved#10168
LIUKRAST wants to merge 1 commit intoCreators-of-Create:mc1.21.1/devfrom
LIUKRAST:display_link_fix

Conversation

@LIUKRAST
Copy link
Copy Markdown

This pull request tries to solve a simple issue happening with factory gauges & display links:

Steps to reproduce

  • Place down a display link connected to any target
  • Place down a factory gauge, set it up and connect it with the display link
  • Open the Display link screen so that the factory gauge is detected
  • Open the factory gauge screen
  • Move the gauge to any slot (even in the same block)

The display link will still be connected to the gauge, but it will not update anymore unless you open the screen again

The solution

I'll first show the pipeline of what happens to then explain my solution

  • Method moveTo is invoked to start moving all the panels
  • Arrives to the line commented with Disconnect links. Here is very important because our display link is now disconnected from the panel
  • Arrives to line commented with add to new BE where it calls attachBehaviourLate(this)
  • Attach behaviour late calls behaviour.initialize(), which in FactoryPanelBehaviour calls notifyRedstoneOutputs()
  • Notify redstone outputs iterates all links including, guess what, our display link! Calling linkAt.notifyLink()
  • NotifyLink calls onNotify.run() which in our display link calls updateGatheredData()
  • Update gathered data now calls getSourcePosition, which will NOT return our factory panel position because as we said before, it's now unlinked. Now the display link is successfully unlinked from our panel, and it will be re-linked later, but this resets all the information, requiring, as said before, to setup everything again from the screen.

The Solution, now for real

My solution was simple, we store all the connection with display links inside a map, remove them from the targetedByLinks map of the moving factory panel, so that on behaviour initialize it will not broadcast his update to display links, thinking he is not connected to any. Finally, after initializing, we re-add all the connections from the map to our gauge, successfully tricking the display link into thinking he never disconnected

Moral of the story

I know this is a small issue, but working on my addons I find myself in these small edge-situations and being scared this was my code's problem, I solved it. Hope this PR can help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant