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

     1  package block
     2  
     3  import (
     4  	"github.com/df-mc/dragonfly/server/world"
     5  )
     6  
     7  // Dirt is a block found abundantly in most biomes under a layer of grass blocks at the top of the normal
     8  // world.
     9  type Dirt struct {
    10  	solid
    11  
    12  	// Coarse specifies if the dirt should be off the coarse dirt variant. Grass blocks won't spread on
    13  	// the block if set to true.
    14  	Coarse bool
    15  }
    16  
    17  // SoilFor ...
    18  func (d Dirt) SoilFor(block world.Block) bool {
    19  	switch block.(type) {
    20  	case TallGrass, DoubleTallGrass, DeadBush:
    21  		return !d.Coarse
    22  	case Flower, DoubleFlower, NetherSprouts, SugarCane:
    23  		return true
    24  	}
    25  	return false
    26  }
    27  
    28  // BreakInfo ...
    29  func (d Dirt) BreakInfo() BreakInfo {
    30  	return newBreakInfo(0.5, alwaysHarvestable, shovelEffective, oneOf(d))
    31  }
    32  
    33  // Till ...
    34  func (d Dirt) Till() (world.Block, bool) {
    35  	if d.Coarse {
    36  		return Dirt{Coarse: false}, true
    37  	}
    38  	return Farmland{}, true
    39  }
    40  
    41  // Shovel ...
    42  func (d Dirt) Shovel() (world.Block, bool) {
    43  	return DirtPath{}, true
    44  }
    45  
    46  // EncodeItem ...
    47  func (d Dirt) EncodeItem() (name string, meta int16) {
    48  	if d.Coarse {
    49  		meta = 1
    50  	}
    51  	return "minecraft:dirt", meta
    52  }
    53  
    54  // EncodeBlock ...
    55  func (d Dirt) EncodeBlock() (string, map[string]any) {
    56  	if d.Coarse {
    57  		return "minecraft:dirt", map[string]any{"dirt_type": "coarse"}
    58  	}
    59  	return "minecraft:dirt", map[string]any{"dirt_type": "normal"}
    60  }