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
@@ -140,12 +140,8 @@ impl ScreenHandler for GUIScreenHandler {
|
||||
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();
|
||||
let container_slots = i32::from(self.rows * self.columns);
|
||||
|
||||
if slot_index < container_slots {
|
||||
@@ -155,7 +151,7 @@ impl ScreenHandler for GUIScreenHandler {
|
||||
}
|
||||
if !self
|
||||
.insert_item(
|
||||
&mut slot_stack_mut,
|
||||
&mut slot_stack,
|
||||
container_slots,
|
||||
self.get_behaviour().slots.len() as i32,
|
||||
true,
|
||||
@@ -170,7 +166,7 @@ impl ScreenHandler for GUIScreenHandler {
|
||||
return ItemStack::EMPTY.clone();
|
||||
}
|
||||
if !self
|
||||
.insert_item(&mut slot_stack_mut, 0, container_slots, false)
|
||||
.insert_item(&mut slot_stack, 0, container_slots, false)
|
||||
.await
|
||||
{
|
||||
// Move from player area to inventory (start)
|
||||
@@ -178,12 +174,10 @@ impl ScreenHandler for GUIScreenHandler {
|
||||
}
|
||||
}
|
||||
|
||||
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