-
Notifications
You must be signed in to change notification settings - Fork 143
/
splash_potion.go
45 lines (37 loc) · 1.03 KB
/
splash_potion.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package item
import (
"github.com/df-mc/dragonfly/server/item/potion"
"github.com/df-mc/dragonfly/server/world"
"github.com/df-mc/dragonfly/server/world/sound"
"github.com/go-gl/mathgl/mgl64"
)
// SplashPotion is an item that grants effects when thrown.
type SplashPotion struct {
// Type is the type of splash potion.
Type potion.Potion
}
// MaxCount ...
func (s SplashPotion) MaxCount() int {
return 1
}
// Use ...
func (s SplashPotion) Use(w *world.World, user User, ctx *UseContext) bool {
splash, ok := world.EntityByName("minecraft:splash_potion")
if !ok {
return false
}
p, ok := splash.(interface {
New(pos, vel mgl64.Vec3, t potion.Potion, owner world.Entity) world.Entity
})
if !ok {
return false
}
w.PlaySound(user.Position(), sound.ItemThrow{})
w.AddEntity(p.New(eyePosition(user), directionVector(user).Mul(0.5), s.Type, user))
ctx.SubtractFromCount(1)
return true
}
// EncodeItem ...
func (s SplashPotion) EncodeItem() (name string, meta int16) {
return "minecraft:splash_potion", int16(s.Type.Uint8())
}