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

Feature/reset food saturation #903

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions server/player/hunger.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ func (m *hungerManager) Reset() {
m.mu.Unlock()
}

// ResetExhaustion resets the player's exhaustion level to 0.
// Prevents the player's food level from decreasing after preventing food loss.
func (m *hungerManager) resetExhaustion() {
Sandertv marked this conversation as resolved.
Show resolved Hide resolved
aabstractt marked this conversation as resolved.
Show resolved Hide resolved
m.mu.Lock()
defer m.mu.Unlock()
m.exhaustionLevel = 0
m.saturationLevel = 0
m.foodTick = 0
}

// exhaust exhausts the player by the amount of points passed. If the total exhaustion level exceeds 4, a
// saturation point, or food point, if saturation is 0, will be subtracted.
func (m *hungerManager) exhaust(points float64) {
Expand Down
6 changes: 6 additions & 0 deletions server/player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,12 @@ func (p *Player) Exhaust(points float64) {

ctx := event.C()
if p.Handler().HandleFoodLoss(ctx, before, &after); ctx.Cancelled() {
// Reset the exhaustion level if the event was cancelled.
// Because if we cancel this on some moments, and after a time we don't cancel it,
// the first food level going to decrease a bit faster than expected.
// An example is if we cancelled that on a world, and we change of world, our food decrease very fast on the next tick
p.hunger.resetExhaustion()

return
}
p.hunger.SetFood(after)
Expand Down
Loading