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(
|
||||
mut events: EventReader<ReceiveChunkEvent>,
|
||||
mut query: Query<&mut InstanceHolder>,
|
||||
mut query: Query<&InstanceHolder>,
|
||||
) {
|
||||
for event in events.read() {
|
||||
let pos = ChunkPos::new(event.packet.x, event.packet.z);
|
||||
|
|
|
@ -64,7 +64,7 @@ pub struct ConfigPacketHandler<'a> {
|
|||
}
|
||||
impl ConfigPacketHandler<'_> {
|
||||
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 mut instance = instance_holder.instance.write();
|
||||
|
||||
|
|
|
@ -227,7 +227,7 @@ impl GamePacketHandler<'_> {
|
|||
let new_instance_name = p.common.dimension.clone();
|
||||
|
||||
if let Some(mut instance_name) = instance_name {
|
||||
*instance_name = instance_name.clone();
|
||||
**instance_name = new_instance_name.clone();
|
||||
} else {
|
||||
commands
|
||||
.entity(self.player)
|
||||
|
@ -243,7 +243,7 @@ impl GamePacketHandler<'_> {
|
|||
|
||||
// add this world to the instance_container (or don't if it's already
|
||||
// there)
|
||||
let weak_instance = instance_container.insert(
|
||||
let weak_instance = instance_container.get_or_insert(
|
||||
new_instance_name.clone(),
|
||||
dimension_data.height,
|
||||
dimension_data.min_y,
|
||||
|
@ -591,7 +591,7 @@ impl GamePacketHandler<'_> {
|
|||
pub fn set_chunk_cache_center(&mut self, p: &ClientboundSetChunkCacheCenter) {
|
||||
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 mut partial_world = instance_holder.partial_instance.write();
|
||||
|
||||
|
@ -1122,7 +1122,7 @@ impl GamePacketHandler<'_> {
|
|||
pub fn block_update(&mut self, p: &ClientboundBlockUpdate) {
|
||||
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 world = local_player.instance.write();
|
||||
|
@ -1138,7 +1138,7 @@ impl GamePacketHandler<'_> {
|
|||
pub fn section_blocks_update(&mut self, p: &ClientboundSectionBlocksUpdate) {
|
||||
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 world = local_player.instance.write();
|
||||
for state in &p.states {
|
||||
|
@ -1311,7 +1311,7 @@ impl GamePacketHandler<'_> {
|
|||
pub fn forget_level_chunk(&mut self, p: &ClientboundForgetLevelChunk) {
|
||||
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 mut partial_instance = local_player.partial_instance.write();
|
||||
|
@ -1410,6 +1410,7 @@ impl GamePacketHandler<'_> {
|
|||
&mut InstanceHolder,
|
||||
&GameProfileComponent,
|
||||
&ClientInformation,
|
||||
Option<&mut InstanceName>,
|
||||
),
|
||||
With<LocalEntity>,
|
||||
>,
|
||||
|
@ -1419,11 +1420,19 @@ impl GamePacketHandler<'_> {
|
|||
)>(
|
||||
self.ecs,
|
||||
|(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();
|
||||
|
||||
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
|
||||
.common
|
||||
.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
|
||||
// there)
|
||||
let weak_instance = instance_container.insert(
|
||||
let weak_instance = instance_container.get_or_insert(
|
||||
new_instance_name.clone(),
|
||||
dimension_data.height,
|
||||
dimension_data.min_y,
|
||||
|
|
|
@ -101,6 +101,11 @@ impl Simulation {
|
|||
pub fn tick(&mut self) {
|
||||
tick_app(&mut self.app);
|
||||
}
|
||||
|
||||
pub fn minecraft_entity_id(&self) -> MinecraftEntityId {
|
||||
self.component::<MinecraftEntityId>()
|
||||
}
|
||||
|
||||
pub fn component<T: Component + Clone>(&self) -> T {
|
||||
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>>,
|
||||
instance_container: Res<InstanceContainer>,
|
||||
) {
|
||||
for (entity, pos, world_name, mut entity_chunk_pos) in query.iter_mut() {
|
||||
let instance_lock = instance_container.get(world_name).unwrap();
|
||||
for (entity, pos, instance_name, mut entity_chunk_pos) in query.iter_mut() {
|
||||
// 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 old_chunk = **entity_chunk_pos;
|
||||
|
|
|
@ -26,7 +26,9 @@ fn make_test_app() -> App {
|
|||
}
|
||||
|
||||
pub fn insert_overworld(app: &mut App) -> Arc<RwLock<Instance>> {
|
||||
app.world_mut().resource_mut::<InstanceContainer>().insert(
|
||||
app.world_mut()
|
||||
.resource_mut::<InstanceContainer>()
|
||||
.get_or_insert(
|
||||
ResourceLocation::new("minecraft:overworld"),
|
||||
384,
|
||||
-64,
|
||||
|
@ -248,7 +250,10 @@ fn test_top_slab_collision() {
|
|||
#[test]
|
||||
fn test_weird_wall_collision() {
|
||||
let mut app = make_test_app();
|
||||
let world_lock = app.world_mut().resource_mut::<InstanceContainer>().insert(
|
||||
let world_lock = app
|
||||
.world_mut()
|
||||
.resource_mut::<InstanceContainer>()
|
||||
.get_or_insert(
|
||||
ResourceLocation::new("minecraft:overworld"),
|
||||
384,
|
||||
-64,
|
||||
|
@ -307,7 +312,10 @@ fn test_weird_wall_collision() {
|
|||
#[test]
|
||||
fn test_negative_coordinates_weird_wall_collision() {
|
||||
let mut app = make_test_app();
|
||||
let world_lock = app.world_mut().resource_mut::<InstanceContainer>().insert(
|
||||
let world_lock = app
|
||||
.world_mut()
|
||||
.resource_mut::<InstanceContainer>()
|
||||
.get_or_insert(
|
||||
ResourceLocation::new("minecraft:overworld"),
|
||||
384,
|
||||
-64,
|
||||
|
@ -370,7 +378,10 @@ fn test_negative_coordinates_weird_wall_collision() {
|
|||
#[test]
|
||||
fn spawn_and_unload_world() {
|
||||
let mut app = make_test_app();
|
||||
let world_lock = app.world_mut().resource_mut::<InstanceContainer>().insert(
|
||||
let world_lock = app
|
||||
.world_mut()
|
||||
.resource_mut::<InstanceContainer>()
|
||||
.get_or_insert(
|
||||
ResourceLocation::new("minecraft:overworld"),
|
||||
384,
|
||||
-64,
|
||||
|
|
|
@ -16,7 +16,7 @@ pub struct PositionMoveRotation {
|
|||
pub look_direction: LookDirection,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct RelativeMovements {
|
||||
pub x: bool,
|
||||
pub y: bool,
|
||||
|
|
|
@ -46,7 +46,7 @@ impl InstanceContainer {
|
|||
/// Add an empty world to the container (unless it already exists) and
|
||||
/// returns a strong reference to the world.
|
||||
#[must_use = "the world will be immediately forgotten if unused"]
|
||||
pub fn insert(
|
||||
pub fn get_or_insert(
|
||||
&mut self,
|
||||
name: ResourceLocation,
|
||||
height: u32,
|
||||
|
|
Loading…
Add table
Reference in a new issue