github.com/df-mc/dragonfly@v0.9.13/server/block/deadbush.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/particle" 8 "github.com/go-gl/mathgl/mgl64" 9 "math/rand" 10 ) 11 12 // DeadBush is a transparent block in the form of an aesthetic plant. 13 type DeadBush struct { 14 empty 15 replaceable 16 transparent 17 sourceWaterDisplacer 18 } 19 20 // NeighbourUpdateTick ... 21 func (d DeadBush) NeighbourUpdateTick(pos, _ cube.Pos, w *world.World) { 22 if !supportsVegetation(d, w.Block(pos.Side(cube.FaceDown))) { 23 w.SetBlock(pos, nil, nil) 24 w.AddParticle(pos.Vec3Centre(), particle.BlockBreak{Block: d}) 25 if amount := rand.Intn(3); amount != 0 { 26 dropItem(w, item.NewStack(item.Stick{}, amount), pos.Vec3Centre()) 27 } 28 } 29 } 30 31 // UseOnBlock ... 32 func (d DeadBush) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) bool { 33 pos, _, used := firstReplaceable(w, pos, face, d) 34 if !used { 35 return false 36 } 37 if !supportsVegetation(d, w.Block(pos.Side(cube.FaceDown))) { 38 return false 39 } 40 41 place(w, pos, d, user, ctx) 42 return placed(ctx) 43 } 44 45 // SideClosed ... 46 func (d DeadBush) SideClosed(cube.Pos, cube.Pos, *world.World) bool { 47 return false 48 } 49 50 // HasLiquidDrops ... 51 func (d DeadBush) HasLiquidDrops() bool { 52 return true 53 } 54 55 // FlammabilityInfo ... 56 func (d DeadBush) FlammabilityInfo() FlammabilityInfo { 57 return newFlammabilityInfo(60, 100, true) 58 } 59 60 // BreakInfo ... 61 func (d DeadBush) BreakInfo() BreakInfo { 62 return newBreakInfo(0, alwaysHarvestable, nothingEffective, func(t item.Tool, enchantments []item.Enchantment) []item.Stack { 63 if t.ToolType() == item.TypeShears { 64 return []item.Stack{item.NewStack(d, 1)} 65 } 66 if amount := rand.Intn(3); amount != 0 { 67 return []item.Stack{item.NewStack(item.Stick{}, amount)} 68 } 69 return nil 70 }) 71 } 72 73 // EncodeItem ... 74 func (d DeadBush) EncodeItem() (name string, meta int16) { 75 return "minecraft:deadbush", 0 76 } 77 78 // EncodeBlock ... 79 func (d DeadBush) EncodeBlock() (string, map[string]any) { 80 return "minecraft:deadbush", nil 81 }