-
Notifications
You must be signed in to change notification settings - Fork 141
/
ink_sac.go
43 lines (38 loc) · 1.51 KB
/
ink_sac.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
package item
import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/world"
"github.com/go-gl/mathgl/mgl64"
)
// InkSac is an item dropped by a squid upon death used to create black dye, dark prismarine and book and quill. The
// glowing variant, obtained by killing a glow squid, may be used to cause sign text to light up.
type InkSac struct {
// Glowing specifies if the ink sac is that of a glow squid. If true, it may be used on a sign to light up its text.
Glowing bool
}
// UseOnBlock handles the logic of using an ink sac on a sign. Glowing ink sacs turn the text of these signs glowing,
// whereas normal ink sacs revert them back to non-glowing text.
func (i InkSac) UseOnBlock(pos cube.Pos, _ cube.Face, _ mgl64.Vec3, w *world.World, user User, ctx *UseContext) bool {
if in, ok := w.Block(pos).(inkable); ok {
if res, ok := in.Ink(pos, user.Position(), i.Glowing); ok {
w.SetBlock(pos, res, nil)
ctx.SubtractFromCount(1)
return true
}
}
return false
}
// inkable represents a block that may be inked, either glowing or reverted from glowing, by using a (glow) ink sac
// on it.
type inkable interface {
// Ink uses an ink sac on the block, returning the resulting block and a bool specifying if inking the block was
// successful.
Ink(pos cube.Pos, userPos mgl64.Vec3, glowing bool) (world.Block, bool)
}
// EncodeItem ...
func (i InkSac) EncodeItem() (name string, meta int16) {
if i.Glowing {
return "minecraft:glow_ink_sac", 0
}
return "minecraft:ink_sac", 0
}