-
Notifications
You must be signed in to change notification settings - Fork 150
/
helmet.go
89 lines (76 loc) · 1.94 KB
/
helmet.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
package item
import (
"github.com/df-mc/dragonfly/server/world"
"image/color"
)
// Helmet is a defensive item that may be worn in the head slot. It comes in several tiers, each with
// different defence points and armour toughness.
type Helmet struct {
// Tier is the tier of the armour.
Tier ArmourTier
}
// Use handles the using of a helmet to auto-equip it in an armour slot.
func (h Helmet) Use(_ *world.World, _ User, ctx *UseContext) bool {
ctx.SwapHeldWithArmour(0)
return false
}
// MaxCount always returns 1.
func (h Helmet) MaxCount() int {
return 1
}
// DefencePoints ...
func (h Helmet) DefencePoints() float64 {
switch h.Tier.(type) {
case ArmourTierLeather:
return 1
case ArmourTierGold, ArmourTierChain, ArmourTierIron:
return 2
case ArmourTierDiamond, ArmourTierNetherite:
return 3
}
panic("invalid helmet tier")
}
// KnockBackResistance ...
func (h Helmet) KnockBackResistance() float64 {
return h.Tier.KnockBackResistance()
}
// Toughness ...
func (h Helmet) Toughness() float64 {
return h.Tier.Toughness()
}
// DurabilityInfo ...
func (h Helmet) DurabilityInfo() DurabilityInfo {
return DurabilityInfo{
MaxDurability: int(h.Tier.BaseDurability()),
BrokenItem: simpleItem(Stack{}),
}
}
// RepairableBy ...
func (h Helmet) RepairableBy(i Stack) bool {
return armourTierRepairable(h.Tier)(i)
}
// Helmet ...
func (h Helmet) Helmet() bool {
return true
}
// EncodeItem ...
func (h Helmet) EncodeItem() (name string, meta int16) {
return "minecraft:" + h.Tier.Name() + "_helmet", 0
}
// DecodeNBT ...
func (h Helmet) DecodeNBT(data map[string]any) any {
if t, ok := h.Tier.(ArmourTierLeather); ok {
if v, ok := data["customColor"].(int32); ok {
t.Colour = rgbaFromInt32(v)
h.Tier = t
}
}
return h
}
// EncodeNBT ...
func (h Helmet) EncodeNBT() map[string]any {
if t, ok := h.Tier.(ArmourTierLeather); ok && t.Colour != (color.RGBA{}) {
return map[string]any{"customColor": int32FromRGBA(t.Colour)}
}
return nil
}