-
-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
59 changed files
with
796 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
[ | ||
"speed", | ||
"slowness", | ||
"haste", | ||
"mining_fatigue", | ||
"strength", | ||
"instant_health", | ||
"instant_damage", | ||
"jump_boost", | ||
"nausea", | ||
"regeneration", | ||
"resistance", | ||
"fire_resistance", | ||
"water_breathing", | ||
"invisibility", | ||
"blindness", | ||
"night_vision", | ||
"hunger", | ||
"weakness", | ||
"poison", | ||
"wither", | ||
"health_boost", | ||
"absorption", | ||
"saturation", | ||
"glowing", | ||
"levitation", | ||
"luck", | ||
"unluck", | ||
"slow_falling", | ||
"conduit_power", | ||
"dolphins_grace", | ||
"bad_omen", | ||
"hero_of_the_village", | ||
"darkness", | ||
"trial_omen", | ||
"raid_omen", | ||
"wind_charged", | ||
"weaving", | ||
"oozing", | ||
"infested" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use heck::ToPascalCase; | ||
use proc_macro2::TokenStream; | ||
use quote::{format_ident, quote}; | ||
|
||
pub(crate) fn build() -> TokenStream { | ||
println!("cargo:rerun-if-changed=../assets/status_effects.json"); | ||
|
||
let chunk_status: Vec<String> = | ||
serde_json::from_str(include_str!("../../assets/status_effects.json")) | ||
.expect("Failed to parse status_effects.json"); | ||
let mut variants = TokenStream::new(); | ||
let mut type_from_name = TokenStream::new(); | ||
let mut type_to_name = TokenStream::new(); | ||
|
||
for status in chunk_status.iter() { | ||
let const_ident = format_ident!("{}", status.to_pascal_case()); | ||
let resource_name = status.to_lowercase(); | ||
|
||
variants.extend([quote! { | ||
#const_ident, | ||
}]); | ||
type_from_name.extend(quote! { | ||
#resource_name => Some(Self::#const_ident), | ||
}); | ||
type_to_name.extend(quote! { | ||
Self::#const_ident => #resource_name, | ||
}); | ||
} | ||
quote! { | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | ||
pub enum EffectType { | ||
#variants | ||
} | ||
|
||
impl EffectType { | ||
#[doc = r" Try to parse a Effect Type from a resource location string"] | ||
pub fn from_name(name: &str) -> Option<Self> { | ||
match name { | ||
#type_from_name | ||
_ => None | ||
} | ||
} | ||
|
||
pub const fn to_name(&self) -> &'static str { | ||
match self { | ||
#type_to_name | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use pumpkin_data::packet::clientbound::PLAY_UPDATE_MOB_EFFECT; | ||
use pumpkin_macros::client_packet; | ||
use serde::Serialize; | ||
|
||
use crate::codec::var_int::VarInt; | ||
|
||
#[derive(Serialize)] | ||
#[client_packet(PLAY_UPDATE_MOB_EFFECT)] | ||
pub struct CUpdateMobEffect { | ||
entity_id: VarInt, | ||
effect_id: VarInt, | ||
amplifier: VarInt, | ||
duration: VarInt, | ||
flags: i8, | ||
} | ||
|
||
impl CUpdateMobEffect { | ||
pub fn new( | ||
entity_id: VarInt, | ||
effect_id: VarInt, | ||
amplifier: VarInt, | ||
duration: VarInt, | ||
flags: i8, | ||
) -> Self { | ||
Self { | ||
entity_id, | ||
effect_id, | ||
amplifier, | ||
duration, | ||
flags, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use async_trait::async_trait; | ||
use pumpkin_data::entity::EffectType; | ||
use pumpkin_protocol::client::play::{ArgumentType, CommandSuggestion, SuggestionProviders}; | ||
|
||
use crate::command::{ | ||
CommandSender, | ||
args::{ | ||
Arg, ArgumentConsumer, ConsumedArgs, DefaultNameArgConsumer, FindArg, | ||
GetClientSideArgParser, | ||
}, | ||
dispatcher::CommandError, | ||
tree::RawArgs, | ||
}; | ||
use crate::server::Server; | ||
|
||
pub struct EffectTypeArgumentConsumer; | ||
|
||
impl GetClientSideArgParser for EffectTypeArgumentConsumer { | ||
fn get_client_side_parser(&self) -> ArgumentType { | ||
ArgumentType::Resource { | ||
identifier: "mob_effect", | ||
} | ||
} | ||
|
||
fn get_client_side_suggestion_type_override(&self) -> Option<SuggestionProviders> { | ||
None | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl ArgumentConsumer for EffectTypeArgumentConsumer { | ||
async fn consume<'a>( | ||
&'a self, | ||
_sender: &CommandSender<'a>, | ||
_server: &'a Server, | ||
args: &mut RawArgs<'a>, | ||
) -> Option<Arg<'a>> { | ||
let name = args.pop()?; | ||
|
||
// Create a static damage type first | ||
let damage_type = EffectType::from_name(&name.replace("minecraft:", ""))?; | ||
// Find matching static damage type from values array | ||
Some(Arg::Effect(damage_type)) | ||
} | ||
|
||
async fn suggest<'a>( | ||
&'a self, | ||
_sender: &CommandSender<'a>, | ||
_server: &'a Server, | ||
_input: &'a str, | ||
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> { | ||
Ok(None) | ||
} | ||
} | ||
|
||
impl DefaultNameArgConsumer for EffectTypeArgumentConsumer { | ||
fn default_name(&self) -> &'static str { | ||
"mob_effect" | ||
} | ||
} | ||
|
||
impl<'a> FindArg<'a> for EffectTypeArgumentConsumer { | ||
type Data = &'a EffectType; | ||
|
||
fn find_arg(args: &'a ConsumedArgs, name: &str) -> Result<Self::Data, CommandError> { | ||
match args.get(name) { | ||
Some(Arg::Effect(data)) => Ok(data), | ||
_ => Err(CommandError::InvalidConsumption(Some(name.to_string()))), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pub mod damage_type; | ||
pub mod effect; | ||
pub mod item; | ||
pub mod particle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.