mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added make_sprite command
This commit is contained in:
parent
1e900e8c6a
commit
388a899a7f
@ -59,6 +59,7 @@ pub enum ChatCommand {
|
||||
Lantern,
|
||||
Light,
|
||||
MakeBlock,
|
||||
MakeSprite,
|
||||
Motd,
|
||||
Object,
|
||||
Players,
|
||||
@ -105,6 +106,7 @@ pub static CHAT_COMMANDS: &[ChatCommand] = &[
|
||||
ChatCommand::Lantern,
|
||||
ChatCommand::Light,
|
||||
ChatCommand::MakeBlock,
|
||||
ChatCommand::MakeSprite,
|
||||
ChatCommand::Motd,
|
||||
ChatCommand::Object,
|
||||
ChatCommand::Players,
|
||||
@ -162,6 +164,11 @@ lazy_static! {
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
static ref SPRITE_KINDS: Vec<String> = terrain::sprite::SPRITE_KINDS
|
||||
.keys()
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
/// List of item specifiers. Useful for tab completing
|
||||
static ref ITEM_SPECS: Vec<String> = {
|
||||
let path = assets::ASSETS_PATH.join("common").join("items");
|
||||
@ -306,7 +313,12 @@ impl ChatCommand {
|
||||
),
|
||||
ChatCommand::MakeBlock => cmd(
|
||||
vec![Enum("block", BLOCK_KINDS.clone(), Required)],
|
||||
"Make a block",
|
||||
"Make a block at your location",
|
||||
Admin,
|
||||
),
|
||||
ChatCommand::MakeSprite => cmd(
|
||||
vec![Enum("sprite", SPRITE_KINDS.clone(), Required)],
|
||||
"Make a sprite at your location",
|
||||
Admin,
|
||||
),
|
||||
ChatCommand::Motd => cmd(
|
||||
@ -422,6 +434,7 @@ impl ChatCommand {
|
||||
ChatCommand::Lantern => "lantern",
|
||||
ChatCommand::Light => "light",
|
||||
ChatCommand::MakeBlock => "make_block",
|
||||
ChatCommand::MakeSprite => "make_sprite",
|
||||
ChatCommand::Motd => "motd",
|
||||
ChatCommand::Object => "object",
|
||||
ChatCommand::Players => "players",
|
||||
|
@ -7,7 +7,7 @@ use crate::{
|
||||
sys,
|
||||
terrain::{Block, TerrainChunk, TerrainGrid},
|
||||
time::DayPeriod,
|
||||
vol::WriteVol,
|
||||
vol::{ReadVol, WriteVol},
|
||||
};
|
||||
use hashbrown::{HashMap, HashSet};
|
||||
use rayon::{ThreadPool, ThreadPoolBuilder};
|
||||
@ -264,6 +264,11 @@ impl State {
|
||||
/// Get a writable reference to this state's terrain.
|
||||
pub fn terrain_mut(&self) -> FetchMut<TerrainGrid> { self.ecs.write_resource() }
|
||||
|
||||
/// Get a block in this state's terrain.
|
||||
pub fn get_block(&self, pos: Vec3<i32>) -> Option<Block> {
|
||||
self.terrain().get(pos).ok().copied()
|
||||
}
|
||||
|
||||
/// Set a block in this state's terrain.
|
||||
pub fn set_block(&mut self, pos: Vec3<i32>, block: Block) {
|
||||
self.ecs.write_resource::<BlockChange>().set(pos, block);
|
||||
|
@ -12,9 +12,9 @@ use common::{
|
||||
npc::{self, get_npc_name},
|
||||
state::TimeOfDay,
|
||||
sync::{Uid, WorldSyncExt},
|
||||
terrain::{Block, BlockKind, TerrainChunkSize},
|
||||
terrain::{Block, BlockKind, SpriteKind, TerrainChunkSize},
|
||||
util::Dir,
|
||||
vol::RectVolSize,
|
||||
vol::{RectVolSize, Vox},
|
||||
LoadoutBuilder,
|
||||
};
|
||||
use rand::Rng;
|
||||
@ -87,6 +87,7 @@ fn get_handler(cmd: &ChatCommand) -> CommandHandler {
|
||||
ChatCommand::Lantern => handle_lantern,
|
||||
ChatCommand::Light => handle_light,
|
||||
ChatCommand::MakeBlock => handle_make_block,
|
||||
ChatCommand::MakeSprite => handle_make_sprite,
|
||||
ChatCommand::Motd => handle_motd,
|
||||
ChatCommand::Object => handle_object,
|
||||
ChatCommand::Players => handle_players,
|
||||
@ -217,6 +218,44 @@ fn handle_make_block(
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_make_sprite(
|
||||
server: &mut Server,
|
||||
client: EcsEntity,
|
||||
target: EcsEntity,
|
||||
args: String,
|
||||
action: &ChatCommand,
|
||||
) {
|
||||
if let Some(sprite_name) = scan_fmt_some!(&args, &action.arg_fmt(), String) {
|
||||
if let Ok(sk) = SpriteKind::try_from(sprite_name.as_str()) {
|
||||
match server.state.read_component_copied::<comp::Pos>(target) {
|
||||
Some(pos) => {
|
||||
let pos = pos.0.map(|e| e.floor() as i32);
|
||||
let new_block = server
|
||||
.state
|
||||
.get_block(pos)
|
||||
.unwrap_or_else(Block::empty)
|
||||
.with_sprite(sk);
|
||||
server.state.set_block(pos, new_block);
|
||||
},
|
||||
None => server.notify_client(
|
||||
client,
|
||||
ChatType::CommandError.server_msg(String::from("You have no position.")),
|
||||
),
|
||||
}
|
||||
} else {
|
||||
server.notify_client(
|
||||
client,
|
||||
ChatType::CommandError.server_msg(format!("Invalid sprite kind: {}", sprite_name)),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
server.notify_client(
|
||||
client,
|
||||
ChatType::CommandError.server_msg(action.help_string()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_motd(
|
||||
server: &mut Server,
|
||||
client: EcsEntity,
|
||||
|
@ -44,7 +44,6 @@ impl Animation for AlphaAnimation {
|
||||
/ 10.0;
|
||||
|
||||
let switch = if random > 0.5 { 1.0 } else { -1.0 };
|
||||
println!("{:?}", random);
|
||||
if switch > 0.0 {
|
||||
next.head.position = Vec3::new(0.0, skeleton_attr.head.0, skeleton_attr.head.1) * 1.02;
|
||||
next.head.orientation = Quaternion::rotation_z(0.0) * Quaternion::rotation_x(-0.2);
|
||||
|
Loading…
Reference in New Issue
Block a user