Skip to content

Commit

Permalink
crystal tool format
Browse files Browse the repository at this point in the history
  • Loading branch information
grepsedawk committed Jun 27, 2023
1 parent b0edbb8 commit 3095f73
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
5 changes: 2 additions & 3 deletions spec/integration/inventory_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Spectator.describe Rosegold::Bot do
sleep 1
bot.use_hand
sleep 1

expect((bot.inventory.inventory + bot.inventory.hotbar).map(&.item_id)).to contain "diamond_sword"
expect(bot.inventory.content.map(&.item_id)).not_to contain "diamond_sword"
end
Expand All @@ -115,7 +115,7 @@ Spectator.describe Rosegold::Bot do
sleep 1
bot.chat "/give #{bot.username} minecraft:diamond_sword 1"
sleep 1

bot.pitch = 90
bot.use_hand
sleep 1
Expand All @@ -129,7 +129,6 @@ Spectator.describe Rosegold::Bot do
expect((bot.inventory.inventory + bot.inventory.hotbar).map(&.item_id)).not_to contain "diamond_sword"
expect(bot.inventory.content.map(&.item_id)).to contain "diamond_sword"
end

end
end
end
Expand Down
14 changes: 7 additions & 7 deletions src/rosegold/control/inventory.cr
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,27 @@ class Rosegold::Inventory
deposit_at_least(count, spec)
end

private def find_empty_slot(source)
private def find_empty_slot(source)
empty_slot = nil

source.each do |slot|
if slot.empty?
empty_slot = slot
break
end
end

return empty_slot
empty_slot
end

private def shift_click_at_least(count, spec, source : Array(WindowSlot), target : Array(WindowSlot))
transferred = 0

# prefer large stacks for minimum clicks
# for equal stacks, preserve order
source.sort_by { |s| -s.count.to_i8 }.each do |slot|
next unless slot.matches? spec

# Find first empty slot in target container
target_slot = find_empty_slot target

Expand All @@ -113,8 +113,8 @@ class Rosegold::Inventory
# Swap slots
changed_slots = [
Rosegold::WindowSlot.new(target_slot.slot_nr, slot),
Rosegold::WindowSlot.new(slot.slot_nr, target_slot)
]
Rosegold::WindowSlot.new(slot.slot_nr, target_slot),
]

client.send_packet! Serverbound::ClickWindow.new :shift, 0_i8, slot.slot_nr.to_i16, changed_slots, client.window.id.to_u8, client.window.state_id.to_i32, client.window.cursor

Expand Down
2 changes: 1 addition & 1 deletion src/rosegold/world/slot.cr
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ class Rosegold::WindowSlot < Rosegold::Slot
def initialize(@slot_nr, slot)
super slot.item_id_int, slot.count, slot.nbt
end
end
end

0 comments on commit 3095f73

Please sign in to comment.