@@ -5,12 +5,11 @@ use crate::{errors::WorldError, vanilla_chunk_format::VanillaHeightmaps};
55use bitcode_derive:: { Decode , Encode } ;
66use deepsize:: DeepSizeOf ;
77use ferrumc_general_purpose:: data_packing:: i32:: read_nbit_i32;
8- use ferrumc_macros:: { NBTDeserialize , NBTSerialize } ;
8+ use ferrumc_macros:: { block , NBTDeserialize , NBTSerialize } ;
99use ferrumc_net_codec:: net_types:: var_int:: VarInt ;
1010use std:: cmp:: max;
1111use std:: collections:: HashMap ;
1212use tracing:: error;
13- use vanilla_chunk_format:: BlockData ;
1413// #[cfg(test)]
1514// const BLOCKSFILE: &[u8] = &[0];
1615
@@ -76,7 +75,9 @@ pub struct BiomeStates {
7675 pub palette : Vec < VarInt > ,
7776}
7877
79- fn convert_to_net_palette ( vanilla_palettes : Vec < BlockData > ) -> Result < Vec < VarInt > , WorldError > {
78+ fn convert_to_net_palette (
79+ vanilla_palettes : Vec < vanilla_chunk_format:: BlockData > ,
80+ ) -> Result < Vec < VarInt > , WorldError > {
8081 let mut new_palette = Vec :: new ( ) ;
8182 for palette in vanilla_palettes {
8283 if let Some ( id) = BLOCK2ID . get ( & palette) {
@@ -135,17 +136,17 @@ impl VanillaChunk {
135136 while i + bits_per_block < 64 {
136137 let palette_index = read_nbit_i32 ( chunk, bits_per_block as usize , i as u32 ) ?;
137138 let block = match palette. get ( palette_index as usize ) {
138- Some ( block) => block,
139+ Some ( block) => block. to_block_id ( ) ,
139140 None => {
140141 error ! ( "Could not find block for palette index: {}" , palette_index) ;
141- & BlockData :: default ( )
142+ BlockId :: default ( )
142143 }
143144 } ;
144145
145- if let Some ( count) = block_counts. get_mut ( & block. to_block_id ( ) ) {
146+ if let Some ( count) = block_counts. get_mut ( & block) {
146147 * count += 1 ;
147148 } else {
148- block_counts. insert ( block. to_block_id ( ) , 0 ) ;
149+ block_counts. insert ( block, 0 ) ;
149150 }
150151
151152 i += bits_per_block;
@@ -163,24 +164,8 @@ impl VanillaChunk {
163164 } ;
164165 // Count the number of blocks that are either air, void air, or cave air
165166 let mut air_blocks = * block_counts. get ( & BlockId :: default ( ) ) . unwrap_or ( & 0 ) as u16 ;
166- air_blocks += * block_counts
167- . get (
168- & BlockData {
169- name : "minecraft:void_air" . to_string ( ) ,
170- properties : None ,
171- }
172- . to_block_id ( ) ,
173- )
174- . unwrap_or ( & 0 ) as u16 ;
175- air_blocks += * block_counts
176- . get (
177- & BlockData {
178- name : "minecraft:cave_air" . to_string ( ) ,
179- properties : None ,
180- }
181- . to_block_id ( ) ,
182- )
183- . unwrap_or ( & 0 ) as u16 ;
167+ air_blocks += * block_counts. get ( & block ! ( "void_air" ) ) . unwrap_or ( & 0 ) as u16 ;
168+ air_blocks += * block_counts. get ( & block ! ( "cave_air" ) ) . unwrap_or ( & 0 ) as u16 ;
184169 let non_air_blocks = 4096 - air_blocks;
185170 let block_states = BlockStates {
186171 block_counts,
@@ -253,6 +238,7 @@ impl Chunk {
253238 for section in & mut sections {
254239 section. optimise ( ) . expect ( "Failed to optimise section" ) ;
255240 }
241+ block ! ( "stone" ) ;
256242 Chunk {
257243 x,
258244 z,
@@ -266,7 +252,6 @@ impl Chunk {
266252#[ cfg( test) ]
267253mod tests {
268254 use super :: * ;
269- use crate :: block_id:: BlockId ;
270255 use ferrumc_macros:: block;
271256
272257 #[ test]
@@ -322,11 +307,7 @@ mod tests {
322307 #[ test]
323308 fn test_false_positive ( ) {
324309 let mut chunk = Chunk :: new ( 0 , 0 , "overworld" . to_string ( ) ) ;
325- let block = BlockData {
326- name : "minecraft:stone" . to_string ( ) ,
327- properties : None ,
328- }
329- . to_block_id ( ) ;
310+ let block = block ! ( "stone" ) ;
330311 chunk. set_block ( 0 , 0 , 0 , block) . unwrap ( ) ;
331312 assert_ne ! ( chunk. get_block( 0 , 1 , 0 ) . unwrap( ) , block) ;
332313 }
0 commit comments