-
Notifications
You must be signed in to change notification settings - Fork 27
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
Module cleanup + Potion "durability" + Documentation #3
Conversation
… update to the Alchemy module.
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.
Great work, and probably one of the best documented pieces of code in the whole project 😆
Have a look at the comments, mabye they are helpful at some point.
Tested out the durability, and it looks to work just right.
* @param instigator The instigator who is applying this effect on the entity. It can be a herb, potion, etc. | ||
* @param entity The entity who the herb effect is being applied on. | ||
* @param magnitude The magnitude of the effect. | ||
* @param duration The duration of the effect. |
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.
What is the unit of duration
? Imho this should be stated in the javadoc, e.g., "The duration of the effect in seconds"
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.
Done. And actually the duration is in milliseconds.
* @param id This particular HerbEffect's ID. Can be used to differentiate different effects under the | ||
* same family. | ||
* @param magnitude The magnitude of the effect. | ||
* @param duration The duration of the effect. |
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.
missing unit spec (2)
@@ -15,7 +15,10 @@ | |||
*/ | |||
package org.terasology.potions; | |||
|
|||
// Class containing a list of constant Strings used for potion-related effect type checks. | |||
/** | |||
* This class contains a list of constant Strings used for potion-related effect type checks. Most are self-explanatory |
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 would call the "constant Strings" just constants. Are these the effect IDs?
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.
Yep, they are basically effect IDs.
@@ -17,10 +17,15 @@ | |||
|
|||
import org.terasology.reflection.MappedContainer; | |||
|
|||
// This class or container contains details on a particular effect of a potion. | |||
/** This class or mapped container contains details on a particular effect of a potion. */ |
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.
Afaik, the mapped container allows to serialize the effect list. I'd just go for "Common class for describing a potion effect" or something like that.
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.
Okay, going with:
Common class for describing an effect that may be present in a potion.
/** | ||
* This HerbEffect wraps any AlterationEffect so that the latter can function within the herbalism systems and be treated | ||
* as a HerbEffect. | ||
*/ | ||
public class AlterationEffectWrapperHerbEffect implements HerbEffect { |
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.
Neatpicking on naming 😛 what about AlterationToHerbEffectWrapper
?
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.
Done! That was an old class from older maintainer (from WoodAndStone in fact).
* Informs whether or not this event has been consumed. | ||
* | ||
* @return True if the the event has been consumed, false otherwise. | ||
*/ | ||
@Override | ||
public boolean isConsumed() { |
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.
you may checkout {@inheritDoc}
and use cases. this case seems like the javadoc should be same in the parent class (the consumable event). If you don't write javadoc at all, it is automatically copied from the override method.
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.
It is done.
@@ -20,34 +20,76 @@ | |||
import org.terasology.entitySystem.event.Event; | |||
import org.terasology.potions.component.PotionComponent; | |||
|
|||
/** | |||
* This event is sent to an entity to indicate that it'll be drinking a given potion. |
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.
is this event treating the potion as one or is it sent for each effect, as the BeforeDrink
event?
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.
Treated the Potion as one.
DrinkPotionEvent sends the entire potion.
BeforeDrinkPotionEvent (now titled BeforeApplyPotionEffectEvent) works on one potion effect at a time.
* | ||
* @param instigator The entity who is trying to consume this potion. | ||
* @param item A reference to the potion item entity which has the potion effect. | ||
* @param p The PotionComponent of the potion item. |
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.
although well documented, please remove the abbreviated variable names and change them to something more clear
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.
Done. I un-abbreviated the names.
EntityRef potion = event.getItem(); | ||
DurabilityComponent durability = potion.getComponent(DurabilityComponent.class); | ||
|
||
// If the Durability component exists. |
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.
some people might argue about the usefulness of such comments... I don't mind them, but in this case it is very clear from the code what is happening
|
||
// If the Durability component exists. | ||
if (durability != null) { | ||
// If the new durability value will be above 0 following the potion drink, or the bottle has inf durability, proceed. |
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.
this one is fine, though ;-)
Overall, I thank you for the suggestions @skaldarnar . I applied to them to the module, and I'll be pushing them tomorrow. |
Changes look good! What keeps you from merging this? Anything outstanding to be tested? |
Nothing. I was just waiting for your confirmation before merging @skaldarnar. Now that I have it, I'll merge this in now. |
Contains
How to Test
Spawn potions using the console, and drink them. If no potion bottle is returned, then it's a success.
To test the other scenario, modify one of the potion prefabs to include the following code:
Then, spawn that potion and drink it. It should return an empty GlassBottle.
Issues
None so far.
Credits
@AWebb3701 and @Cervator for advice.