Skip to content

Commit

Permalink
Set saturation level to food level with feed flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
sk89q committed Jun 27, 2014
1 parent fb5ae83 commit b298bed
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/main/java/com/sk89q/worldguard/bukkit/FlagStateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@

package com.sk89q.worldguard.bukkit;

import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;

import java.util.HashMap;
import java.util.Map;

import org.bukkit.GameMode;
import org.bukkit.World;
import org.bukkit.entity.Player;

import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import org.bukkit.GameMode;
import org.bukkit.World;
import org.bukkit.entity.Player;

import java.util.HashMap;
import java.util.Map;

import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;

/**
* This processes per-player state information and is also meant to be used
Expand Down Expand Up @@ -182,10 +181,12 @@ private void processFeed(ApplicableRegionSet applicable, Player player,

if (feedDelay <= 0) {
player.setFoodLevel(feedAmount > 0 ? maxHunger : minHunger);
player.setSaturation(player.getFoodLevel());
state.lastFeed = now;
} else if (now - state.lastFeed > feedDelay * 1000) {
// clamp health between minimum and maximum
player.setFoodLevel(Math.min(maxHunger, Math.max(minHunger, player.getFoodLevel() + feedAmount)));
player.setSaturation(player.getFoodLevel());
state.lastFeed = now;
}
}
Expand Down

10 comments on commit b298bed

@DarkArc
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't saturation normally max out at 5?

@wizjany
Copy link
Collaborator

Choose a reason for hiding this comment

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

yea...I think without a separate flag, we should set it to 5 for a positive feed_amount, and 0 for any negative feed_amount.

@DarkArc
Copy link
Member

Choose a reason for hiding this comment

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

Also, it might be best to do it only after the food has exceeded the food bar's capacity, otherwise strange things will happen, like 3 hunger with 3 invisible hunger...

@sk89q
Copy link
Member Author

@sk89q sk89q commented on b298bed Jun 27, 2014

Choose a reason for hiding this comment

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

As far as I know, and according to the MC wiki, saturation levels max at current food level. Therefore, your saturation level would max out at 20 if your food level was 20, and so on, as demonstrated in the code here.

I personally think that adjusting food level without adjusting saturation level is pretty pointless. If your saturation level is at 0 and your food level is bumped to 20, your food level will plummet down to 0 anyway, defeating the purpose.

Now perhaps there's an argument for not adjusting saturation if the food level is on a downward trend.

On the comment of "strange things": If you have 3 hunger and 0 "invisible hunger", you will drop to 0 hunger very soon. You need invisible hunger, aka. saturation. Arguably, 90% of what makes up hunger in Minecraft is the saturation level -- the food level is completely useless (the exception, of course, is when you drop to 6 or below food level).

@DarkArc
Copy link
Member

Choose a reason for hiding this comment

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

Interesting, I was under the impression that saturation was only affected after your current hunger bar was filled, thus being the extra. For example, steaks restores 8 hunger, and if eaten at 19 hunger would add 7 saturation. (EDIT: Though, now that I think about it, that doesn't make much sense with the presumption that it maxes at 5 lol)

@DarkArc
Copy link
Member

Choose a reason for hiding this comment

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

I did some testing to confirm how it actually works. Saturation does max out at 20, not 5, however, the behaviour here is still slightly strange, food has a separate value assigned to it for saturation, which makes things very awkward here. Ideally we could just have a separate flag for saturation amounts, but that would cause further confusion when you look at a declining hunger value -- so for addition this probably is the best case. Furthermore, the proper behaviour for removing hunger would indeed be to subtract the saturation, and then begin subtracting from the hunger level, so that should probably be changed.

One thing that I suppose should be considered is that now capping the maximum hunger caps the maximum saturation, which could cause strange behaviour for some existing usage cases of the flag -- though at the same time, the maximum food level is correlated to the maximum saturation level, and it's unlikely that anyone has a mechanic that is so finely tuned that it encompasses the usage of the saturation level, so... do we actually care?

@sk89q
Copy link
Member Author

@sk89q sk89q commented on b298bed Jun 27, 2014

Choose a reason for hiding this comment

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

I'm not sure what you mean by "now" -- maximum hunger has always capped saturation.

@DarkArc
Copy link
Member

Choose a reason for hiding this comment

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

Our flag caps it now, if you set max-hunger, it will modify the saturation, where as before it was untouched, ex max-hunger could be 4 and you could have a saturation level of 20 prior to this change. It's probably not worth worrying about in the slightest, but I figured I'd mention it.

@sk89q
Copy link
Member Author

@sk89q sk89q commented on b298bed Jun 27, 2014

Choose a reason for hiding this comment

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

Does Minecraft not cap it?

@DarkArc
Copy link
Member

Choose a reason for hiding this comment

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

It caps at 20, you can set a lower value to the saturation now though, and effectively cap it at some lower number like 16 with the flag, where as prior to the change it would be the default value (EDIT: we wouldn't modify the saturation, so the effective cap was the game's hard cap of 20), and thus capped at 20 regardless of the flag's value.

Please sign in to comment.