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

Fix container management #154

Merged
merged 17 commits into from
Jun 28, 2023

Conversation

ArtificialDriver
Copy link
Collaborator

  • Adds specs for withdraw / deposit
  • Completes the implementation of the shift click method to correctly send the changed slots
  • Fixes the data types of the click_window packet

Copy link
Collaborator

@Gjum Gjum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a high level note, getting rid of force_reset_hack may pass the simple tests, but in the long run means that you'll have to implement each and every combination of click type and inventory state, including partial slots, NBT comparison, and "special" slots that can only receive certain item types (eg, furnace). Otherwise client-server inventory desync will be inevitable.

@@ -132,7 +132,6 @@ class Rosegold::Window

def click(slot_nr, right = false, shift = false, double = false)
send_click ClickWindow.click self, slot_nr, right, shift, double
force_reset_hack # TODO update slots
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The client must update the slots to the new states after the click.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain to me how this hack exactly works? (I didn't observe it to be working so I removed it during test; probably shouldn't have committed this)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a probably better solution is to implement the few basic things bots need to do (pretty much exclusively "quick swap" (shift click) and implement the slot management directly
Once we get to crafting we'll need a more robust API but for now I think something similar to this is fine

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shift clicking is one of the more complex click modes to implement (see other comment); if you want something simple but useful you can start with "swap with hotbar".

The way the hack works is it sends an invalid variant of the click you want to execute, the server executes it as expected but notices that the client state is desynchronized and sends the entire inventory state again. As a result, the client only has to wait for the updated inventory state but doesn't need to implement the complex click logic itself.

src/rosegold/client.cr Outdated Show resolved Hide resolved
Comment on lines +107 to +108
# Find first empty slot in target container
target_slot = find_empty_slot target
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shift clicking is also possible when there are no empty slots, but some matching target slots are not entirely full. This also requires comparing NBT data.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree; think this can be done as a separate issue though (I'll add a comment)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image I think the client specifies it. But we'll also need to account for >2 slots being updated at once like so ^^

src/rosegold/control/inventory.cr Outdated Show resolved Hide resolved
Just don't close the other window if the server opens a new one
@grepsedawk grepsedawk merged commit e2bcc50 into RosegoldMC:main Jun 28, 2023
grepsedawk added a commit that referenced this pull request Jun 28, 2023
@grepsedawk
Copy link
Collaborator

Wait, shoot I wanted to turn on automerge

@grepsedawk
Copy link
Collaborator

Whelp, I fixed the main issues with this at least...
I'll test more with this change

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.

3 participants