-
Notifications
You must be signed in to change notification settings - Fork 141
/
dye.go
37 lines (32 loc) · 1.14 KB
/
dye.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
package item
import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/world"
"github.com/go-gl/mathgl/mgl64"
)
// Dye is an item that comes in 16 colours which allows you to colour blocks like concrete and sheep.
type Dye struct {
// Colour is the colour of the dye.
Colour Colour
}
// UseOnBlock implements the colouring behaviour of signs.
func (d Dye) UseOnBlock(pos cube.Pos, _ cube.Face, _ mgl64.Vec3, w *world.World, user User, ctx *UseContext) bool {
if dy, ok := w.Block(pos).(dyeable); ok {
if res, ok := dy.Dye(pos, user.Position(), d.Colour); ok {
w.SetBlock(pos, res, nil)
ctx.SubtractFromCount(1)
return true
}
}
return false
}
// dyeable represents a block that may be dyed by clicking it with a dye item.
type dyeable interface {
// Dye uses a dye with the Colour passed on the block. The resulting block is returned. A bool is returned to
// indicate if dyeing the block was successful.
Dye(pos cube.Pos, userPos mgl64.Vec3, c Colour) (world.Block, bool)
}
// EncodeItem ...
func (d Dye) EncodeItem() (name string, meta int16) {
return "minecraft:" + d.Colour.String() + "_dye", 0
}