Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/commands/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ feather-core = { path = "../../core" }
feather-server-types = { path = "../types" }
feather-server-util = { path = "../util" }
feather-definitions = { path = "../../definitions" }
feather-server-entity = {path = "../entity"}

fecs = { git = "https://github.com/feather-rs/fecs", rev = "0c4838d65b41ca059012b6e9147eabf0c275a731" }
lieutenant = { git = "https://github.com/feather-rs/lieutenant", branch = "master" }
Expand Down
24 changes: 24 additions & 0 deletions server/commands/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::CommandCtx;
use feather_core::position;
use feather_core::util::{Gamemode, Position};
use feather_definitions::Item;
use feather_server_entity::*;
use feather_server_types::{Game, Name, NetworkId, Player};
use fecs::{component, Entity, IntoQuery, Read, World};
use lieutenant::{ArgumentKind, Input};
Expand Down Expand Up @@ -426,3 +427,26 @@ impl ArgumentKind<CommandCtx> for PositiveI32Argument {
}
}
}
///Argument used in spawn. It maps from the entity string to the spawn
/// function
#[derive(Clone, Debug)]
pub struct EntityType(pub fn() -> fecs::EntityBuilder);
#[derive(Debug, Error)]
pub enum EntityTypeParseError {
#[error("Unknown Entity: {0}")]
Unknown(String),
}
impl ArgumentKind<CommandCtx> for EntityType {
type ParseError = EntityTypeParseError;
fn satisfies<'a>(_ctx: &CommandCtx, input: &mut Input<'a>) -> bool {
!input.advance_until(" ").is_empty()
}
fn parse<'a>(_ctx: &CommandCtx, input: &mut Input<'a>) -> Result<Self, Self::ParseError> {
let identifier = input.advance_until(" ");
if let Some(entity) = from_string(identifier) {
Ok(EntityType(entity))
} else {
Err(EntityTypeParseError::Unknown(identifier.to_string()))
}
}
}
19 changes: 19 additions & 0 deletions server/commands/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,3 +502,22 @@ fn clear_items(
);
}
}
use crate::arguments::EntityType;
use feather_server_types::EntitySpawnEvent;
#[command(usage = "summon <entity> <pos>")]
pub fn summon(ctx: &mut CommandCtx, entity: EntityType, pos: Coordinates) -> anyhow::Result<()> {
let player_position = *ctx.world.get::<Position>(ctx.sender);
let spawn_position = pos.into_position(player_position);
let spawned_entity = entity.0()
.with(spawn_position)
.build()
.spawn_in(&mut *ctx.world);
ctx.game.handle(
&mut *ctx.world,
EntitySpawnEvent {
entity: spawned_entity,
},
);

Ok(Some("".to_string()))
}
2 changes: 2 additions & 0 deletions server/commands/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ impl CommandState {
clear_2,
clear_3,
clear_4,

summon,
}

