Skip to content

Commit

Permalink
Merge branch 'valence-rs:main' into anvil
Browse files Browse the repository at this point in the history
  • Loading branch information
TerminatorNL authored Dec 11, 2022
2 parents 5ce1a13 + 8b50e93 commit 4f57df7
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,21 @@ impl<C: Config> Inventory<C> {
mem::replace(old, new)
}

pub fn swap_slot(&mut self, idx_a: u16, idx_b: u16) {
assert!(idx_a < self.slot_count(), "slot index out of range");
assert!(idx_b < self.slot_count(), "slot index out of range");

if idx_a == idx_b || self.slots[idx_a as usize] == self.slots[idx_b as usize] {
// Nothing to do here, ignore.
return;
}

self.modified |= 1 << idx_a;
self.modified |= 1 << idx_b;

self.slots.swap(idx_a as usize, idx_b as usize);
}

pub fn slot_count(&self) -> u16 {
self.slots.len() as u16
}
Expand Down

0 comments on commit 4f57df7

Please sign in to comment.