github.com/df-mc/dragonfly@v0.9.13/server/item/glass_bottle.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  // GlassBottle is an item that can hold various liquids.
    10  type GlassBottle struct{}
    11  
    12  // bottleFiller is implemented by blocks that can fill bottles by clicking on them.
    13  type bottleFiller interface {
    14  	// FillBottle fills a GlassBottle by interacting with a block. Blocks that implement this interface return both the
    15  	// block that should be placed in the world after filling the bottle, and the item that was produced as a result of
    16  	// the filling.
    17  	// If the bool returned is false, nothing will happen when using a GlassBottle on the block.
    18  	FillBottle() (world.Block, Stack, bool)
    19  }
    20  
    21  // UseOnBlock ...
    22  func (g GlassBottle) UseOnBlock(pos cube.Pos, _ cube.Face, _ mgl64.Vec3, w *world.World, _ User, ctx *UseContext) bool {
    23  	bl := w.Block(pos)
    24  	if b, ok := bl.(bottleFiller); ok {
    25  		var res world.Block
    26  		if res, ctx.NewItem, ok = b.FillBottle(); ok {
    27  			ctx.SubtractFromCount(1)
    28  			if res != bl {
    29  				// Some blocks (think a cauldron) change when using a bottle on it.
    30  				w.SetBlock(pos, res, nil)
    31  			}
    32  		}
    33  	}
    34  	return false
    35  }
    36  
    37  // EncodeItem ...
    38  func (g GlassBottle) EncodeItem() (name string, meta int16) {
    39  	return "minecraft:glass_bottle", 0
    40  }