github.com/df-mc/dragonfly@v0.9.13/server/item/dye.go (about) 1 package item 2 3 import ( 4 "github.com/df-mc/dragonfly/server/block/cube" 5 "github.com/df-mc/dragonfly/server/world" 6 "github.com/go-gl/mathgl/mgl64" 7 ) 8 9 // Dye is an item that comes in 16 colours which allows you to colour blocks like concrete and sheep. 10 type Dye struct { 11 // Colour is the colour of the dye. 12 Colour Colour 13 } 14 15 // UseOnBlock implements the colouring behaviour of signs. 16 func (d Dye) UseOnBlock(pos cube.Pos, _ cube.Face, _ mgl64.Vec3, w *world.World, user User, ctx *UseContext) bool { 17 if dy, ok := w.Block(pos).(dyeable); ok { 18 if res, ok := dy.Dye(pos, user.Position(), d.Colour); ok { 19 w.SetBlock(pos, res, nil) 20 ctx.SubtractFromCount(1) 21 return true 22 } 23 } 24 return false 25 } 26 27 // dyeable represents a block that may be dyed by clicking it with a dye item. 28 type dyeable interface { 29 // Dye uses a dye with the Colour passed on the block. The resulting block is returned. A bool is returned to 30 // indicate if dyeing the block was successful. 31 Dye(pos cube.Pos, userPos mgl64.Vec3, c Colour) (world.Block, bool) 32 } 33 34 // EncodeItem ... 35 func (d Dye) EncodeItem() (name string, meta int16) { 36 return "minecraft:" + d.Colour.String() + "_dye", 0 37 }