-
Notifications
You must be signed in to change notification settings - Fork 146
[WIP] Implement Potion Effects #430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c83ebbb
Implementing Potion Effects
walker27460 d598cb1
cargo fmt
walker27460 4b531c2
Merge branch 'main' into main
walker27460 d1ad164
cargo fmt
walker27460 065fee6
Change Vec to HashSet
walker27460 74aa42b
Implementing Potion Effect (Plugin Host Call)
walker27460 c19dc69
Register each effects as component
walker27460 777e662
Added doc comment for the struct PotionApplication
walker27460 97c82b5
removed dumb things
walker27460 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,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"] } |
This file contains hidden or 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,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), | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -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)] | ||
|
|
@@ -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); | ||
| }; | ||
| } | ||
|
|
||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of these should have the |
||
|
|
||
| /// Wheather an entity is sneaking, like in pressing shift. | ||
| #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
| pub struct Sneaking(pub bool); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.