refactor(inventory): replace per-slot Arc<Mutex<ItemStack>> with container-level synchronization
This commit is contained in:
1 parent
ffcf09ece4
commit
63d97e2c82
121 files changed
+1674
-1931
No files matched your search
@@ -94,18 +94,14 @@ impl ScreenHandler for BeaconScreenHandler {
|
||||
let slot = self.get_behaviour().slots[slot_index as usize].clone();
|
||||
|
||||
if slot.has_stack().await {
|
||||
let slot_stack_lock = slot.get_stack().await;
|
||||
let slot_stack_guard = slot_stack_lock.lock().await;
|
||||
stack_left = slot_stack_guard.clone();
|
||||
drop(slot_stack_guard);
|
||||
|
||||
let mut slot_stack_mut = slot_stack_lock.lock().await;
|
||||
let mut slot_stack = slot.get_stack().await;
|
||||
stack_left = slot_stack.clone();
|
||||
|
||||
if slot_index == 0 {
|
||||
// Move from the single beacon slot to the player inventory (slots 1 to end)
|
||||
if !self
|
||||
.insert_item(
|
||||
&mut slot_stack_mut,
|
||||
&mut slot_stack,
|
||||
1,
|
||||
self.get_behaviour().slots.len() as i32,
|
||||
true,
|
||||
@@ -116,17 +112,15 @@ impl ScreenHandler for BeaconScreenHandler {
|
||||
}
|
||||
} else {
|
||||
// Move from player inventory into the beacon payment slot (slot 0)
|
||||
if !self.insert_item(&mut slot_stack_mut, 0, 1, false).await {
|
||||
if !self.insert_item(&mut slot_stack, 0, 1, false).await {
|
||||
return ItemStack::EMPTY.clone();
|
||||
}
|
||||
}
|
||||
|
||||
if slot_stack_mut.is_empty() {
|
||||
drop(slot_stack_mut);
|
||||
if slot_stack.is_empty() {
|
||||
slot.set_stack(ItemStack::EMPTY.clone()).await;
|
||||
} else {
|
||||
drop(slot_stack_mut);
|
||||
slot.mark_dirty().await;
|
||||
slot.set_stack(slot_stack).await;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user