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