github.com/df-mc/dragonfly@v0.9.13/server/block/loom.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  	"time"
     9  )
    10  
    11  // Loom is a block used to apply patterns on banners. It is also used as a shepherd's job site block that is found in
    12  // villages.
    13  type Loom struct {
    14  	solid
    15  	bass
    16  
    17  	// Facing is the direction the loom is facing.
    18  	Facing cube.Direction
    19  }
    20  
    21  // FuelInfo ...
    22  func (Loom) FuelInfo() item.FuelInfo {
    23  	return newFuelInfo(time.Second * 15)
    24  }
    25  
    26  // BreakInfo ...
    27  func (l Loom) BreakInfo() BreakInfo {
    28  	return newBreakInfo(2.5, alwaysHarvestable, axeEffective, oneOf(l))
    29  }
    30  
    31  // Activate ...
    32  func (Loom) Activate(pos cube.Pos, _ cube.Face, _ *world.World, u item.User, _ *item.UseContext) bool {
    33  	if opener, ok := u.(ContainerOpener); ok {
    34  		opener.OpenBlockContainer(pos)
    35  		return true
    36  	}
    37  	return false
    38  }
    39  
    40  // UseOnBlock ...
    41  func (l Loom) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) (used bool) {
    42  	pos, _, used = firstReplaceable(w, pos, face, l)
    43  	if !used {
    44  		return
    45  	}
    46  	l.Facing = user.Rotation().Direction().Opposite()
    47  	place(w, pos, l, user, ctx)
    48  	return placed(ctx)
    49  }
    50  
    51  // EncodeItem ...
    52  func (Loom) EncodeItem() (name string, meta int16) {
    53  	return "minecraft:loom", 0
    54  }
    55  
    56  // EncodeBlock ...
    57  func (l Loom) EncodeBlock() (name string, properties map[string]interface{}) {
    58  	return "minecraft:loom", map[string]interface{}{"direction": int32(horizontalDirection(l.Facing))}
    59  }
    60  
    61  // allLooms ...
    62  func allLooms() (looms []world.Block) {
    63  	for _, d := range cube.Directions() {
    64  		looms = append(looms, Loom{Facing: d})
    65  	}
    66  	return
    67  }