Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

parlough
Copy link
Contributor

@parlough parlough commented Apr 20, 2017

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.

@@ -45,6 +52,7 @@
public class LanternLiving extends LanternEntity implements Living {

private Vector3d headRotation = Vector3d.ZERO;
private long lastFoodTick = System.currentTimeMillis();
Copy link
Member

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(),
Copy link
Member

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();

Copy link
Member

@Cybermaxke Cybermaxke Apr 27, 2017

Choose a reason for hiding this comment

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

Try to reuse the Values 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()));

@parlough
Copy link
Contributor Author

I'll try to finish this in a few days. Next weekend will bring more time for me.

@parlough parlough force-pushed the feature/health-data branch from 046eebe to a3e59a4 Compare June 25, 2017 06:51
@parlough parlough changed the title [WIP] Begin work on food data and some health related ideas Some food data work for players Jun 25, 2017
@@ -45,7 +45,7 @@

public final class LanternServerLaunch {

public void main(String[] args) {
public static void main(String[] args) {
Copy link
Member

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.

Copy link
Contributor Author

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);
Copy link
Member

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();
Copy link
Member

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()) {
Copy link
Member

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(
Copy link
Member

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");
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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

Copy link
Contributor Author

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"

Copy link
Contributor Author

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

Copy link
Member

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.

@parlough
Copy link
Contributor Author

parlough commented Jun 25, 2017

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);
Copy link
Member

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

@Cybermaxke Cybermaxke self-assigned this Jun 27, 2017
@parlough parlough force-pushed the feature/health-data branch 2 times, most recently from b816e1f to eec7b6b Compare June 28, 2017 15:36
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);
Copy link
Member

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.

@parlough parlough force-pushed the feature/health-data branch from 83020cb to 4d41b03 Compare June 30, 2017 07:06
@parlough
Copy link
Contributor Author

I'll fix that build error when I solve the exhaustion issues.

@Cybermaxke Cybermaxke mentioned this pull request Jun 30, 2017
33 tasks
@parlough parlough force-pushed the feature/health-data branch from 4d41b03 to c874be6 Compare June 30, 2017 19:46
@parlough
Copy link
Contributor Author

parlough commented Jun 30, 2017

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:

image

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.

@parlough parlough force-pushed the feature/health-data branch 2 times, most recently from 2552297 to 3e6847a Compare July 2, 2017 22:11
@parlough parlough force-pushed the feature/health-data branch from 3e6847a to 2f05793 Compare July 3, 2017 21:35
@parlough
Copy link
Contributor Author

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.

@Cybermaxke
Copy link
Member

Development continues in #42

@Cybermaxke Cybermaxke closed this Sep 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants