Tweak biomes

This commit is contained in:
Ryan 2022-07-02 13:41:45 -07:00
parent c468fc3eea
commit 0c6ecc9c12
3 changed files with 35 additions and 19 deletions

View file

@ -10,8 +10,8 @@ use valence::client::{Event, GameMode};
use valence::config::{Config, ServerListPing}; use valence::config::{Config, ServerListPing};
use valence::text::Color; use valence::text::Color;
use valence::{ use valence::{
async_trait, BlockState, Client, DimensionId, Server, ShutdownResult, Text, TextFormat, async_trait, ident, Biome, BlockState, Client, Dimension, DimensionId, Server, ShutdownResult,
WorldId, Worlds, Text, TextFormat, WorldId, Worlds,
}; };
pub fn main() -> ShutdownResult { pub fn main() -> ShutdownResult {
@ -57,6 +57,21 @@ impl Config for Game {
false 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 { async fn server_list_ping(&self, _server: &Server, _remote_addr: SocketAddr) -> ServerListPing {
ServerListPing::Respond { ServerListPing::Respond {
online_players: self.player_count.load(Ordering::SeqCst) as i32, online_players: self.player_count.load(Ordering::SeqCst) as i32,
@ -148,7 +163,7 @@ impl Config for Game {
} }
Event::Movement { position, .. } => { Event::Movement { position, .. } => {
if position.y <= 0.0 { if position.y <= 0.0 {
client.teleport(spawn_pos, 0.0, 0.0); client.teleport(spawn_pos, client.pitch(), client.yaw());
} }
} }
_ => {} _ => {}

View file

@ -24,6 +24,7 @@ pub struct Biome {
pub fog_color: u32, pub fog_color: u32,
pub water_color: u32, pub water_color: u32,
pub foliage_color: Option<u32>, pub foliage_color: Option<u32>,
pub grass_color: Option<u32>,
pub grass_color_modifier: BiomeGrassColorModifier, pub grass_color_modifier: BiomeGrassColorModifier,
pub music: Option<BiomeMusic>, pub music: Option<BiomeMusic>,
pub ambient_sound: Option<Ident>, pub ambient_sound: Option<Ident>,
@ -38,7 +39,6 @@ pub struct Biome {
// * downfall: f32 // * downfall: f32
// * category // * category
// * temperature_modifier // * temperature_modifier
// * grass_color (misleading name?)
} }
impl Default for Biome { impl Default for Biome {
@ -51,6 +51,7 @@ impl Default for Biome {
fog_color: 12638463, fog_color: 12638463,
water_color: 4159204, water_color: 4159204,
foliage_color: None, foliage_color: None,
grass_color: None,
grass_color_modifier: BiomeGrassColorModifier::None, grass_color_modifier: BiomeGrassColorModifier::None,
music: None, music: None,
ambient_sound: None, ambient_sound: None,
@ -71,19 +72,14 @@ pub enum BiomePrecipitation {
/// Minecraft handles grass colors for swamps and dark oak forests in a special /// Minecraft handles grass colors for swamps and dark oak forests in a special
/// way. /// way.
#[derive(Clone, Copy, PartialEq, Eq, Debug)] #[derive(Clone, Copy, PartialEq, Eq, Default, Debug)]
pub enum BiomeGrassColorModifier { pub enum BiomeGrassColorModifier {
Swamp, Swamp,
DarkForest, DarkForest,
#[default]
None, None,
} }
impl Default for BiomeGrassColorModifier {
fn default() -> Self {
Self::None
}
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct BiomeMusic { pub struct BiomeMusic {
pub replace_current_music: bool, pub replace_current_music: bool,

View file

@ -220,7 +220,8 @@ impl Client {
self.pending_teleports = match self.pending_teleports.checked_add(1) { self.pending_teleports = match self.pending_teleports.checked_add(1) {
Some(n) => n, Some(n) => n,
None => { None => {
self.disconnect("Too many pending teleports"); log::warn!("too many pending teleports for {}", self.username());
self.disconnect_no_reason();
return; return;
} }
}; };
@ -384,7 +385,8 @@ impl Client {
match pkt { match pkt {
C2sPlayPacket::AcceptTeleportation(p) => { C2sPlayPacket::AcceptTeleportation(p) => {
if self.pending_teleports == 0 { if self.pending_teleports == 0 {
self.disconnect("Unexpected teleport confirmation"); log::warn!("unexpected teleport confirmation from {}", self.username());
self.disconnect_no_reason();
return; return;
} }
@ -396,9 +398,12 @@ impl Client {
if got == expected { if got == expected {
self.pending_teleports -= 1; self.pending_teleports -= 1;
} else { } else {
self.disconnect(format!( log::warn!(
"Unexpected teleport ID (expected {expected}, got {got})" "unexpected teleport ID from {} (expected {expected}, got {got})",
)); self.username()
);
self.disconnect_no_reason();
return;
} }
} }
C2sPlayPacket::BlockEntityTagQuery(_) => {} C2sPlayPacket::BlockEntityTagQuery(_) => {}
@ -916,9 +921,9 @@ fn make_dimension_codec(server: &Server) -> RegistryCodec {
if !biomes.iter().any(|b| b.name == ident!("plains")) { if !biomes.iter().any(|b| b.name == ident!("plains")) {
let biome = Biome::default(); let biome = Biome::default();
assert_eq!(biome.name, ident!("plains")); 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 { RegistryCodec {
dimension_type_registry: DimensionTypeRegistry { dimension_type_registry: DimensionTypeRegistry {
typ: ident!("dimension_type"), 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, fog_color: biome.fog_color as i32,
water_color: biome.water_color as i32, water_color: biome.water_color as i32,
foliage_color: biome.foliage_color.map(|x| x 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 { grass_color_modifier: match biome.grass_color_modifier {
BiomeGrassColorModifier::Swamp => Some("swamp".into()), BiomeGrassColorModifier::Swamp => Some("swamp".into()),
BiomeGrassColorModifier::DarkForest => Some("dark_forest".into()), BiomeGrassColorModifier::DarkForest => Some("dark_forest".into()),