github.com/df-mc/dragonfly@v0.9.13/server/item/ink_sac.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  // InkSac is an item dropped by a squid upon death used to create black dye, dark prismarine and book and quill. The
    10  // glowing variant, obtained by killing a glow squid, may be used to cause sign text to light up.
    11  type InkSac struct {
    12  	// 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.
    13  	Glowing bool
    14  }
    15  
    16  // UseOnBlock handles the logic of using an ink sac on a sign. Glowing ink sacs turn the text of these signs glowing,
    17  // whereas normal ink sacs revert them back to non-glowing text.
    18  func (i InkSac) UseOnBlock(pos cube.Pos, _ cube.Face, _ mgl64.Vec3, w *world.World, user User, ctx *UseContext) bool {
    19  	if in, ok := w.Block(pos).(inkable); ok {
    20  		if res, ok := in.Ink(pos, user.Position(), i.Glowing); ok {
    21  			w.SetBlock(pos, res, nil)
    22  			ctx.SubtractFromCount(1)
    23  			return true
    24  		}
    25  	}
    26  	return false
    27  }
    28  
    29  // inkable represents a block that may be inked, either glowing or reverted from glowing, by using a (glow) ink sac
    30  // on it.
    31  type inkable interface {
    32  	// Ink uses an ink sac on the block, returning the resulting block and a bool specifying if inking the block was
    33  	// successful.
    34  	Ink(pos cube.Pos, userPos mgl64.Vec3, glowing bool) (world.Block, bool)
    35  }
    36  
    37  // EncodeItem ...
    38  func (i InkSac) EncodeItem() (name string, meta int16) {
    39  	if i.Glowing {
    40  		return "minecraft:glow_ink_sac", 0
    41  	}
    42  	return "minecraft:ink_sac", 0
    43  }