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

Clean-up digging operation when client is disconnected #164

Merged
merged 1 commit into from
Jul 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/rosegold/control/interactions.cr
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,10 @@ class Rosegold::Interactions
attack

spawn do
while digging?
while digging? && client.connected?
cancel = false
reached = reach_block_or_entity
sleep 1.tick
next sleep 1.tick if !reached

case reached
case reached = wait_for_reached_block
when ReachedBlock
start_digging reached

Expand All @@ -84,6 +81,14 @@ class Rosegold::Interactions
end
end

def wait_for_reached_block
until reached = reach_block_or_entity
sleep 1.tick
end

reached
end

private def attack
if reached = reach_block_or_entity
return if reached.is_a? ReachedBlock
Expand Down
Loading