forked from df-mc/dragonfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
area_effect_cloud.go
79 lines (71 loc) · 2.86 KB
/
area_effect_cloud.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
package entity
import (
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/block/cube"
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/entity/effect"
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/internal/nbtconv"
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/item/potion"
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/world"
"github.com/go-gl/mathgl/mgl64"
"time"
)
// NewAreaEffectCloud creates a new area effect cloud entity and returns it.
func NewAreaEffectCloud(pos mgl64.Vec3, p potion.Potion) *Ent {
config := areaEffectCloudConf
for _, e := range p.Effects() {
if _, ok := e.Type().(effect.LastingType); !ok {
config.ReapplicationDelay = 0
break
}
}
return Config{Behaviour: config.New(p)}.New(AreaEffectCloudType{}, pos)
}
var areaEffectCloudConf = AreaEffectCloudBehaviourConfig{
RadiusUseGrowth: -0.5,
RadiusTickGrowth: -0.005,
ReapplicationDelay: time.Second * 2,
}
// NewAreaEffectCloudWith ...
func NewAreaEffectCloudWith(pos mgl64.Vec3, t potion.Potion, duration, reapplicationDelay, durationOnUse time.Duration, radius, radiusOnUse, radiusGrowth float64) *Ent {
config := AreaEffectCloudBehaviourConfig{
Radius: radius,
RadiusUseGrowth: radiusOnUse,
RadiusTickGrowth: radiusGrowth,
Duration: duration,
DurationUseGrowth: durationOnUse,
ReapplicationDelay: reapplicationDelay,
}
return Config{Behaviour: config.New(t)}.New(AreaEffectCloudType{}, pos)
}
// AreaEffectCloudType is a world.EntityType implementation for AreaEffectCloud.
type AreaEffectCloudType struct{}
func (AreaEffectCloudType) EncodeEntity() string { return "minecraft:area_effect_cloud" }
func (AreaEffectCloudType) BBox(e world.Entity) cube.BBox {
r := e.(*Ent).Behaviour().(*AreaEffectCloudBehaviour).Radius()
return cube.Box(-r, 0, -r, r, 0.5, r)
}
func (AreaEffectCloudType) DecodeNBT(m map[string]any) world.Entity {
return NewAreaEffectCloudWith(
nbtconv.Vec3(m, "Pos"),
potion.From(nbtconv.Int32(m, "PotionId")),
nbtconv.TickDuration[int32](m, "Duration"),
nbtconv.TickDuration[int32](m, "ReapplicationDelay"),
nbtconv.TickDuration[int32](m, "DurationOnUse"),
float64(nbtconv.Float32(m, "Radius")),
float64(nbtconv.Float32(m, "RadiusOnUse")),
float64(nbtconv.Float32(m, "RadiusPerTick")),
)
}
func (AreaEffectCloudType) EncodeNBT(e world.Entity) map[string]any {
ent := e.(*Ent)
a := ent.Behaviour().(*AreaEffectCloudBehaviour)
return map[string]any{
"Pos": nbtconv.Vec3ToFloat32Slice(ent.Position()),
"ReapplicationDelay": int32(a.conf.ReapplicationDelay),
"RadiusPerTick": float32(a.conf.RadiusTickGrowth),
"RadiusOnUse": float32(a.conf.RadiusUseGrowth),
"DurationOnUse": int32(a.conf.DurationUseGrowth),
"Radius": float32(a.radius),
"Duration": int32(a.duration),
"PotionId": int32(a.t.Uint8()),
}
}