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

     1  package block
     2  
     3  import (
     4  	"github.com/df-mc/dragonfly/server/block/cube"
     5  	"github.com/df-mc/dragonfly/server/item"
     6  	"github.com/df-mc/dragonfly/server/world"
     7  	"github.com/df-mc/dragonfly/server/world/sound"
     8  	"github.com/go-gl/mathgl/mgl64"
     9  )
    10  
    11  // HayBale is a decorative, flammable block that can also be used to
    12  // feed horses, breed llamas, reduce fall damage, and extend campfire smokes.
    13  type HayBale struct {
    14  	solid
    15  
    16  	// Axis is the axis which the hay bale block faces.
    17  	Axis cube.Axis
    18  }
    19  
    20  // Instrument ...
    21  func (HayBale) Instrument() sound.Instrument {
    22  	return sound.Banjo()
    23  }
    24  
    25  // EntityLand ...
    26  func (h HayBale) EntityLand(_ cube.Pos, _ *world.World, e world.Entity, distance *float64) {
    27  	if _, ok := e.(fallDistanceEntity); ok {
    28  		*distance *= 0.2
    29  	}
    30  }
    31  
    32  // UseOnBlock ...
    33  func (h HayBale) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) (used bool) {
    34  	pos, face, used = firstReplaceable(w, pos, face, h)
    35  	if !used {
    36  		return
    37  	}
    38  	h.Axis = face.Axis()
    39  
    40  	place(w, pos, h, user, ctx)
    41  	return placed(ctx)
    42  }
    43  
    44  // FlammabilityInfo ...
    45  func (HayBale) FlammabilityInfo() FlammabilityInfo {
    46  	return newFlammabilityInfo(60, 20, false)
    47  }
    48  
    49  // BreakInfo ...
    50  func (h HayBale) BreakInfo() BreakInfo {
    51  	return newBreakInfo(0.5, alwaysHarvestable, hoeEffective, oneOf(h))
    52  }
    53  
    54  // CompostChance ...
    55  func (HayBale) CompostChance() float64 {
    56  	return 0.85
    57  }
    58  
    59  // EncodeItem ...
    60  func (HayBale) EncodeItem() (name string, meta int16) {
    61  	return "minecraft:hay_block", 0
    62  }
    63  
    64  // EncodeBlock ...
    65  func (h HayBale) EncodeBlock() (name string, properties map[string]interface{}) {
    66  	return "minecraft:hay_block", map[string]interface{}{"pillar_axis": h.Axis.String(), "deprecated": int32(0)}
    67  }
    68  
    69  // allHayBales ...
    70  func allHayBales() (haybale []world.Block) {
    71  	for _, a := range cube.Axes() {
    72  		haybale = append(haybale, HayBale{Axis: a})
    73  	}
    74  	return
    75  }