-
Notifications
You must be signed in to change notification settings - Fork 139
/
register.go
93 lines (90 loc) · 2.82 KB
/
register.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
82
83
84
85
86
87
88
89
90
91
92
93
package entity
import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/item"
"github.com/df-mc/dragonfly/server/item/enchantment"
"github.com/df-mc/dragonfly/server/item/potion"
"github.com/df-mc/dragonfly/server/world"
"github.com/go-gl/mathgl/mgl64"
"time"
)
// DefaultRegistry is a world.EntityRegistry that registers all default entities
// implemented by Dragonfly.
var DefaultRegistry = conf.New([]world.EntityType{
AreaEffectCloudType{},
ArrowType{},
BottleOfEnchantingType{},
EggType{},
EnderPearlType{},
ExperienceOrbType{},
FallingBlockType{},
FireworkType{},
ItemType{},
LightningType{},
LingeringPotionType{},
SnowballType{},
SplashPotionType{},
TNTType{},
TextType{},
})
var conf = world.EntityRegistryConfig{
Item: func(it any, pos, vel mgl64.Vec3) world.Entity {
i := NewItem(it.(item.Stack), pos)
i.vel = vel
return i
},
FallingBlock: func(bl world.Block, pos mgl64.Vec3) world.Entity {
return NewFallingBlock(bl, pos)
},
TNT: func(pos mgl64.Vec3, fuse time.Duration) world.Entity {
return NewTNT(pos, fuse)
},
BottleOfEnchanting: func(pos, vel mgl64.Vec3, owner world.Entity) world.Entity {
b := NewBottleOfEnchanting(pos, owner)
b.vel = vel
return b
},
Arrow: func(pos, vel mgl64.Vec3, rot cube.Rotation, damage float64, owner world.Entity, critical, disallowPickup, obtainArrowOnPickup bool, punchLevel int, tip any) world.Entity {
a := NewTippedArrowWithDamage(pos, rot, damage, owner, tip.(potion.Potion))
b := a.conf.Behaviour.(*ProjectileBehaviour)
b.conf.KnockBackForceAddend = float64(punchLevel) * (enchantment.Punch{}).KnockBackMultiplier()
b.conf.DisablePickup = disallowPickup
if obtainArrowOnPickup {
b.conf.PickupItem = item.NewStack(item.Arrow{Tip: tip.(potion.Potion)}, 1)
}
b.conf.Critical = critical
a.vel = vel
return a
},
Egg: func(pos, vel mgl64.Vec3, owner world.Entity) world.Entity {
e := NewEgg(pos, owner)
e.vel = vel
return e
},
EnderPearl: func(pos, vel mgl64.Vec3, owner world.Entity) world.Entity {
e := NewEnderPearl(pos, owner)
e.vel = vel
return e
},
Firework: func(pos mgl64.Vec3, rot cube.Rotation, attached bool, firework world.Item, owner world.Entity) world.Entity {
return NewFireworkAttached(pos, rot, firework.(item.Firework), owner, attached)
},
LingeringPotion: func(pos, vel mgl64.Vec3, t any, owner world.Entity) world.Entity {
p := NewLingeringPotion(pos, owner, t.(potion.Potion))
p.vel = vel
return p
},
Snowball: func(pos, vel mgl64.Vec3, owner world.Entity) world.Entity {
s := NewSnowball(pos, owner)
s.vel = vel
return s
},
SplashPotion: func(pos, vel mgl64.Vec3, t any, owner world.Entity) world.Entity {
p := NewSplashPotion(pos, owner, t.(potion.Potion))
p.vel = vel
return p
},
Lightning: func(pos mgl64.Vec3) world.Entity {
return NewLightning(pos)
},
}