From 5e29847e12ec2588e263348a9775017abe58cb64 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 20 Jun 2021 23:38:53 +0100 Subject: [PATCH] Added /make_rgb and /make_palette --- .gitignore | 1 + common/src/cmd.rs | 14 +++++++++++++ server/src/cmd.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/.gitignore b/.gitignore index 1d3eeae7fc..45af8efdd1 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ maps screenshots todo.txt userdata +chunks # Export data *.csv diff --git a/common/src/cmd.rs b/common/src/cmd.rs index 41d45416f9..a222aaa768 100644 --- a/common/src/cmd.rs +++ b/common/src/cmd.rs @@ -78,6 +78,8 @@ pub enum ChatCommand { Light, MakeBlock, MakeSprite, + MakeRgb, + MakePalette, Motd, Object, PermitBuild, @@ -471,6 +473,16 @@ impl ChatCommand { "Make a sprite at your location", None, ), + ChatCommand::MakeRgb => cmd( + vec![Enum("block", BLOCK_KINDS.clone(), Required), Integer("r", 255, Required), Integer("g", 255, Required), Integer("b", 255, Required)], + "Make a coloured block at your location", + None, + ), + ChatCommand::MakePalette => cmd( + vec![], + "Make a colourful palette at your location", + None, + ), ChatCommand::Motd => cmd(vec![Message(Optional)], "View the server description", None), ChatCommand::Object => cmd( vec![Enum("object", OBJECTS.clone(), Required)], @@ -640,6 +652,8 @@ impl ChatCommand { ChatCommand::Light => "light", ChatCommand::MakeBlock => "make_block", ChatCommand::MakeSprite => "make_sprite", + ChatCommand::MakeRgb => "make_rgb", + ChatCommand::MakePalette => "make_palette", ChatCommand::Motd => "motd", ChatCommand::Object => "object", ChatCommand::PermitBuild => "permit_build", diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 586daf29d6..6d088f68f6 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -145,6 +145,8 @@ fn do_command( ChatCommand::Light => handle_light, ChatCommand::MakeBlock => handle_make_block, ChatCommand::MakeSprite => handle_make_sprite, + ChatCommand::MakeRgb => handle_make_rgb, + ChatCommand::MakePalette => handle_make_palette, ChatCommand::Motd => handle_motd, ChatCommand::Object => handle_object, ChatCommand::PermitBuild => handle_permit_build, @@ -563,6 +565,57 @@ fn handle_make_sprite( } } +fn handle_make_rgb( + server: &mut Server, + _client: EcsEntity, + target: EcsEntity, + args: String, + action: &ChatCommand, +) -> CmdResult<()> { + if let (Some(block_name), Some(r), Some(g), Some(b)) = scan_fmt_some!(&args, &action.arg_fmt(), String, u8, u8, u8) { + if let Ok(bk) = BlockKind::try_from(block_name.as_str()) { + let pos = position(server, target, "target")?; + let pos = pos.0.map(|e| e.floor() as i32); + let new_block = Block::new(bk, Rgb::new(r, g, b)); + server.state.set_block(pos, new_block); + server.state.ecs().write_resource::().set_block(pos, new_block); + Ok(()) + } else { + Err(format!("Invalid block kind: {}", block_name)) + } + } else { + Err(action.help_string()) + } +} + +fn handle_make_palette( + server: &mut Server, + _client: EcsEntity, + target: EcsEntity, + args: String, + action: &ChatCommand, +) -> CmdResult<()> { + let pos = position(server, target, "target")?; + let pos = pos.0.map(|e| e.floor() as i32); + for x in -8..9 { + for y in -8..9 { + if x == 0 || y == 0 { continue; } + + for z in 0..16 { + let r = (8 + x + if x > 0 { -1 } else { 0 }) * 16 + 8; + let g = (8 + y + if y > 0 { -1 } else { 0 }) * 16 + 8; + let b = z * 16; + + let pos = pos + Vec3::new(x, y, z * 3); + let new_block = Block::new(BlockKind::Misc, Rgb::new(r as u8, g as u8, b as u8)); + server.state.set_block(pos, new_block); + server.state.ecs().write_resource::().set_block(pos, new_block); + } + } + } + Ok(()) +} + fn handle_motd( server: &mut Server, client: EcsEntity,