github.com/df-mc/dragonfly@v0.9.13/server/block/sand.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  )
     8  
     9  // Sand is a block affected by gravity. It can come in a red variant.
    10  type Sand struct {
    11  	gravityAffected
    12  	solid
    13  	snare
    14  
    15  	// Red toggles the red sand variant.
    16  	Red bool
    17  }
    18  
    19  // SoilFor ...
    20  func (s Sand) SoilFor(block world.Block) bool {
    21  	switch block.(type) {
    22  	case Cactus, DeadBush, SugarCane:
    23  		return true
    24  	}
    25  	return false
    26  }
    27  
    28  // NeighbourUpdateTick ...
    29  func (s Sand) NeighbourUpdateTick(pos, _ cube.Pos, w *world.World) {
    30  	s.fall(s, pos, w)
    31  }
    32  
    33  // BreakInfo ...
    34  func (s Sand) BreakInfo() BreakInfo {
    35  	return newBreakInfo(0.5, alwaysHarvestable, shovelEffective, oneOf(s))
    36  }
    37  
    38  // SmeltInfo ...
    39  func (Sand) SmeltInfo() item.SmeltInfo {
    40  	return newSmeltInfo(item.NewStack(Glass{}, 1), 0.1)
    41  }
    42  
    43  // EncodeItem ...
    44  func (s Sand) EncodeItem() (name string, meta int16) {
    45  	if s.Red {
    46  		return "minecraft:sand", 1
    47  	}
    48  	return "minecraft:sand", 0
    49  }
    50  
    51  // EncodeBlock ...
    52  func (s Sand) EncodeBlock() (string, map[string]any) {
    53  	if s.Red {
    54  		return "minecraft:sand", map[string]any{"sand_type": "red"}
    55  	}
    56  	return "minecraft:sand", map[string]any{"sand_type": "normal"}
    57  }