@@ -7,14 +7,14 @@ use crate::resource_location::ResourceLocation;
7
7
use azalea_buf:: { BufReadError , McBuf , McBufReadable , McBufWritable } ;
8
8
#[ cfg( feature = "serde" ) ]
9
9
use serde:: { Deserialize , Serialize } ;
10
- use std:: fmt:: Display ;
11
10
use std:: str:: FromStr ;
12
11
use std:: {
13
12
fmt,
14
13
hash:: Hash ,
15
14
io:: { Cursor , Write } ,
16
15
ops:: { Add , AddAssign , Mul , Rem , Sub } ,
17
16
} ;
17
+ use std:: num:: { ParseFloatError , ParseIntError } ;
18
18
19
19
macro_rules! vec3_impl {
20
20
( $name: ident, $type: ty) => {
@@ -272,33 +272,6 @@ impl BlockPos {
272
272
}
273
273
}
274
274
275
- impl Display for BlockPos {
276
- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
277
- write ! ( f, "({}, {}, {})" , self . x, self . y, self . z)
278
- }
279
- }
280
-
281
- impl FromStr for BlockPos {
282
- type Err = & ' static str ;
283
-
284
- fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
285
- let pos = s
286
- . trim_matches ( |c| c == '(' || c == ')' )
287
- . split ( ',' )
288
- . collect :: < Vec < _ > > ( ) ;
289
-
290
- if pos. len ( ) != 3 {
291
- return Err ( "Must be a length of 3" ) ;
292
- }
293
-
294
- Ok ( BlockPos {
295
- x : pos[ 0 ] . parse ( ) ?,
296
- y : pos[ 1 ] . parse ( ) ?,
297
- z : pos[ 2 ] . parse ( ) ?,
298
- } )
299
- }
300
- }
301
-
302
275
/// Chunk coordinates are used to represent where a chunk is in the world. You
303
276
/// can convert the x and z to block coordinates by multiplying them by 16.
304
277
#[ derive( Clone , Copy , Debug , Default , PartialEq , Eq ) ]
@@ -602,6 +575,46 @@ impl fmt::Display for Vec3 {
602
575
}
603
576
}
604
577
578
+ impl FromStr for BlockPos {
579
+ type Err = String ;
580
+
581
+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
582
+ let pos = s
583
+ . split ( ' ' )
584
+ . collect :: < Vec < _ > > ( ) ;
585
+
586
+ if pos. len ( ) != 3 {
587
+ return Err ( "Must be a length of 3" . to_string ( ) ) ;
588
+ }
589
+
590
+ Ok ( BlockPos {
591
+ x : pos[ 0 ] . parse ( ) . map_err ( |e : ParseIntError | e. to_string ( ) ) ?,
592
+ y : pos[ 1 ] . parse ( ) . map_err ( |e : ParseIntError | e. to_string ( ) ) ?,
593
+ z : pos[ 2 ] . parse ( ) . map_err ( |e : ParseIntError | e. to_string ( ) ) ?,
594
+ } )
595
+ }
596
+ }
597
+
598
+ impl FromStr for Vec3 {
599
+ type Err = String ;
600
+
601
+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
602
+ let pos = s
603
+ . split ( ' ' )
604
+ . collect :: < Vec < _ > > ( ) ;
605
+
606
+ if pos. len ( ) != 3 {
607
+ return Err ( "Must be a length of 3" . to_string ( ) ) ;
608
+ }
609
+
610
+ Ok ( Vec3 {
611
+ x : pos[ 0 ] . parse ( ) . map_err ( |e : ParseFloatError | e. to_string ( ) ) ?,
612
+ y : pos[ 1 ] . parse ( ) . map_err ( |e : ParseFloatError | e. to_string ( ) ) ?,
613
+ z : pos[ 2 ] . parse ( ) . map_err ( |e : ParseFloatError | e. to_string ( ) ) ?,
614
+ } )
615
+ }
616
+ }
617
+
605
618
const PACKED_X_LENGTH : u64 = 1 + 25 ; // minecraft does something a bit more complicated to get this 25
606
619
const PACKED_Z_LENGTH : u64 = PACKED_X_LENGTH ;
607
620
const PACKED_Y_LENGTH : u64 = 64 - PACKED_X_LENGTH - PACKED_Z_LENGTH ;
0 commit comments