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

Add getter methods for weather states #955

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 20 additions & 1 deletion server/world/weather.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package world

import (
"time"

"github.com/df-mc/dragonfly/server/block/cube"
"github.com/go-gl/mathgl/mgl64"
"time"
)

// weather implements weather related methods for World. World embeds this
Expand Down Expand Up @@ -72,6 +73,15 @@ func (w weather) StartRaining(dur time.Duration) {
w.setRaining(true, dur)
}

// Raining returns whether it is currently raining in the world,
// as well as the remaining time it will be raining for.
func (w weather) Raining() (bool, time.Duration) {
w.w.set.Lock()
defer w.w.set.Unlock()

return w.w.set.Raining, time.Duration(w.w.set.RainTime)
}

// StopRaining makes it stop raining in the World.
func (w weather) StopRaining() {
w.w.set.Lock()
Expand All @@ -98,6 +108,15 @@ func (w weather) StartThundering(dur time.Duration) {
w.setRaining(true, dur)
}

// Thundering returns whether it is currently thundering and raining in the world,
// as well as the remaining time it will be thundering for.
func (w weather) Thundering() (bool, time.Duration) {
w.w.set.Lock()
defer w.w.set.Unlock()

return w.w.set.Thundering && w.w.set.Raining, time.Duration(w.w.set.ThunderTime)
}

// StopThundering makes it stop thundering in the current world.
func (w weather) StopThundering() {
w.w.set.Lock()
Expand Down
Loading