mirror of
https://github.com/italicsjenga/valence.git
synced 2024-12-23 14:31:30 +11:00
Improve BlockPos API
This commit is contained in:
parent
c14bf88bd1
commit
232b76a8f7
|
@ -1,6 +1,7 @@
|
|||
use std::io::{Read, Write};
|
||||
|
||||
use anyhow::bail;
|
||||
use vek::Vec3;
|
||||
|
||||
use crate::protocol::{Decode, Encode};
|
||||
|
||||
|
@ -15,6 +16,10 @@ impl BlockPos {
|
|||
pub const fn new(x: i32, y: i32, z: i32) -> Self {
|
||||
Self { x, y, z }
|
||||
}
|
||||
|
||||
pub fn at(pos: impl Into<Vec3<f64>>) -> Self {
|
||||
pos.into().floor().as_::<i32>().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl Encode for BlockPos {
|
||||
|
@ -71,6 +76,18 @@ impl From<BlockPos> for [i32; 3] {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Vec3<i32>> for BlockPos {
|
||||
fn from(pos: Vec3<i32>) -> Self {
|
||||
Self::new(pos.x, pos.y, pos.z)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BlockPos> for Vec3<i32> {
|
||||
fn from(pos: BlockPos) -> Self {
|
||||
Vec3::new(pos.x, pos.y, pos.z)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Reference in a new issue