1717 * <https://www.gnu.org/licenses/>.
1818 */
1919
20- use std:: cmp:: Ordering ;
20+ use std:: { cmp:: Ordering , sync :: Arc } ;
2121
2222use rayon:: prelude:: * ;
2323
@@ -31,15 +31,16 @@ use crate::{
3131 Encoder ,
3232 } ,
3333 world:: { blocks:: Blocks , World } ,
34+ CrawlState ,
3435} ;
3536
3637#[ derive( Debug ) ]
3738pub struct WorldCache {
3839 pub encoded : Vec < Vec < u8 > > ,
3940}
4041
41- impl From < World > for WorldCache {
42- fn from ( world : World ) -> Self {
42+ impl WorldCache {
43+ pub fn from_anvil ( crawlstate : CrawlState , world : World ) -> Self {
4344 let mut chunks = world. 0 . iter ( ) . collect :: < Vec < _ > > ( ) ;
4445
4546 chunks. sort_by ( |( ( ax, az) , _) , ( ( bx, bz) , _) | {
@@ -54,7 +55,7 @@ impl From<World> for WorldCache {
5455
5556 let chunks = chunks
5657 . par_iter ( )
57- . map ( |( _, c) | ChunkDataUpdateLightC :: new ( c, & block_states) )
58+ . map ( |( _, c) | ChunkDataUpdateLightC :: new ( crawlstate . clone ( ) , c, & block_states) )
5859 . collect :: < Vec < ChunkDataUpdateLightC < ' _ > > > ( ) ;
5960
6061 let encoded = chunks
@@ -76,13 +77,15 @@ impl From<World> for WorldCache {
7677pub struct RegistryCache {
7778 pub encoded : Vec < u8 > ,
7879 pub the_end_id : VarInt ,
80+ pub the_end_biome_id : u16 ,
7981}
8082
8183impl From < & AllRegistries > for RegistryCache {
8284 fn from ( registry : & AllRegistries ) -> Self {
8385 let mut encoder = Encoder :: new ( ) ;
8486
8587 let dimensions = Registry :: from ( registry. dimension_type . clone ( ) ) ;
88+ let biomes = Registry :: from ( registry. biome . clone ( ) ) ;
8689 encoder
8790 . append_packet ( & Registry :: from ( registry. trim_material . clone ( ) ) )
8891 . expect ( "Failed to encode trim material" ) ;
@@ -92,9 +95,6 @@ impl From<&AllRegistries> for RegistryCache {
9295 encoder
9396 . append_packet ( & Registry :: from ( registry. banner_pattern . clone ( ) ) )
9497 . expect ( "Failed to encode banner pattern" ) ;
95- encoder
96- . append_packet ( & Registry :: from ( registry. biome . clone ( ) ) )
97- . expect ( "Failed to encode biome" ) ;
9898 encoder
9999 . append_packet ( & Registry :: from ( registry. chat_type . clone ( ) ) )
100100 . expect ( "Failed to encode chat type" ) ;
@@ -104,6 +104,9 @@ impl From<&AllRegistries> for RegistryCache {
104104 encoder
105105 . append_packet ( & dimensions)
106106 . expect ( "Failed to encode dimensions" ) ;
107+ encoder
108+ . append_packet ( & biomes)
109+ . expect ( "Failed to encode biomes" ) ;
107110 encoder
108111 . append_packet ( & Registry :: from ( registry. wolf_variant . clone ( ) ) )
109112 . expect ( "Failed to encode wolf variants" ) ;
@@ -114,6 +117,7 @@ impl From<&AllRegistries> for RegistryCache {
114117 Self {
115118 encoded : encoder. take ( ) . to_vec ( ) ,
116119 the_end_id : VarInt ( dimensions. index_of ( "minecraft:the_end" ) ) ,
120+ the_end_biome_id : biomes. index_of ( "minecraft:the_end" ) as u16 ,
117121 }
118122 }
119123}
0 commit comments