Skip to content

Commit 15fe2be

Browse files
committed
Fix anvil
1 parent cf0985b commit 15fe2be

File tree

4 files changed

+15
-18
lines changed

4 files changed

+15
-18
lines changed

crates/valence_anvil/src/lib.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ impl AnvilLevel {
8383
.iter()
8484
.map(|(id, name, _)| (name.to_string_ident(), id))
8585
.collect(),
86-
height: 0, // Assigned later.
87-
min_y: 0, // Assigned later.
8886
}),
8987
ignored_chunks: HashSet::new(),
9088
pending: HashMap::new(),
@@ -139,10 +137,6 @@ struct ChunkWorkerState {
139137
decompress_buf: Vec<u8>,
140138
/// Mapping of biome names to their biome ID.
141139
biome_to_id: BTreeMap<Ident<String>, BiomeId>,
142-
/// Height of chunks in the instance.
143-
height: u32,
144-
/// Minimum Y position of chunks in the instance.
145-
min_y: i32,
146140
}
147141

148142
impl ChunkWorkerState {
@@ -291,11 +285,9 @@ impl Plugin for AnvilPlugin {
291285
}
292286
}
293287

294-
fn init_anvil(mut query: Query<(&mut AnvilLevel, &Instance), Added<AnvilLevel>>) {
295-
for (mut level, inst) in &mut query {
296-
if let Some(mut state) = level.worker_state.take() {
297-
state.height = inst.height();
298-
state.min_y = inst.min_y();
288+
fn init_anvil(mut query: Query<&mut AnvilLevel, (Added<AnvilLevel>, With<Instance>)>) {
289+
for mut level in &mut query {
290+
if let Some(state) = level.worker_state.take() {
299291
thread::spawn(move || anvil_worker(state));
300292
}
301293
}

crates/valence_anvil/src/parse_chunk.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pub(crate) fn parse_chunk(
188188
let z = i / 16 % 16;
189189
let y = i / (16 * 16);
190190

191-
chunk.set_block_state(x, y, z, block);
191+
chunk.set_block_state(x, sect_y * 16 + y, z, block);
192192

193193
i += 1;
194194
}
@@ -255,7 +255,7 @@ pub(crate) fn parse_chunk(
255255
let z = i / 4 % 4;
256256
let y = i / (4 * 4);
257257

258-
chunk.set_biome(x, y, z, biome);
258+
chunk.set_biome(x, sect_y * 4 + y, z, biome);
259259

260260
i += 1;
261261
}

crates/valence_instance/src/chunk/loaded.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,17 @@ impl LoadedChunk {
170170
let old_sections = self
171171
.sections
172172
.iter_mut()
173-
.map(|sect| {
173+
.zip(chunk.sections)
174+
.map(|(sect, other_sect)| {
174175
sect.section_updates.clear();
175176

176177
unloaded::Section {
177-
block_states: mem::take(&mut sect.block_states),
178-
biomes: mem::take(&mut sect.biomes),
178+
block_states: mem::replace(&mut sect.block_states, other_sect.block_states),
179+
biomes: mem::replace(&mut sect.biomes, other_sect.biomes),
179180
}
180181
})
181182
.collect();
182-
let old_block_entities = mem::take(&mut self.block_entities);
183+
let old_block_entities = mem::replace(&mut self.block_entities, chunk.block_entities);
183184
self.changed_block_entities.clear();
184185
self.changed_biomes = false;
185186
self.packet_buf.clear();

examples/anvil_loading.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,14 @@ fn handle_chunk_loads(
100100
}
101101
ChunkLoadStatus::Failed(e) => {
102102
// Something went wrong.
103-
eprintln!(
103+
let errmsg = format!(
104104
"failed to load chunk at ({}, {}): {e:#}",
105105
event.pos.x, event.pos.z
106106
);
107+
108+
eprintln!("{errmsg}");
109+
inst.send_chat_message(errmsg.color(Color::RED));
110+
107111
inst.insert_chunk(event.pos, UnloadedChunk::new());
108112
}
109113
}

0 commit comments

Comments
 (0)