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
8 changes: 8 additions & 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"libcraft/macros",
"libcraft/particles",
"libcraft/text",
"libcraft/effects",

# Quill
"quill/sys-macros",
Expand Down
1 change: 1 addition & 0 deletions feather/plugin-host/src/host_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod plugin_message;
mod query;
mod system;


macro_rules! host_calls {
(
$($name:literal => $function:ident),* $(,)?
Expand Down
10 changes: 10 additions & 0 deletions libcraft/effects/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "libcraft-effects"
version = "0.1.0"
authors = ["Yui Tanabe <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1", features = ["derive"] }
84 changes: 84 additions & 0 deletions libcraft/effects/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;

#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
pub enum PotionEffect {
None = 0,
Speed = 1,
Slowness = 2,
Haste = 3,
MiningFatigue = 4,
Strength = 5,
InstantHealth = 6,
InstantDamage = 7,
JumpBoost = 8,
Nausea = 9,
Regeneration = 10,
Resistance = 11,
FireResistance = 12,
WaterBreathing = 13,
Invisibility = 14,
Blindness = 15,
NightVision = 16,
Hunger = 17,
Weakness = 18,
Poison = 19,
Wither = 20,
HealthBoost = 21,
Absorption = 22,
Saturation = 23,
Glowing = 24,
Levitation = 25,
Luck = 26,
BadLuck = 27,
SlowFalling = 28,
ConduitPower = 29,
DolphinsGrace = 30,
BadOmen = 31,
HeroOfTheVillage = 32,
}

#[derive(Debug, Copy, Clone)]
pub struct PotionEffectConvertError;

impl TryFrom<&str> for PotionEffect {
type Error = PotionEffectConvertError;

fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"speed" => Ok(Self::Speed),
"slowness" => Ok(Self::Slowness),
"haste" => Ok(Self::Haste),
"mining_fatigue" => Ok(Self::MiningFatigue),
"strength" => Ok(Self::Strength),
"instant_health" => Ok(Self::InstantHealth),
"instant_damage" => Ok(Self::InstantDamage),
"jump_boost" => Ok(Self::JumpBoost),
"nausea" => Ok(Self::Nausea),
"regeneration" => Ok(Self::Regeneration),
"resistance" => Ok(Self::Resistance),
"fire_resistance" => Ok(Self::FireResistance),
"water_breathing" => Ok(Self::WaterBreathing),
"invisibility" => Ok(Self::Invisibility),
"blindness" => Ok(Self::Blindness),
"night_vision" => Ok(Self::NightVision),
"hunger" => Ok(Self::Hunger),
"weakness" => Ok(Self::Weakness),
"poison" => Ok(Self::Poison),
"wither" => Ok(Self::Wither),
"health_boost" => Ok(Self::HealthBoost),
"absorption" => Ok(Self::Absorption),
"saturation" => Ok(Self::Saturation),
"glowing" => Ok(Self::Glowing),
"levitation" => Ok(Self::Levitation),
"luck" => Ok(Self::Luck),
"unluck" => Ok(Self::BadLuck),
"slow_falling" => Ok(Self::SlowFalling),
"conduit_power" => Ok(Self::ConduitPower),
"dolphins_grace" => Ok(Self::DolphinsGrace),
"bad_omen" => Ok(Self::BadOmen),
"hero_of_the_village" => Ok(Self::HeroOfTheVillage),
_ => Err(PotionEffectConvertError),
}
}
}
1 change: 1 addition & 0 deletions quill/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ bytemuck = { version = "1", features = ["derive"] }
libcraft-core = { path = "../../libcraft/core" }
libcraft-particles = { path = "../../libcraft/particles" }
libcraft-text = { path = "../../libcraft/text" }
libcraft-effects = { path = "../../libcraft/effects" }
serde = { version = "1", features = ["derive"] }
smartstring = { version = "0.2", features = ["serde"] }
uuid = { version = "0.8", features = ["serde"] }
Expand Down
35 changes: 34 additions & 1 deletion quill/common/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,40 @@ host_component_enum! {
// `Pod` components
Position = 0,

// Effect Components
Speed = 1,
Slowness = 2,
Haste = 3,
MiningFatigue = 4,
Strength = 5,
InstantHealth = 6,
InstantDamage = 7,
JumpBoost = 8,
Nausea = 9,
Regeneration = 10,
Resistance = 11,
FireResistance = 12,
WaterBreathing = 13,
Invisibility = 14,
Blindness = 15,
NightVision = 16,
Hunger = 17,
Weakness = 18,
Poison = 19,
WitherEffect = 20,
HealthBoost = 21,
Absorption = 22,
Saturation = 23,
Glowing = 24,
Levitation = 25,
Luck = 26,
BadLuck = 27,
SlowFalling = 28,
ConduitPower = 29,
DolphinsGrace = 30,
BadOmen = 31,
HeroOfTheVillage = 32,

// Entity marker components
AreaEffectCloud = 100,
ArmorStand = 101,
Expand Down Expand Up @@ -189,7 +223,6 @@ host_component_enum! {
Sneaking = 1011,
SneakEvent = 1012,


}
}