Self {
Expand Down
95 changes: 95 additions & 0 deletions server/entity/src/mob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod hostile;
mod neutral;
mod passive;

use crate::object;
pub use boss::*;
pub use defensive::*;
use feather_core::entitymeta::EntityMetadata;
Expand Down Expand Up @@ -132,3 +133,97 @@ pub fn spawn_packet_creator(kind: MobKind) -> SpawnPacketCreator {

SpawnPacketCreator(Box::leak(f))
}
pub fn from_string(identifier: &str) -> Option<fn() -> fecs::EntityBuilder> {
match identifier {
"minecraft:area_effect_cloud" => None,
"minecraft:armor_stand" => None,
"minecraft:arrow" => Some(object::arrow::create),
"minecraft:bat" => Some(passive::bat::create),
"minecraft:blaze" => Some(hostile::blaze::create),
"minecraft:boat" => None,
"minecraft:cave_spider" => Some(neutral::cave_spider::create),
"minecraft:chest_minecart" => None,
"minecraft:chicken" => Some(passive::chicken::create),
"minecraft:cod" => None,
"minecraft:command_block_minecart" => None,
"minecraft:cow" => Some(passive::cow::create),
"minecraft:creeper" => Some(hostile::creeper::create),
"minecraft:dolphin" => Some(neutral::dolphin::create),
"minecraft:donkey" => Some(passive::donkey::create),
"minecraft:dragon_fireball" => None,
"minecraft:drowned" => Some(hostile::drowned::create),
"minecraft:egg" => None,
"minecraft:elder_guardian" => Some(hostile::elder_guardian::create),
"minecraft:end_crystal" => None,
"minecraft:ender_dragon" => None,
"minecraft:ender_pearl" => None,
"minecraft:enderman" => None,
"minecraft:endermite" => Some(hostile::endermite::create),
"minecraft:evoker" => None,
"minecraft:evoker_fangs" => None,
"minecraft:experience_bottle" => None,
"minecraft:experience_orb" => None,
"minecraft:eye_of_ender" => None,
"minecraft:falling_block" => None,
"minecraft:fireball" => None,
"minecraft:firework_rocket" => None,
"minecraft:furnace_minecart" => None,
"minecraft:ghast" => Some(hostile::ghast::create),
"minecraft:giant" => None,
"minecraft:guardian" => Some(hostile::guardian::create),
"minecraft:hopper_minecart" => None,
"minecraft:horse" => Some(passive::horse::create),
"minecraft:husk" => Some(hostile::husk::create),
"minecraft:illusioner" => None,
"minecraft:iron_golem" => None,
"minecraft:item_frame" => None,
"minecraft:leash_knot" => None,
"minecraft:lightning_bolt" => None,
"minecraft:llama" => Some(neutral::llama::create),
"minecraft:llama_spit" => None,
"minecraft:mooshroom" => Some(passive::mooshroom::create),
"minecraft:mule" => Some(passive::mule::create),
"minecraft:ocelot" => Some(passive::ocelot::create),
"minecraft:panting" => None,
"minecraft:parrot" => Some(passive::parrot::create),
"minecraft:phantom" => Some(hostile::phantom::create),
"minecraft:pig" => Some(passive::pig::create),
"minecraft:polar_bear" => Some(neutral::polar_bear::create),
"minecraft:potion" => None,
"minecraft:puffer_fish" => Some(defensive::pufferfish::create),
"minecraft:rabbit" => Some(passive::rabbit::create),
"minecraft:salmon" => Some(passive::salmon::create),
"minecraft:sheep" => Some(passive::sheep::create),
"minecraft:shulker" => Some(hostile::shulker::create),
"minecraft:shulker_bullet" => None,
"minecraft:silverfish" => Some(hostile::silverfish::create),
"minecraft:skeleton" => Some(hostile::skeleton::create),
"minecraft:skeleton_horse" => Some(passive::skeleton_horse::create),
"minecraft:slime" => Some(hostile::slime::create),
"minecraft:small_fireball" => None,
"minecraft:snow_golem" => None,
"minecraft:snowball" => None,
"minecraft:spawner_minecart" => None,
"minecraft:spectral_arrow" => None,
"minecraft:spider" => Some(neutral::spider::create),
"minecraft:squid" => Some(passive::squid::create),
"minecraft:stray" => None,
"minecraft:tnt" => None,
"minecraft:tnt_minecart" => None,
"minecraft:trident" => None,
"minecraft:tropical_fish" => Some(passive::tropical_fish::create),
"minecraft:turtle" => Some(passive::turtle::create),
"minecraft:vex" => Some(hostile::vex::create),
"minecraft:villager" => Some(passive::villager::create),
"minecraft:vindicator" => Some(hostile::vindicator::create),
"minecraft:witch" => Some(hostile::witch::create),
"minecraft:wither" => Some(boss::wither::create),
"minecraft:wither_skeleton" => Some(hostile::wither_skeleton::create),
"minecraft:wither_skull" => None,
"minecraft:zombie" => Some(hostile::zombie::create),
"minecraft:zombie_horse" => None,
"minecraft:zombie_pigman" => Some(neutral::zombie_pigman::create),
"minecraft:zombie_villagar" => Some(hostile::zombie_villager::create),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is still a typo, it's villager ^^

_ => None,
}
}