mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
fix InstanceName desync
This commit is contained in:
parent
11a74f215e
commit
881055e587
8 changed files with 64 additions and 38 deletions
|
@ -67,7 +67,7 @@ pub struct ChunkBatchFinishedEvent {
|
||||||
|
|
||||||
pub fn handle_receive_chunk_events(
|
pub fn handle_receive_chunk_events(
|
||||||
mut events: EventReader<ReceiveChunkEvent>,
|
mut events: EventReader<ReceiveChunkEvent>,
|
||||||
mut query: Query<&mut InstanceHolder>,
|
mut query: Query<&InstanceHolder>,
|
||||||
) {
|
) {
|
||||||
for event in events.read() {
|
for event in events.read() {
|
||||||
let pos = ChunkPos::new(event.packet.x, event.packet.z);
|
let pos = ChunkPos::new(event.packet.x, event.packet.z);
|
||||||
|
|
|
@ -64,7 +64,7 @@ pub struct ConfigPacketHandler<'a> {
|
||||||
}
|
}
|
||||||
impl ConfigPacketHandler<'_> {
|
impl ConfigPacketHandler<'_> {
|
||||||
pub fn registry_data(&mut self, p: &ClientboundRegistryData) {
|
pub fn registry_data(&mut self, p: &ClientboundRegistryData) {
|
||||||
as_system::<Query<&mut InstanceHolder>>(self.ecs, |mut query| {
|
as_system::<Query<&InstanceHolder>>(self.ecs, |mut query| {
|
||||||
let instance_holder = query.get_mut(self.player).unwrap();
|
let instance_holder = query.get_mut(self.player).unwrap();
|
||||||
let mut instance = instance_holder.instance.write();
|
let mut instance = instance_holder.instance.write();
|
||||||
|
|
||||||
|
|
|
@ -227,7 +227,7 @@ impl GamePacketHandler<'_> {
|
||||||
let new_instance_name = p.common.dimension.clone();
|
let new_instance_name = p.common.dimension.clone();
|
||||||
|
|
||||||
if let Some(mut instance_name) = instance_name {
|
if let Some(mut instance_name) = instance_name {
|
||||||
*instance_name = instance_name.clone();
|
**instance_name = new_instance_name.clone();
|
||||||
} else {
|
} else {
|
||||||
commands
|
commands
|
||||||
.entity(self.player)
|
.entity(self.player)
|
||||||
|
@ -243,7 +243,7 @@ impl GamePacketHandler<'_> {
|
||||||
|
|
||||||
// add this world to the instance_container (or don't if it's already
|
// add this world to the instance_container (or don't if it's already
|
||||||
// there)
|
// there)
|
||||||
let weak_instance = instance_container.insert(
|
let weak_instance = instance_container.get_or_insert(
|
||||||
new_instance_name.clone(),
|
new_instance_name.clone(),
|
||||||
dimension_data.height,
|
dimension_data.height,
|
||||||
dimension_data.min_y,
|
dimension_data.min_y,
|
||||||
|
@ -591,7 +591,7 @@ impl GamePacketHandler<'_> {
|
||||||
pub fn set_chunk_cache_center(&mut self, p: &ClientboundSetChunkCacheCenter) {
|
pub fn set_chunk_cache_center(&mut self, p: &ClientboundSetChunkCacheCenter) {
|
||||||
debug!("Got chunk cache center packet {p:?}");
|
debug!("Got chunk cache center packet {p:?}");
|
||||||
|
|
||||||
as_system::<Query<&mut InstanceHolder>>(self.ecs, |mut query| {
|
as_system::<Query<&InstanceHolder>>(self.ecs, |mut query| {
|
||||||
let instance_holder = query.get_mut(self.player).unwrap();
|
let instance_holder = query.get_mut(self.player).unwrap();
|
||||||
let mut partial_world = instance_holder.partial_instance.write();
|
let mut partial_world = instance_holder.partial_instance.write();
|
||||||
|
|
||||||
|
@ -1122,7 +1122,7 @@ impl GamePacketHandler<'_> {
|
||||||
pub fn block_update(&mut self, p: &ClientboundBlockUpdate) {
|
pub fn block_update(&mut self, p: &ClientboundBlockUpdate) {
|
||||||
debug!("Got block update packet {p:?}");
|
debug!("Got block update packet {p:?}");
|
||||||
|
|
||||||
as_system::<Query<&mut InstanceHolder>>(self.ecs, |mut query| {
|
as_system::<Query<&InstanceHolder>>(self.ecs, |mut query| {
|
||||||
let local_player = query.get_mut(self.player).unwrap();
|
let local_player = query.get_mut(self.player).unwrap();
|
||||||
|
|
||||||
let world = local_player.instance.write();
|
let world = local_player.instance.write();
|
||||||
|
@ -1138,7 +1138,7 @@ impl GamePacketHandler<'_> {
|
||||||
pub fn section_blocks_update(&mut self, p: &ClientboundSectionBlocksUpdate) {
|
pub fn section_blocks_update(&mut self, p: &ClientboundSectionBlocksUpdate) {
|
||||||
debug!("Got section blocks update packet {p:?}");
|
debug!("Got section blocks update packet {p:?}");
|
||||||
|
|
||||||
as_system::<Query<&mut InstanceHolder>>(self.ecs, |mut query| {
|
as_system::<Query<&InstanceHolder>>(self.ecs, |mut query| {
|
||||||
let local_player = query.get_mut(self.player).unwrap();
|
let local_player = query.get_mut(self.player).unwrap();
|
||||||
let world = local_player.instance.write();
|
let world = local_player.instance.write();
|
||||||
for state in &p.states {
|
for state in &p.states {
|
||||||
|
@ -1311,7 +1311,7 @@ impl GamePacketHandler<'_> {
|
||||||
pub fn forget_level_chunk(&mut self, p: &ClientboundForgetLevelChunk) {
|
pub fn forget_level_chunk(&mut self, p: &ClientboundForgetLevelChunk) {
|
||||||
debug!("Got forget level chunk packet {p:?}");
|
debug!("Got forget level chunk packet {p:?}");
|
||||||
|
|
||||||
as_system::<Query<&mut InstanceHolder>>(self.ecs, |mut query| {
|
as_system::<Query<&InstanceHolder>>(self.ecs, |mut query| {
|
||||||
let local_player = query.get_mut(self.player).unwrap();
|
let local_player = query.get_mut(self.player).unwrap();
|
||||||
|
|
||||||
let mut partial_instance = local_player.partial_instance.write();
|
let mut partial_instance = local_player.partial_instance.write();
|
||||||
|
@ -1410,6 +1410,7 @@ impl GamePacketHandler<'_> {
|
||||||
&mut InstanceHolder,
|
&mut InstanceHolder,
|
||||||
&GameProfileComponent,
|
&GameProfileComponent,
|
||||||
&ClientInformation,
|
&ClientInformation,
|
||||||
|
Option<&mut InstanceName>,
|
||||||
),
|
),
|
||||||
With<LocalEntity>,
|
With<LocalEntity>,
|
||||||
>,
|
>,
|
||||||
|
@ -1419,11 +1420,19 @@ impl GamePacketHandler<'_> {
|
||||||
)>(
|
)>(
|
||||||
self.ecs,
|
self.ecs,
|
||||||
|(mut commands, mut query, mut events, mut instance_container, mut loaded_by_query)| {
|
|(mut commands, mut query, mut events, mut instance_container, mut loaded_by_query)| {
|
||||||
let (mut instance_holder, game_profile, client_information) =
|
let (mut instance_holder, game_profile, client_information, instance_name) =
|
||||||
query.get_mut(self.player).unwrap();
|
query.get_mut(self.player).unwrap();
|
||||||
|
|
||||||
let new_instance_name = p.common.dimension.clone();
|
let new_instance_name = p.common.dimension.clone();
|
||||||
|
|
||||||
|
if let Some(mut instance_name) = instance_name {
|
||||||
|
**instance_name = new_instance_name.clone();
|
||||||
|
} else {
|
||||||
|
commands
|
||||||
|
.entity(self.player)
|
||||||
|
.insert(InstanceName(new_instance_name.clone()));
|
||||||
|
}
|
||||||
|
|
||||||
let Some((_dimension_type, dimension_data)) = p
|
let Some((_dimension_type, dimension_data)) = p
|
||||||
.common
|
.common
|
||||||
.dimension_type(&instance_holder.instance.read().registries)
|
.dimension_type(&instance_holder.instance.read().registries)
|
||||||
|
@ -1433,7 +1442,7 @@ impl GamePacketHandler<'_> {
|
||||||
|
|
||||||
// add this world to the instance_container (or don't if it's already
|
// add this world to the instance_container (or don't if it's already
|
||||||
// there)
|
// there)
|
||||||
let weak_instance = instance_container.insert(
|
let weak_instance = instance_container.get_or_insert(
|
||||||
new_instance_name.clone(),
|
new_instance_name.clone(),
|
||||||
dimension_data.height,
|
dimension_data.height,
|
||||||
dimension_data.min_y,
|
dimension_data.min_y,
|
||||||
|
|
|
@ -101,6 +101,11 @@ impl Simulation {
|
||||||
pub fn tick(&mut self) {
|
pub fn tick(&mut self) {
|
||||||
tick_app(&mut self.app);
|
tick_app(&mut self.app);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn minecraft_entity_id(&self) -> MinecraftEntityId {
|
||||||
|
self.component::<MinecraftEntityId>()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn component<T: Component + Clone>(&self) -> T {
|
pub fn component<T: Component + Clone>(&self) -> T {
|
||||||
self.app.world().get::<T>(self.entity).unwrap().clone()
|
self.app.world().get::<T>(self.entity).unwrap().clone()
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,8 +131,9 @@ pub fn update_entity_chunk_positions(
|
||||||
mut query: Query<(Entity, &Position, &InstanceName, &mut EntityChunkPos), Changed<Position>>,
|
mut query: Query<(Entity, &Position, &InstanceName, &mut EntityChunkPos), Changed<Position>>,
|
||||||
instance_container: Res<InstanceContainer>,
|
instance_container: Res<InstanceContainer>,
|
||||||
) {
|
) {
|
||||||
for (entity, pos, world_name, mut entity_chunk_pos) in query.iter_mut() {
|
for (entity, pos, instance_name, mut entity_chunk_pos) in query.iter_mut() {
|
||||||
let instance_lock = instance_container.get(world_name).unwrap();
|
// TODO: move this inside of the if statement so it's not called as often
|
||||||
|
let instance_lock = instance_container.get(instance_name).unwrap();
|
||||||
let mut instance = instance_lock.write();
|
let mut instance = instance_lock.write();
|
||||||
|
|
||||||
let old_chunk = **entity_chunk_pos;
|
let old_chunk = **entity_chunk_pos;
|
||||||
|
|
|
@ -26,12 +26,14 @@ fn make_test_app() -> App {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_overworld(app: &mut App) -> Arc<RwLock<Instance>> {
|
pub fn insert_overworld(app: &mut App) -> Arc<RwLock<Instance>> {
|
||||||
app.world_mut().resource_mut::<InstanceContainer>().insert(
|
app.world_mut()
|
||||||
ResourceLocation::new("minecraft:overworld"),
|
.resource_mut::<InstanceContainer>()
|
||||||
384,
|
.get_or_insert(
|
||||||
-64,
|
ResourceLocation::new("minecraft:overworld"),
|
||||||
&RegistryHolder::default(),
|
384,
|
||||||
)
|
-64,
|
||||||
|
&RegistryHolder::default(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -248,12 +250,15 @@ fn test_top_slab_collision() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_weird_wall_collision() {
|
fn test_weird_wall_collision() {
|
||||||
let mut app = make_test_app();
|
let mut app = make_test_app();
|
||||||
let world_lock = app.world_mut().resource_mut::<InstanceContainer>().insert(
|
let world_lock = app
|
||||||
ResourceLocation::new("minecraft:overworld"),
|
.world_mut()
|
||||||
384,
|
.resource_mut::<InstanceContainer>()
|
||||||
-64,
|
.get_or_insert(
|
||||||
&RegistryHolder::default(),
|
ResourceLocation::new("minecraft:overworld"),
|
||||||
);
|
384,
|
||||||
|
-64,
|
||||||
|
&RegistryHolder::default(),
|
||||||
|
);
|
||||||
let mut partial_world = PartialInstance::default();
|
let mut partial_world = PartialInstance::default();
|
||||||
|
|
||||||
partial_world.chunks.set(
|
partial_world.chunks.set(
|
||||||
|
@ -307,12 +312,15 @@ fn test_weird_wall_collision() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_negative_coordinates_weird_wall_collision() {
|
fn test_negative_coordinates_weird_wall_collision() {
|
||||||
let mut app = make_test_app();
|
let mut app = make_test_app();
|
||||||
let world_lock = app.world_mut().resource_mut::<InstanceContainer>().insert(
|
let world_lock = app
|
||||||
ResourceLocation::new("minecraft:overworld"),
|
.world_mut()
|
||||||
384,
|
.resource_mut::<InstanceContainer>()
|
||||||
-64,
|
.get_or_insert(
|
||||||
&RegistryHolder::default(),
|
ResourceLocation::new("minecraft:overworld"),
|
||||||
);
|
384,
|
||||||
|
-64,
|
||||||
|
&RegistryHolder::default(),
|
||||||
|
);
|
||||||
let mut partial_world = PartialInstance::default();
|
let mut partial_world = PartialInstance::default();
|
||||||
|
|
||||||
partial_world.chunks.set(
|
partial_world.chunks.set(
|
||||||
|
@ -370,12 +378,15 @@ fn test_negative_coordinates_weird_wall_collision() {
|
||||||
#[test]
|
#[test]
|
||||||
fn spawn_and_unload_world() {
|
fn spawn_and_unload_world() {
|
||||||
let mut app = make_test_app();
|
let mut app = make_test_app();
|
||||||
let world_lock = app.world_mut().resource_mut::<InstanceContainer>().insert(
|
let world_lock = app
|
||||||
ResourceLocation::new("minecraft:overworld"),
|
.world_mut()
|
||||||
384,
|
.resource_mut::<InstanceContainer>()
|
||||||
-64,
|
.get_or_insert(
|
||||||
&RegistryHolder::default(),
|
ResourceLocation::new("minecraft:overworld"),
|
||||||
);
|
384,
|
||||||
|
-64,
|
||||||
|
&RegistryHolder::default(),
|
||||||
|
);
|
||||||
let mut partial_world = PartialInstance::default();
|
let mut partial_world = PartialInstance::default();
|
||||||
|
|
||||||
partial_world.chunks.set(
|
partial_world.chunks.set(
|
||||||
|
|
|
@ -16,7 +16,7 @@ pub struct PositionMoveRotation {
|
||||||
pub look_direction: LookDirection,
|
pub look_direction: LookDirection,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct RelativeMovements {
|
pub struct RelativeMovements {
|
||||||
pub x: bool,
|
pub x: bool,
|
||||||
pub y: bool,
|
pub y: bool,
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl InstanceContainer {
|
||||||
/// Add an empty world to the container (unless it already exists) and
|
/// Add an empty world to the container (unless it already exists) and
|
||||||
/// returns a strong reference to the world.
|
/// returns a strong reference to the world.
|
||||||
#[must_use = "the world will be immediately forgotten if unused"]
|
#[must_use = "the world will be immediately forgotten if unused"]
|
||||||
pub fn insert(
|
pub fn get_or_insert(
|
||||||
&mut self,
|
&mut self,
|
||||||
name: ResourceLocation,
|
name: ResourceLocation,
|
||||||
height: u32,
|
height: u32,
|
||||||
|
|
Loading…
Add table
Reference in a new issue