github.com/df-mc/dragonfly@v0.9.13/server/block/dragon_egg.go (about) 1 package block 2 3 import ( 4 "math/rand" 5 6 "github.com/df-mc/dragonfly/server/block/cube" 7 "github.com/df-mc/dragonfly/server/item" 8 "github.com/df-mc/dragonfly/server/world" 9 "github.com/df-mc/dragonfly/server/world/particle" 10 ) 11 12 // DragonEgg is a decorative block or a "trophy item", and the rarest item in the game. 13 type DragonEgg struct { 14 solid 15 transparent 16 gravityAffected 17 sourceWaterDisplacer 18 } 19 20 // NeighbourUpdateTick ... 21 func (d DragonEgg) NeighbourUpdateTick(pos, _ cube.Pos, w *world.World) { 22 d.fall(d, pos, w) 23 } 24 25 // SideClosed ... 26 func (d DragonEgg) SideClosed(cube.Pos, cube.Pos, *world.World) bool { 27 return false 28 } 29 30 // teleport ... 31 func (d DragonEgg) teleport(pos cube.Pos, w *world.World) { 32 for i := 0; i < 1000; i++ { 33 newPos := pos.Add(cube.Pos{rand.Intn(31) - 15, max(w.Range()[0]-pos.Y(), min(w.Range()[1]-pos.Y(), rand.Intn(15)-7)), rand.Intn(31) - 15}) 34 35 if _, ok := w.Block(newPos).(Air); ok { 36 w.SetBlock(newPos, d, nil) 37 w.SetBlock(pos, nil, nil) 38 w.AddParticle(pos.Vec3(), particle.DragonEggTeleport{Diff: pos.Sub(newPos)}) 39 return 40 } 41 } 42 } 43 44 // LightEmissionLevel ... 45 func (d DragonEgg) LightEmissionLevel() uint8 { 46 return 1 47 } 48 49 // Punch ... 50 func (d DragonEgg) Punch(pos cube.Pos, _ cube.Face, w *world.World, u item.User) { 51 if gm, ok := u.(interface{ GameMode() world.GameMode }); ok && gm.GameMode().CreativeInventory() { 52 return 53 } 54 d.teleport(pos, w) 55 } 56 57 // Activate ... 58 func (d DragonEgg) Activate(pos cube.Pos, _ cube.Face, w *world.World, _ item.User, _ *item.UseContext) bool { 59 d.teleport(pos, w) 60 return true 61 } 62 63 // BreakInfo ... 64 func (d DragonEgg) BreakInfo() BreakInfo { 65 return newBreakInfo(3, pickaxeHarvestable, pickaxeEffective, oneOf(d)) 66 } 67 68 // EncodeItem ... 69 func (DragonEgg) EncodeItem() (name string, meta int16) { 70 return "minecraft:dragon_egg", 0 71 } 72 73 // EncodeBlock ... 74 func (DragonEgg) EncodeBlock() (string, map[string]any) { 75 return "minecraft:dragon_egg", nil 76 }