github.com/df-mc/dragonfly@v0.9.13/server/block/pumpkin.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  // Pumpkin is a crop block. Interacting with shears results in the carved variant.
    12  type Pumpkin struct {
    13  	solid
    14  
    15  	// Carved is whether the pumpkin is carved.
    16  	Carved bool
    17  	// Facing is the direction the pumpkin is facing.
    18  	Facing cube.Direction
    19  }
    20  
    21  // Instrument ...
    22  func (p Pumpkin) Instrument() sound.Instrument {
    23  	if !p.Carved {
    24  		return sound.Didgeridoo()
    25  	}
    26  	return sound.Piano()
    27  }
    28  
    29  // UseOnBlock ...
    30  func (p Pumpkin) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) (used bool) {
    31  	pos, _, used = firstReplaceable(w, pos, face, p)
    32  	if !used {
    33  		return
    34  	}
    35  	p.Facing = user.Rotation().Direction().Opposite()
    36  
    37  	place(w, pos, p, user, ctx)
    38  	return placed(ctx)
    39  }
    40  
    41  // BreakInfo ...
    42  func (p Pumpkin) BreakInfo() BreakInfo {
    43  	return newBreakInfo(1, alwaysHarvestable, axeEffective, oneOf(p))
    44  }
    45  
    46  // CompostChance ...
    47  func (Pumpkin) CompostChance() float64 {
    48  	return 0.65
    49  }
    50  
    51  // Carve ...
    52  func (p Pumpkin) Carve(f cube.Face) (world.Block, bool) {
    53  	return Pumpkin{Facing: f.Direction(), Carved: true}, !p.Carved
    54  }
    55  
    56  // Helmet ...
    57  func (p Pumpkin) Helmet() bool {
    58  	return p.Carved
    59  }
    60  
    61  // DefencePoints ...
    62  func (p Pumpkin) DefencePoints() float64 {
    63  	return 0
    64  }
    65  
    66  // Toughness ...
    67  func (p Pumpkin) Toughness() float64 {
    68  	return 0
    69  }
    70  
    71  // KnockBackResistance ...
    72  func (p Pumpkin) KnockBackResistance() float64 {
    73  	return 0
    74  }
    75  
    76  // EncodeItem ...
    77  func (p Pumpkin) EncodeItem() (name string, meta int16) {
    78  	if p.Carved {
    79  		return "minecraft:carved_pumpkin", 0
    80  	}
    81  	return "minecraft:pumpkin", 0
    82  }
    83  
    84  // EncodeBlock ...
    85  func (p Pumpkin) EncodeBlock() (name string, properties map[string]any) {
    86  	if p.Carved {
    87  		return "minecraft:carved_pumpkin", map[string]any{"minecraft:cardinal_direction": p.Facing.String()}
    88  	}
    89  	return "minecraft:pumpkin", map[string]any{"minecraft:cardinal_direction": p.Facing.String()}
    90  }
    91  
    92  func allPumpkins() (pumpkins []world.Block) {
    93  	for i := cube.Direction(0); i <= 3; i++ {
    94  		pumpkins = append(pumpkins, Pumpkin{Facing: i})
    95  		pumpkins = append(pumpkins, Pumpkin{Facing: i, Carved: true})
    96  	}
    97  	return
    98  }