mirror of
https://github.com/italicsjenga/valence.git
synced 2025-01-26 05:26:34 +11:00
Improve BlockPos API
This commit is contained in:
parent
c14bf88bd1
commit
232b76a8f7
1 changed files with 17 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
use anyhow::bail;
|
use anyhow::bail;
|
||||||
|
use vek::Vec3;
|
||||||
|
|
||||||
use crate::protocol::{Decode, Encode};
|
use crate::protocol::{Decode, Encode};
|
||||||
|
|
||||||
|
@ -15,6 +16,10 @@ impl BlockPos {
|
||||||
pub const fn new(x: i32, y: i32, z: i32) -> Self {
|
pub const fn new(x: i32, y: i32, z: i32) -> Self {
|
||||||
Self { x, y, z }
|
Self { x, y, z }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn at(pos: impl Into<Vec3<f64>>) -> Self {
|
||||||
|
pos.into().floor().as_::<i32>().into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Encode for BlockPos {
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Add table
Reference in a new issue