mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
resolve some todos in az-core
This commit is contained in:
parent
33e1a1326a
commit
3c3952bb0b
6 changed files with 56 additions and 28 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -369,6 +369,7 @@ name = "azalea-core"
|
||||||
version = "0.11.0+mc1.21.4"
|
version = "0.11.0+mc1.21.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"azalea-buf",
|
"azalea-buf",
|
||||||
|
"azalea-chat",
|
||||||
"azalea-registry",
|
"azalea-registry",
|
||||||
"bevy_ecs",
|
"bevy_ecs",
|
||||||
"nohash-hasher",
|
"nohash-hasher",
|
||||||
|
|
|
@ -44,3 +44,19 @@ impl Add for BlockStates {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<HashSet<azalea_registry::Block>> for BlockStates {
|
||||||
|
fn from(set: HashSet<azalea_registry::Block>) -> Self {
|
||||||
|
Self {
|
||||||
|
set: set.into_iter().map(|b| b.into()).collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&HashSet<azalea_registry::Block>> for BlockStates {
|
||||||
|
fn from(set: &HashSet<azalea_registry::Block>) -> Self {
|
||||||
|
Self {
|
||||||
|
set: set.iter().map(|&b| b.into()).collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -13,10 +13,9 @@ bevy_ecs = { workspace = true, optional = true }
|
||||||
nohash-hasher = { workspace = true }
|
nohash-hasher = { workspace = true }
|
||||||
num-traits = { workspace = true }
|
num-traits = { workspace = true }
|
||||||
serde = { workspace = true, optional = true }
|
serde = { workspace = true, optional = true }
|
||||||
#serde_json = { workspace = true }
|
|
||||||
simdnbt = { workspace = true }
|
simdnbt = { workspace = true }
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
#uuid = { workspace = true }
|
azalea-chat = { path = "../azalea-chat", version = "0.11.0" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
bevy_ecs = ["dep:bevy_ecs"]
|
bevy_ecs = ["dep:bevy_ecs"]
|
||||||
|
|
|
@ -62,7 +62,10 @@ impl Direction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: make azalea_block use this instead of FacingCardinal
|
/// The four cardinal directions.
|
||||||
|
///
|
||||||
|
/// Note that azalea_block has a similar enum named `FacingCardinal` that is
|
||||||
|
/// used for block states.
|
||||||
#[derive(Clone, Copy, Debug, AzBuf, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, Debug, AzBuf, PartialEq, Eq, Hash)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
pub enum CardinalDirection {
|
pub enum CardinalDirection {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::io::{Cursor, Write};
|
use std::io::{Cursor, Write};
|
||||||
|
|
||||||
use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, BufReadError};
|
use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, BufReadError};
|
||||||
|
use azalea_chat::translatable_component::TranslatableComponent;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
/// A Minecraft gamemode, like survival or creative.
|
/// A Minecraft gamemode, like survival or creative.
|
||||||
|
@ -51,26 +52,15 @@ impl GameMode {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn short_name(&self) -> &'static str {
|
/// The short translatable display name for the gamemode, like "Survival".
|
||||||
// TODO: these should be translated
|
pub fn short_name(&self) -> TranslatableComponent {
|
||||||
// TranslatableComponent("selectWorld.gameMode." + string2)
|
TranslatableComponent::new(format!("selectWorld.gameMode.{}", self.name()), vec![])
|
||||||
match self {
|
|
||||||
GameMode::Survival => "Survival",
|
|
||||||
GameMode::Creative => "Creative",
|
|
||||||
GameMode::Adventure => "Adventure",
|
|
||||||
GameMode::Spectator => "Spectator",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn long_name(&self) -> &'static str {
|
/// The long translatable display name for the gamemode, like "Survival
|
||||||
// TODO: These should be translated TranslatableComponent("gameMode." +
|
/// Mode".
|
||||||
// string2);
|
pub fn long_name(&self) -> TranslatableComponent {
|
||||||
match self {
|
TranslatableComponent::new(format!("gameMode.{}", self.name()), vec![])
|
||||||
GameMode::Survival => "Survival Mode",
|
|
||||||
GameMode::Creative => "Creative Mode",
|
|
||||||
GameMode::Adventure => "Adventure Mode",
|
|
||||||
GameMode::Spectator => "Spectator Mode",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_name(name: &str) -> GameMode {
|
pub fn from_name(name: &str) -> GameMode {
|
||||||
|
@ -82,6 +72,16 @@ impl GameMode {
|
||||||
_ => panic!("Unknown game type name: {name}"),
|
_ => panic!("Unknown game type name: {name}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The internal name for the game mode, like "survival".
|
||||||
|
pub fn name(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
GameMode::Survival => "survival",
|
||||||
|
GameMode::Creative => "creative",
|
||||||
|
GameMode::Adventure => "adventure",
|
||||||
|
GameMode::Spectator => "spectator",
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GameMode {
|
impl GameMode {
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
use std::{f64::consts::PI, sync::LazyLock};
|
use std::{
|
||||||
|
f64::consts::PI,
|
||||||
|
ops::{Add, Div, Sub},
|
||||||
|
sync::LazyLock,
|
||||||
|
};
|
||||||
|
|
||||||
pub const EPSILON: f64 = 1.0E-7;
|
pub const EPSILON: f64 = 1.0E-7;
|
||||||
|
|
||||||
|
@ -24,17 +28,22 @@ pub fn cos(x: f32) -> f32 {
|
||||||
SIN[x]
|
SIN[x]
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: make this generic
|
pub fn binary_search<
|
||||||
pub fn binary_search(mut min: i32, max: i32, predicate: &dyn Fn(i32) -> bool) -> i32 {
|
T: Ord + PartialOrd + Add<Output = T> + Sub<Output = T> + Div<Output = T> + From<u8> + Copy,
|
||||||
|
>(
|
||||||
|
mut min: T,
|
||||||
|
max: T,
|
||||||
|
predicate: impl Fn(T) -> bool,
|
||||||
|
) -> T {
|
||||||
let mut diff = max - min;
|
let mut diff = max - min;
|
||||||
while diff > 0 {
|
while diff > T::from(0) {
|
||||||
let diff_mid = diff / 2;
|
let diff_mid = diff / T::from(2);
|
||||||
let mid = min + diff_mid;
|
let mid = min + diff_mid;
|
||||||
if predicate(mid) {
|
if predicate(mid) {
|
||||||
diff = diff_mid;
|
diff = diff_mid;
|
||||||
} else {
|
} else {
|
||||||
min = mid + 1;
|
min = mid + T::from(1);
|
||||||
diff -= diff_mid + 1;
|
diff = diff - (diff_mid + T::from(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue