-
Notifications
You must be signed in to change notification settings - Fork 12
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
Some food data work for players #5
Conversation
@@ -45,6 +52,7 @@ | |||
public class LanternLiving extends LanternEntity implements Living { | |||
|
|||
private Vector3d headRotation = Vector3d.ZERO; | |||
private long lastFoodTick = System.currentTimeMillis(); |
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.
lastFoodTime
is a better name
@@ -600,6 +597,9 @@ public void pulse() { | |||
offer(LanternKeys.ELYTRA_SPEED_BOOST, get(Keys.IS_SPRINTING).get()); | |||
} | |||
} | |||
|
|||
getConnection().send(new MessagePlayOutPlayerHealthUpdate(health().get().floatValue(), |
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 should be moved to the PlayerEntityProtocol
.
return; | ||
} | ||
final Difficulty difficulty = getWorld().getDifficulty(); | ||
|
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.
Try to reuse the Value
s more instead of looking them up multiple times and messing them up with normal get
functions.
For example:
offer(Keys.FOOD_LEVEL, Math.max(get(Keys.FOOD_LEVEL).get() - 1, getValue(Keys.FOOD_LEVEL).get().getMinValue()));
to:
final MutableBoundedValue<Integer> foodLevel = getValue(Keys.FOOD_LEVEL).get();
offer(Keys.FOOD_LEVEL, Math.max(foodLevel.get() - 1, foodLevel.getMinValue()));
I'll try to finish this in a few days. Next weekend will bring more time for me. |
046eebe
to
a3e59a4
Compare
@@ -45,7 +45,7 @@ | |||
|
|||
public final class LanternServerLaunch { | |||
|
|||
public void main(String[] args) { | |||
public static void main(String[] args) { |
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 can make this non-static again, the method is called from LanternLaunch
. This isn't really the main
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.
Ah, my run configuration was just set-up wrong then. Will do!
@@ -306,7 +306,8 @@ public void registerKeys() { | |||
registerKey(LanternKeys.MAX_FOOD_LEVEL, 20, 0, Integer.MAX_VALUE); | |||
registerKey(Keys.FOOD_LEVEL, 20, 0, LanternKeys.MAX_FOOD_LEVEL); | |||
registerKey(LanternKeys.MAX_SATURATION, 40.0, 0.0, Double.MAX_VALUE); | |||
registerKey(Keys.SATURATION, 40.0, 0.0, LanternKeys.MAX_SATURATION); | |||
registerKey(Keys.SATURATION, 5.0, 0.0, LanternKeys.MAX_SATURATION); | |||
registerKey(Keys.EXHAUSTION, 0.0, 0.0, 40.0); |
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.
Maybe also a MAX_EXHAUSTION
key?
* @return If this entity can be healed | ||
*/ | ||
public boolean canBeHealed() { | ||
return health().get() > health().getMinValue() && health().get() < health().getMaxValue(); |
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.
Only call health()
once and reuse the result.
* @param amount The amount to heal for | ||
*/ | ||
public void heal(double amount) { | ||
if (health().get() > health().getMinValue()) { |
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.
Only call health()
once and reuse the result.
} | ||
} else if (foodLevel.get() <= foodLevel.getMinValue()) { | ||
if ((System.currentTimeMillis() - this.lastFoodTime) >= 4000) { | ||
if (health().get() > 10.0 || getWorld().getDifficulty().equals(Difficulties.HARD) || health().get() > 1.0 && difficulty.equals( |
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.
Only call health()
once and reuse the result.
} | ||
} | ||
|
||
final boolean naturalRegeneration = getWorld().getGameRule(DefaultGameRules.NATURAL_REGENERATION).orElse("true").equals("true"); |
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.
Use the getRule
method, this will automatically handle parsing. The rule can be found in RuleTypes
.
c.registerKey(LanternKeys.MAX_FOOD_LEVEL, 20, 0, Integer.MAX_VALUE); | ||
c.registerKey(Keys.FOOD_LEVEL, 20, 0, LanternKeys.MAX_FOOD_LEVEL); | ||
c.registerKey(LanternKeys.MAX_EXHAUSTION, 40.0, 0.0, Double.MAX_VALUE); | ||
c.registerKey(Keys.EXHAUSTION, 0.0, 0.0, 40.0); |
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.
The MAX_EXHAUSTION
key shoul be used instead of the 40.0
as the max value.
c.registerKey(Keys.FOOD_LEVEL, 20, 0, LanternKeys.MAX_FOOD_LEVEL); | ||
c.registerKey(LanternKeys.MAX_EXHAUSTION, 40.0, 0.0, Double.MAX_VALUE); | ||
c.registerKey(Keys.EXHAUSTION, 0.0, 0.0, LanternKeys.MAX_EXHAUSTION); | ||
c.registerKey(LanternKeys.MAX_SATURATION, 40.0, 0.0, Double.MAX_VALUE); |
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.
The default max saturation is 5.0
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 seems that's the default saturation. I can't find a clear max, as it seems to actually change?
"The maximum value of the food saturation level is equal to the current value of your food level"
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'm not really sure how to handle this
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.
So maximum 20 by default? You can also remove the MAX_SATURATION
key and use FOOD
as the maximum for SATURATION
. I don't really know how the food system works.
So I think the other behaviors are out of scope of what I can accomplish now, at least the movement ones, as they are a bit over my head. For the damage one, I am waiting on SpongePowered/SpongeAPI#1592 For now though, I think the functionality is pretty close. It seems peaceful regeneration of food looks strange, not sure how to go about fixing that though. |
@@ -47,6 +48,11 @@ public BehaviorResult tryBreak(BehaviorPipeline<Behavior> pipeline, BehaviorCont | |||
builder.blockState(BlockTypes.AIR.getDefaultState()); | |||
// Add the block change | |||
context.addBlockChange(builder.build()); | |||
context.get(Parameters.PLAYER).ifPresent(p -> { | |||
if (p.supports(Keys.EXHAUSTION)) { | |||
p.offer(Keys.EXHAUSTION, p.get(Keys.EXHAUSTION).get() + .005); |
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.
Can you replace the .005
with 0.005
b816e1f
to
eec7b6b
Compare
c.register(Keys.SATURATION, 0.0, 0.0, 5.0); | ||
c.register(Keys.FOOD_LEVEL, 20, 0, LanternKeys.MAX_FOOD_LEVEL); | ||
c.registerWithSuppliedMax(LanternKeys.MAX_SATURATION, 20.0, 0.0, container -> container.get(Keys.FOOD_LEVEL).get().doubleValue()); | ||
c.register(Keys.SATURATION, 5.0, 0.0, LanternKeys.MAX_SATURATION); |
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.
Weren't you going to remove the MAX_SATURATION
key and use the food level as max? Because now will the max saturation never change, well, it can only become smaller if the food level decreases.
83020cb
to
4d41b03
Compare
I'll fix that build error when I solve the exhaustion issues. |
4d41b03
to
c874be6
Compare
So it seems everything is working including the hunger effect - I am successfully adding 0.005 x level per tick as the wiki for the 30 seconds to add up to 3 exhaustion which matches the description on the wiki here: The remaining exhaustion effects, damages, and changes to consumables are probably out of the scope of this PR for now, so if you want any other changes just ask. |
2552297
to
3e6847a
Compare
3e6847a
to
2f05793
Compare
My PR about switching SaturationProperty to use the proper value was pulled into Sponge, so I will go ahead and update all of the current saturation values as well as where I manipulate them. |
Development continues in #42 |
This is still work in progress, but I wouldn't mind some input as I continue on as I may be doing this completely wrong.