fix so that it actually always updates both clients
This commit is contained in:
parent
daaafeefea
commit
d07eec2245
@ -32,7 +32,12 @@ impl Click {
|
||||
-999 => Slot::OutsideInventory,
|
||||
_ => {
|
||||
// TODO: Error here
|
||||
Slot::Normal(slot.try_into().unwrap())
|
||||
let slot = slot.try_into();
|
||||
if let Ok(slot) = slot {
|
||||
Slot::Normal(slot)
|
||||
} else {
|
||||
Slot::OutsideInventory
|
||||
}
|
||||
}
|
||||
};
|
||||
let button = match button {
|
||||
|
||||
@ -66,7 +66,6 @@ impl Container for Chest {
|
||||
}
|
||||
|
||||
fn all_slots(&mut self) -> Vec<&mut Option<ItemStack>> {
|
||||
dbg!(self.slots.iter().len());
|
||||
self.slots.iter_mut().collect()
|
||||
}
|
||||
|
||||
|
||||
@ -4,15 +4,15 @@ use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x15)]
|
||||
pub struct CSetContainerSlot<'a> {
|
||||
pub struct CSetContainerSlot {
|
||||
window_id: i8,
|
||||
state_id: VarInt,
|
||||
slot: i16,
|
||||
slot_data: &'a Slot,
|
||||
slot_data: Slot,
|
||||
}
|
||||
|
||||
impl<'a> CSetContainerSlot<'a> {
|
||||
pub fn new(window_id: i8, state_id: i32, slot: usize, slot_data: &'a Slot) -> Self {
|
||||
impl CSetContainerSlot {
|
||||
pub fn new(window_id: i8, state_id: i32, slot: usize, slot_data: Slot) -> Self {
|
||||
Self {
|
||||
window_id,
|
||||
state_id: state_id.into(),
|
||||
|
||||
@ -119,6 +119,7 @@ impl Player {
|
||||
};
|
||||
// This is just checking for regular desync, client hasn't done anything malicious
|
||||
if current_state_id != packet.state_id.0 {
|
||||
dbg!(current_state_id, packet.state_id.0);
|
||||
self.set_container_content(opened_container.as_deref_mut());
|
||||
return Ok(());
|
||||
}
|
||||
@ -328,36 +329,54 @@ impl Player {
|
||||
.into_iter()
|
||||
.filter(|player_id| *player_id != self.entity_id())
|
||||
.collect_vec();
|
||||
let mut container = container.lock().or(Err(InventoryError::LockError))?;
|
||||
dbg!(&player_ids);
|
||||
let player_token = self.client.token;
|
||||
|
||||
// TODO: Figure out better way to get only the players from player_ids
|
||||
// Also refactor out a better method to get individual advanced state ids
|
||||
|
||||
let world = self.world.lock().await;
|
||||
dbg!("here");
|
||||
let players = world
|
||||
.current_players
|
||||
.iter()
|
||||
.filter_map(|(token, player)| {
|
||||
if player_ids.contains(&(token.0 as i32)) {
|
||||
Some(player.clone())
|
||||
dbg!(token);
|
||||
if *token != player_token {
|
||||
let entity_id = player.lock().unwrap().entity_id();
|
||||
if player_ids.contains(&entity_id) {
|
||||
Some(player.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect_vec();
|
||||
std::mem::drop(world);
|
||||
drop(world);
|
||||
for player in players {
|
||||
dbg!("really shouldn't be here");
|
||||
dbg!("here");
|
||||
let mut player = player.lock().unwrap();
|
||||
let mut container =
|
||||
OptionallyCombinedContainer::new(&mut self.inventory, Some(container.deref_mut()));
|
||||
let state_id = container.advance_state_id();
|
||||
let all_slots = container.all_slots_ref();
|
||||
dbg!(player.entity_id());
|
||||
let total_opened_containers = player.inventory.total_opened_containers;
|
||||
let mut container = container.lock().or(Err(InventoryError::LockError))?;
|
||||
let mut combined_container = OptionallyCombinedContainer::new(
|
||||
&mut player.inventory,
|
||||
Some(container.deref_mut()),
|
||||
);
|
||||
let state_id = combined_container.advance_state_id();
|
||||
let all_slots = combined_container.all_slots_ref();
|
||||
|
||||
let slot = Slot::from(all_slots[slot_index]);
|
||||
let packet =
|
||||
CSetContainerSlot::new(*container.window_type() as i8, state_id, slot_index, &slot);
|
||||
player.client.send_packet(&packet)
|
||||
let packet = CSetContainerSlot::new(
|
||||
dbg!(total_opened_containers) as i8,
|
||||
state_id,
|
||||
slot_index,
|
||||
slot,
|
||||
);
|
||||
player.client.send_packet(&packet);
|
||||
drop(container)
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@ -123,6 +123,7 @@ impl Server {
|
||||
// Basicly the default world
|
||||
// TODO: select default from config
|
||||
let world = self.worlds[0].clone();
|
||||
|
||||
let player = Arc::new(Mutex::new(Player::new(
|
||||
client,
|
||||
world.clone(),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user