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