nurtex_protocol/types/
block_pos.rs1use std::io::{self, Cursor, Write};
2
3use nurtex_codec::Buffer;
4
5#[derive(Debug, Clone, Copy, PartialEq)]
7pub struct BlockPos {
8 pub x: i32,
9 pub y: i32,
10 pub z: i32,
11}
12
13impl BlockPos {
14 pub fn new(x: i32, y: i32, z: i32) -> Self {
16 Self { x, y, z }
17 }
18
19 pub fn zero() -> Self {
21 Self { x: 0, y: 0, z: 0 }
22 }
23}
24
25impl Buffer for BlockPos {
26 fn read_buf(buffer: &mut Cursor<&[u8]>) -> Option<Self> {
27 Some(Self {
28 x: i32::read_buf(buffer)?,
29 y: i32::read_buf(buffer)?,
30 z: i32::read_buf(buffer)?,
31 })
32 }
33
34 fn write_buf(&self, buffer: &mut impl Write) -> io::Result<()> {
35 self.x.write_buf(buffer)?;
36 self.y.write_buf(buffer)?;
37 self.z.write_buf(buffer)?;
38 Ok(())
39 }
40}