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

     1  package block
     2  
     3  import (
     4  	"github.com/df-mc/dragonfly/server/item"
     5  	"github.com/df-mc/dragonfly/server/world"
     6  	"math/rand"
     7  )
     8  
     9  // Blackstone is a naturally generating block in the nether that can be used to craft stone tools, brewing stands and
    10  // furnaces. Gilded blackstone also has a 10% chance to drop 2-6 golden nuggets.
    11  type Blackstone struct {
    12  	solid
    13  	bassDrum
    14  
    15  	// Type is the type of blackstone of the block.
    16  	Type BlackstoneType
    17  }
    18  
    19  // BreakInfo ...
    20  func (b Blackstone) BreakInfo() BreakInfo {
    21  	drops := oneOf(b)
    22  	if b.Type == GildedBlackstone() {
    23  		drops = func(item.Tool, []item.Enchantment) []item.Stack {
    24  			if rand.Float64() < 0.1 {
    25  				return []item.Stack{item.NewStack(item.GoldNugget{}, rand.Intn(4)+2)}
    26  			}
    27  			return []item.Stack{item.NewStack(b, 1)}
    28  		}
    29  	}
    30  	return newBreakInfo(1.5, pickaxeHarvestable, pickaxeEffective, drops).withBlastResistance(30)
    31  }
    32  
    33  // EncodeItem ...
    34  func (b Blackstone) EncodeItem() (name string, meta int16) {
    35  	return "minecraft:" + b.Type.String(), 0
    36  }
    37  
    38  // EncodeBlock ...
    39  func (b Blackstone) EncodeBlock() (string, map[string]any) {
    40  	return "minecraft:" + b.Type.String(), nil
    41  }
    42  
    43  // allBlackstone returns a list of all blackstone block variants.
    44  func allBlackstone() (s []world.Block) {
    45  	for _, t := range BlackstoneTypes() {
    46  		s = append(s, Blackstone{Type: t})
    47  	}
    48  	return
    49  }