github.com/df-mc/dragonfly@v0.9.13/server/item/shears.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  // Shears is a tool used to shear sheep, mine a few types of blocks, and carve pumpkins.
    10  type Shears struct{}
    11  
    12  // UseOnBlock ...
    13  func (s Shears) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, _ User, ctx *UseContext) bool {
    14  	if face == cube.FaceUp || face == cube.FaceDown {
    15  		// Pumpkins can only be carved when one of the horizontal faces is clicked.
    16  		return false
    17  	}
    18  	if c, ok := w.Block(pos).(carvable); ok {
    19  		if res, ok := c.Carve(face); ok {
    20  			// TODO: Drop pumpkin seeds.
    21  			w.SetBlock(pos, res, nil)
    22  
    23  			ctx.DamageItem(1)
    24  			return true
    25  		}
    26  	}
    27  	return false
    28  }
    29  
    30  // carvable represents a block that may be carved by using shears on it.
    31  type carvable interface {
    32  	// Carve returns the resulting block of carving this block. If carving it has no result, Carve returns false.
    33  	Carve(f cube.Face) (world.Block, bool)
    34  }
    35  
    36  // ToolType ...
    37  func (s Shears) ToolType() ToolType {
    38  	return TypeShears
    39  }
    40  
    41  // HarvestLevel ...
    42  func (s Shears) HarvestLevel() int {
    43  	return 1
    44  }
    45  
    46  // BaseMiningEfficiency ...
    47  func (s Shears) BaseMiningEfficiency(world.Block) float64 {
    48  	return 1.5
    49  }
    50  
    51  // DurabilityInfo ...
    52  func (s Shears) DurabilityInfo() DurabilityInfo {
    53  	return DurabilityInfo{
    54  		MaxDurability:    238,
    55  		BrokenItem:       simpleItem(Stack{}),
    56  		AttackDurability: 0,
    57  		BreakDurability:  1,
    58  	}
    59  }
    60  
    61  // MaxCount ...
    62  func (s Shears) MaxCount() int {
    63  	return 1
    64  }
    65  
    66  // EncodeItem ...
    67  func (s Shears) EncodeItem() (name string, meta int16) {
    68  	return "minecraft:shears", 0
    69  }