Expand Down
77 changes: 77 additions & 0 deletions quill/common/src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use std::{

use serde::{Deserialize, Serialize};
use smartstring::{LazyCompact, SmartString};
use std::cmp::Ordering;
use std::collections::BTreeSet;

/// Whether an entity is touching the ground.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
Expand Down Expand Up @@ -105,6 +107,81 @@ pub struct CreativeFlying(pub bool);

bincode_component_impl!(CreativeFlying);

#[derive(Copy, Clone, Debug, Hash, Serialize, PartialEq, Eq, Deserialize)]

/// Storing Potion effects info.
pub struct PotionApplication {
/// Strength Level of effect.
pub amplifier: u8,
/// Tick-based duration of the effect.
pub duration: u32,
/// Whether spawn particles or not.
pub particle: bool,
/// Whether the effect was given by a beacon or not.
pub ambient: bool,
/// Show effect icon or not.
pub icon: bool,
}

impl Ord for PotionApplication {
fn cmp(&self, other: &Self) -> Ordering {
if self.amplifier > other.amplifier || self.duration > other.duration {
Ordering::Greater
} else if self.amplifier == self.amplifier || self.duration == other.duration {
Ordering::Equal
} else {
Ordering::Less
}
}
}
impl PartialOrd for PotionApplication {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

macro_rules! impl_effect {
($ident:ident) => {
#[derive(Serialize, Deserialize, Eq, PartialEq, Hash)]
pub struct $ident(BTreeSet<PotionApplication>);
impl $ident {}
bincode_component_impl!($ident);
};
}
Comment on lines +143 to +150
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we might have somewhere we try to consolidate macros? Not sure.


impl_effect!(Speed);
impl_effect!(Slowness);
impl_effect!(Haste);
impl_effect!(MiningFatigue);
impl_effect!(Strength);
impl_effect!(InstantHealth);
impl_effect!(InstantDamage);
impl_effect!(JumpBoost);
impl_effect!(Nausea);
impl_effect!(Regeneration);
impl_effect!(Resistance);
impl_effect!(FireResistance);
impl_effect!(WaterBreathing);
impl_effect!(Invisibility);
impl_effect!(Blindness);
impl_effect!(NightVision);
impl_effect!(Hunger);
impl_effect!(Weakness);
impl_effect!(Poison);
impl_effect!(WitherEffect);
impl_effect!(HealthBoost);
impl_effect!(Absorption);
impl_effect!(Saturation);
impl_effect!(Glowing);
impl_effect!(Levitation);
impl_effect!(Luck);
impl_effect!(BadLuck);
impl_effect!(SlowFalling);
impl_effect!(ConduitPower);
impl_effect!(DolphinsGrace);
impl_effect!(BadOmen);
impl_effect!(HeroOfTheVillage);
Comment on lines +152 to +183
Copy link
Contributor

Choose a reason for hiding this comment

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

All of these should have the Effect suffix.


/// Wheather an entity is sneaking, like in pressing shift.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Sneaking(pub bool);
Expand Down