mirror of
https://github.com/italicsjenga/valence.git
synced 2025-01-11 07:11:30 +11:00
Tweak biomes
This commit is contained in:
parent
c468fc3eea
commit
0c6ecc9c12
|
@ -10,8 +10,8 @@ use valence::client::{Event, GameMode};
|
|||
use valence::config::{Config, ServerListPing};
|
||||
use valence::text::Color;
|
||||
use valence::{
|
||||
async_trait, BlockState, Client, DimensionId, Server, ShutdownResult, Text, TextFormat,
|
||||
WorldId, Worlds,
|
||||
async_trait, ident, Biome, BlockState, Client, Dimension, DimensionId, Server, ShutdownResult,
|
||||
Text, TextFormat, WorldId, Worlds,
|
||||
};
|
||||
|
||||
pub fn main() -> ShutdownResult {
|
||||
|
@ -57,6 +57,21 @@ impl Config for Game {
|
|||
false
|
||||
}
|
||||
|
||||
fn biomes(&self) -> Vec<Biome> {
|
||||
vec![Biome {
|
||||
name: ident!("valence:default_biome"),
|
||||
grass_color: Some(0x00ff00),
|
||||
..Biome::default()
|
||||
}]
|
||||
}
|
||||
|
||||
fn dimensions(&self) -> Vec<Dimension> {
|
||||
vec![Dimension {
|
||||
fixed_time: Some(6000),
|
||||
..Dimension::default()
|
||||
}]
|
||||
}
|
||||
|
||||
async fn server_list_ping(&self, _server: &Server, _remote_addr: SocketAddr) -> ServerListPing {
|
||||
ServerListPing::Respond {
|
||||
online_players: self.player_count.load(Ordering::SeqCst) as i32,
|
||||
|
@ -148,7 +163,7 @@ impl Config for Game {
|
|||
}
|
||||
Event::Movement { position, .. } => {
|
||||
if position.y <= 0.0 {
|
||||
client.teleport(spawn_pos, 0.0, 0.0);
|
||||
client.teleport(spawn_pos, client.pitch(), client.yaw());
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
|
12
src/biome.rs
12
src/biome.rs
|
@ -24,6 +24,7 @@ pub struct Biome {
|
|||
pub fog_color: u32,
|
||||
pub water_color: u32,
|
||||
pub foliage_color: Option<u32>,
|
||||
pub grass_color: Option<u32>,
|
||||
pub grass_color_modifier: BiomeGrassColorModifier,
|
||||
pub music: Option<BiomeMusic>,
|
||||
pub ambient_sound: Option<Ident>,
|
||||
|
@ -38,7 +39,6 @@ pub struct Biome {
|
|||
// * downfall: f32
|
||||
// * category
|
||||
// * temperature_modifier
|
||||
// * grass_color (misleading name?)
|
||||
}
|
||||
|
||||
impl Default for Biome {
|
||||
|
@ -51,6 +51,7 @@ impl Default for Biome {
|
|||
fog_color: 12638463,
|
||||
water_color: 4159204,
|
||||
foliage_color: None,
|
||||
grass_color: None,
|
||||
grass_color_modifier: BiomeGrassColorModifier::None,
|
||||
music: None,
|
||||
ambient_sound: None,
|
||||
|
@ -71,19 +72,14 @@ pub enum BiomePrecipitation {
|
|||
|
||||
/// Minecraft handles grass colors for swamps and dark oak forests in a special
|
||||
/// way.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Default, Debug)]
|
||||
pub enum BiomeGrassColorModifier {
|
||||
Swamp,
|
||||
DarkForest,
|
||||
#[default]
|
||||
None,
|
||||
}
|
||||
|
||||
impl Default for BiomeGrassColorModifier {
|
||||
fn default() -> Self {
|
||||
Self::None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct BiomeMusic {
|
||||
pub replace_current_music: bool,
|
||||
|
|
|
@ -220,7 +220,8 @@ impl Client {
|
|||
self.pending_teleports = match self.pending_teleports.checked_add(1) {
|
||||
Some(n) => n,
|
||||
None => {
|
||||
self.disconnect("Too many pending teleports");
|
||||
log::warn!("too many pending teleports for {}", self.username());
|
||||
self.disconnect_no_reason();
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
@ -384,7 +385,8 @@ impl Client {
|
|||
match pkt {
|
||||
C2sPlayPacket::AcceptTeleportation(p) => {
|
||||
if self.pending_teleports == 0 {
|
||||
self.disconnect("Unexpected teleport confirmation");
|
||||
log::warn!("unexpected teleport confirmation from {}", self.username());
|
||||
self.disconnect_no_reason();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -396,9 +398,12 @@ impl Client {
|
|||
if got == expected {
|
||||
self.pending_teleports -= 1;
|
||||
} else {
|
||||
self.disconnect(format!(
|
||||
"Unexpected teleport ID (expected {expected}, got {got})"
|
||||
));
|
||||
log::warn!(
|
||||
"unexpected teleport ID from {} (expected {expected}, got {got})",
|
||||
self.username()
|
||||
);
|
||||
self.disconnect_no_reason();
|
||||
return;
|
||||
}
|
||||
}
|
||||
C2sPlayPacket::BlockEntityTagQuery(_) => {}
|
||||
|
@ -916,9 +921,9 @@ fn make_dimension_codec(server: &Server) -> RegistryCodec {
|
|||
if !biomes.iter().any(|b| b.name == ident!("plains")) {
|
||||
let biome = Biome::default();
|
||||
assert_eq!(biome.name, ident!("plains"));
|
||||
biomes.push(to_biome_registry_item(&biome, 0));
|
||||
biomes.push(to_biome_registry_item(&biome, biomes.len() as i32));
|
||||
}
|
||||
|
||||
|
||||
RegistryCodec {
|
||||
dimension_type_registry: DimensionTypeRegistry {
|
||||
typ: ident!("dimension_type"),
|
||||
|
@ -994,7 +999,7 @@ fn to_biome_registry_item(biome: &Biome, id: i32) -> BiomeRegistryBiome {
|
|||
fog_color: biome.fog_color as i32,
|
||||
water_color: biome.water_color as i32,
|
||||
foliage_color: biome.foliage_color.map(|x| x as i32),
|
||||
grass_color: None,
|
||||
grass_color: biome.grass_color.map(|x| x as i32),
|
||||
grass_color_modifier: match biome.grass_color_modifier {
|
||||
BiomeGrassColorModifier::Swamp => Some("swamp".into()),
|
||||
BiomeGrassColorModifier::DarkForest => Some("dark_forest".into()),
|
||||
|
|
Loading…
Reference in a new issue