github.com/df-mc/dragonfly@v0.9.13/server/block/carpet.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/go-gl/mathgl/mgl64"
     8  )
     9  
    10  // Carpet is a colourful block that can be obtained by killing/shearing sheep, or crafted using four string.
    11  type Carpet struct {
    12  	carpet
    13  	transparent
    14  	sourceWaterDisplacer
    15  
    16  	// Colour is the colour of the carpet.
    17  	Colour item.Colour
    18  }
    19  
    20  // FlammabilityInfo ...
    21  func (c Carpet) FlammabilityInfo() FlammabilityInfo {
    22  	return newFlammabilityInfo(30, 20, true)
    23  }
    24  
    25  // SideClosed ...
    26  func (Carpet) SideClosed(cube.Pos, cube.Pos, *world.World) bool {
    27  	return false
    28  }
    29  
    30  // BreakInfo ...
    31  func (c Carpet) BreakInfo() BreakInfo {
    32  	return newBreakInfo(0.1, alwaysHarvestable, nothingEffective, oneOf(c))
    33  }
    34  
    35  // EncodeItem ...
    36  func (c Carpet) EncodeItem() (name string, meta int16) {
    37  	return "minecraft:" + c.Colour.String() + "_carpet", 0
    38  }
    39  
    40  // EncodeBlock ...
    41  func (c Carpet) EncodeBlock() (name string, properties map[string]any) {
    42  	return "minecraft:" + c.Colour.String() + "_carpet", nil
    43  }
    44  
    45  // HasLiquidDrops ...
    46  func (Carpet) HasLiquidDrops() bool {
    47  	return true
    48  }
    49  
    50  // NeighbourUpdateTick ...
    51  func (c Carpet) NeighbourUpdateTick(pos, _ cube.Pos, w *world.World) {
    52  	if _, ok := w.Block(pos.Side(cube.FaceDown)).(Air); ok {
    53  		w.SetBlock(pos, nil, nil)
    54  		dropItem(w, item.NewStack(c, 1), pos.Vec3Centre())
    55  	}
    56  }
    57  
    58  // UseOnBlock handles not placing carpets on top of air blocks.
    59  func (c Carpet) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) (used bool) {
    60  	pos, _, used = firstReplaceable(w, pos, face, c)
    61  	if !used {
    62  		return
    63  	}
    64  
    65  	if _, ok := w.Block(pos.Side(cube.FaceDown)).(Air); ok {
    66  		return
    67  	}
    68  
    69  	place(w, pos, c, user, ctx)
    70  	return placed(ctx)
    71  }
    72  
    73  // allCarpet ...
    74  func allCarpet() (carpets []world.Block) {
    75  	for _, c := range item.Colours() {
    76  		carpets = append(carpets, Carpet{Colour: c})
    77  	}
    78  	return
    79  }