github.com/df-mc/dragonfly@v0.9.13/server/block/stonecutter.go (about)

     1  package block
     2  
     3  import (
     4  	"github.com/df-mc/dragonfly/server/block/cube"
     5  	"github.com/df-mc/dragonfly/server/block/model"
     6  	"github.com/df-mc/dragonfly/server/item"
     7  	"github.com/df-mc/dragonfly/server/world"
     8  	"github.com/go-gl/mathgl/mgl64"
     9  )
    10  
    11  // Stonecutter is used to craft stone and copper related blocks in smaller and more precise quantities than crafting,
    12  // and is more efficient than crafting for certain recipes.
    13  type Stonecutter struct {
    14  	bassDrum
    15  
    16  	// Facing is the direction the stonecutter is facing.
    17  	Facing cube.Direction
    18  }
    19  
    20  // Model ...
    21  func (Stonecutter) Model() world.BlockModel {
    22  	return model.Stonecutter{}
    23  }
    24  
    25  // BreakInfo ...
    26  func (s Stonecutter) BreakInfo() BreakInfo {
    27  	return newBreakInfo(3.5, pickaxeHarvestable, pickaxeEffective, oneOf(s))
    28  }
    29  
    30  // Activate ...
    31  func (Stonecutter) Activate(pos cube.Pos, _ cube.Face, _ *world.World, u item.User, _ *item.UseContext) bool {
    32  	if opener, ok := u.(ContainerOpener); ok {
    33  		opener.OpenBlockContainer(pos)
    34  		return true
    35  	}
    36  	return false
    37  }
    38  
    39  // UseOnBlock ...
    40  func (s Stonecutter) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) (used bool) {
    41  	pos, _, used = firstReplaceable(w, pos, face, s)
    42  	if !used {
    43  		return
    44  	}
    45  	s.Facing = user.Rotation().Direction().Opposite()
    46  	place(w, pos, s, user, ctx)
    47  	return placed(ctx)
    48  }
    49  
    50  // EncodeItem ...
    51  func (Stonecutter) EncodeItem() (name string, meta int16) {
    52  	return "minecraft:stonecutter_block", 0
    53  }
    54  
    55  // EncodeBlock ...
    56  func (s Stonecutter) EncodeBlock() (name string, properties map[string]interface{}) {
    57  	return "minecraft:stonecutter_block", map[string]any{"minecraft:cardinal_direction": s.Facing.String()}
    58  }
    59  
    60  // allStonecutters ...
    61  func allStonecutters() (stonecutters []world.Block) {
    62  	for _, d := range cube.Directions() {
    63  		stonecutters = append(stonecutters, Stonecutter{Facing: d})
    64  	}
    65  	return
    66  }