github.com/df-mc/dragonfly@v0.9.13/server/block/nether_wart.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 "math/rand" 9 ) 10 11 // NetherWart is a fungus found in the Nether that is vital in the creation of potions. 12 type NetherWart struct { 13 transparent 14 empty 15 16 // Age is the age of the nether wart block. 3 is fully grown. 17 Age int 18 } 19 20 // HasLiquidDrops ... 21 func (n NetherWart) HasLiquidDrops() bool { 22 return true 23 } 24 25 // RandomTick ... 26 func (n NetherWart) RandomTick(pos cube.Pos, w *world.World, r *rand.Rand) { 27 if n.Age < 3 && r.Float64() < 0.1 { 28 n.Age++ 29 w.SetBlock(pos, n, nil) 30 } 31 } 32 33 // UseOnBlock ... 34 func (n NetherWart) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) bool { 35 pos, _, used := firstReplaceable(w, pos, face, n) 36 if !used { 37 return false 38 } 39 if _, ok := w.Block(pos.Side(cube.FaceDown)).(SoulSand); !ok { 40 return false 41 } 42 43 place(w, pos, n, user, ctx) 44 return placed(ctx) 45 } 46 47 // NeighbourUpdateTick ... 48 func (n NetherWart) NeighbourUpdateTick(pos, _ cube.Pos, w *world.World) { 49 if _, ok := w.Block(pos.Side(cube.FaceDown)).(SoulSand); !ok { 50 w.SetBlock(pos, nil, nil) 51 } 52 } 53 54 // BreakInfo ... 55 func (n NetherWart) BreakInfo() BreakInfo { 56 return newBreakInfo(0, alwaysHarvestable, nothingEffective, func(item.Tool, []item.Enchantment) []item.Stack { 57 if n.Age == 3 { 58 return []item.Stack{item.NewStack(n, rand.Intn(3)+2)} 59 } 60 return []item.Stack{item.NewStack(n, 1)} 61 }) 62 } 63 64 // CompostChance ... 65 func (NetherWart) CompostChance() float64 { 66 return 0.65 67 } 68 69 // EncodeItem ... 70 func (NetherWart) EncodeItem() (name string, meta int16) { 71 return "minecraft:nether_wart", 0 72 } 73 74 // EncodeBlock ... 75 func (n NetherWart) EncodeBlock() (name string, properties map[string]any) { 76 return "minecraft:nether_wart", map[string]any{"age": int32(n.Age)} 77 } 78 79 // allNetherWart ... 80 func allNetherWart() (wart []world.Block) { 81 for i := 0; i < 4; i++ { 82 wart = append(wart, NetherWart{Age: i}) 83 } 84 return 85 }