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

     1  package item
     2  
     3  import (
     4  	"github.com/df-mc/dragonfly/server/block/cube"
     5  	"github.com/df-mc/dragonfly/server/world"
     6  	"github.com/df-mc/dragonfly/server/world/sound"
     7  	"github.com/go-gl/mathgl/mgl64"
     8  	"math/rand"
     9  	"time"
    10  )
    11  
    12  // FireCharge is an item that can be used to place fire when used on a block, or shot from a dispenser to create a small
    13  // fireball.
    14  type FireCharge struct{}
    15  
    16  // EncodeItem ...
    17  func (f FireCharge) EncodeItem() (name string, meta int16) {
    18  	return "minecraft:fire_charge", 0
    19  }
    20  
    21  // UseOnBlock ...
    22  func (f FireCharge) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, _ User, ctx *UseContext) bool {
    23  	if l, ok := w.Block(pos).(ignitable); ok && l.Ignite(pos, w) {
    24  		ctx.SubtractFromCount(1)
    25  		w.PlaySound(pos.Vec3Centre(), sound.FireCharge{})
    26  		return true
    27  	} else if s := pos.Side(face); w.Block(s) == air() {
    28  		ctx.SubtractFromCount(1)
    29  		w.PlaySound(s.Vec3Centre(), sound.FireCharge{})
    30  		w.SetBlock(s, fire(), nil)
    31  		w.ScheduleBlockUpdate(s, time.Duration(30+rand.Intn(10))*time.Second/20)
    32  		return true
    33  	}
    34  	return false
    35  }