-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworld_handlers.go
86 lines (73 loc) · 4.35 KB
/
world_handlers.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
package vhandler
type WorldHandlers struct {
liquidFlowHandlers []*handlerWrapper[WorldHandleLiquidFlowFunc]
liquidDecayHandlers []*handlerWrapper[WorldHandleLiquidDecayFunc]
liquidHardenHandlers []*handlerWrapper[WorldHandleLiquidHardenFunc]
soundHandlers []*handlerWrapper[WorldHandleSoundFunc]
fireSpreadHandlers []*handlerWrapper[WorldHandleFireSpreadFunc]
blockBurnHandlers []*handlerWrapper[WorldHandleBlockBurnFunc]
cropTrampleHandlers []*handlerWrapper[WorldHandleCropTrampleFunc]
leavesDecayHandlers []*handlerWrapper[WorldHandleLeavesDecayFunc]
entitySpawnHandlers []*handlerWrapper[WorldHandleEntitySpawnFunc]
entityDespawnHandlers []*handlerWrapper[WorldHandleEntityDespawnFunc]
closeHandlers []*handlerWrapper[WorldHandleCloseFunc]
}
func NewWorldHandlers() *WorldHandlers {
return &WorldHandlers{
liquidFlowHandlers: make([]*handlerWrapper[WorldHandleLiquidFlowFunc], 0),
liquidDecayHandlers: make([]*handlerWrapper[WorldHandleLiquidDecayFunc], 0),
liquidHardenHandlers: make([]*handlerWrapper[WorldHandleLiquidHardenFunc], 0),
soundHandlers: make([]*handlerWrapper[WorldHandleSoundFunc], 0),
fireSpreadHandlers: make([]*handlerWrapper[WorldHandleFireSpreadFunc], 0),
blockBurnHandlers: make([]*handlerWrapper[WorldHandleBlockBurnFunc], 0),
cropTrampleHandlers: make([]*handlerWrapper[WorldHandleCropTrampleFunc], 0),
leavesDecayHandlers: make([]*handlerWrapper[WorldHandleLeavesDecayFunc], 0),
entitySpawnHandlers: make([]*handlerWrapper[WorldHandleEntitySpawnFunc], 0),
entityDespawnHandlers: make([]*handlerWrapper[WorldHandleEntityDespawnFunc], 0),
closeHandlers: make([]*handlerWrapper[WorldHandleCloseFunc], 0),
}
}
func (h *WorldHandlers) OnLiquidFlow(handler WorldHandleLiquidFlowFunc, priority Priority) {
h.liquidFlowHandlers = append(h.liquidFlowHandlers, &handlerWrapper[WorldHandleLiquidFlowFunc]{priority, handler})
sortHandlers(h.liquidFlowHandlers)
}
func (h *WorldHandlers) OnLiquidDecay(handler WorldHandleLiquidDecayFunc, priority Priority) {
h.liquidDecayHandlers = append(h.liquidDecayHandlers, &handlerWrapper[WorldHandleLiquidDecayFunc]{priority, handler})
sortHandlers(h.liquidDecayHandlers)
}
func (h *WorldHandlers) OnLiquidHarden(handler WorldHandleLiquidHardenFunc, priority Priority) {
h.liquidHardenHandlers = append(h.liquidHardenHandlers, &handlerWrapper[WorldHandleLiquidHardenFunc]{priority, handler})
sortHandlers(h.liquidHardenHandlers)
}
func (h *WorldHandlers) OnSound(handler WorldHandleSoundFunc, priority Priority) {
h.soundHandlers = append(h.soundHandlers, &handlerWrapper[WorldHandleSoundFunc]{priority, handler})
sortHandlers(h.soundHandlers)
}
func (h *WorldHandlers) OnFireSpread(handler WorldHandleFireSpreadFunc, priority Priority) {
h.fireSpreadHandlers = append(h.fireSpreadHandlers, &handlerWrapper[WorldHandleFireSpreadFunc]{priority, handler})
sortHandlers(h.fireSpreadHandlers)
}
func (h *WorldHandlers) OnBlockBurn(handler WorldHandleBlockBurnFunc, priority Priority) {
h.blockBurnHandlers = append(h.blockBurnHandlers, &handlerWrapper[WorldHandleBlockBurnFunc]{priority, handler})
sortHandlers(h.blockBurnHandlers)
}
func (h *WorldHandlers) OnCropTrample(handler WorldHandleCropTrampleFunc, priority Priority) {
h.cropTrampleHandlers = append(h.cropTrampleHandlers, &handlerWrapper[WorldHandleCropTrampleFunc]{priority, handler})
sortHandlers(h.cropTrampleHandlers)
}
func (h *WorldHandlers) OnLeavesDecay(handler WorldHandleLeavesDecayFunc, priority Priority) {
h.leavesDecayHandlers = append(h.leavesDecayHandlers, &handlerWrapper[WorldHandleLeavesDecayFunc]{priority, handler})
sortHandlers(h.leavesDecayHandlers)
}
func (h *WorldHandlers) OnEntitySpawn(handler WorldHandleEntitySpawnFunc, priority Priority) {
h.entitySpawnHandlers = append(h.entitySpawnHandlers, &handlerWrapper[WorldHandleEntitySpawnFunc]{priority, handler})
sortHandlers(h.entitySpawnHandlers)
}
func (h *WorldHandlers) OnEntityDespawn(handler WorldHandleEntityDespawnFunc, priority Priority) {
h.entityDespawnHandlers = append(h.entityDespawnHandlers, &handlerWrapper[WorldHandleEntityDespawnFunc]{priority, handler})
sortHandlers(h.entityDespawnHandlers)
}
func (h *WorldHandlers) OnClose(handler WorldHandleCloseFunc, priority Priority) {
h.closeHandlers = append(h.closeHandlers, &handlerWrapper[WorldHandleCloseFunc]{priority, handler})
sortHandlers(h.closeHandlers)
}