-
Notifications
You must be signed in to change notification settings - Fork 150
/
helmet.go
66 lines (56 loc) · 1.52 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
package item
import (
"github.com/df-mc/dragonfly/server/item/armour"
"github.com/df-mc/dragonfly/server/world"
)
// 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 armour.Tier
}
// Use handles the using of a helmet to auto-equip it in an armour slot.
func (h Helmet) Use(_ *world.World, user User, _ *UseContext) bool {
if armoured, ok := user.(Armoured); ok {
currentEquipped := armoured.Armour().Helmet()
right, left := user.HeldItems()
armoured.Armour().SetHelmet(right)
user.SetHeldItems(currentEquipped, left)
}
return false
}
// MaxCount always returns 1.
func (h Helmet) MaxCount() int {
return 1
}
// DefencePoints ...
func (h Helmet) DefencePoints() float64 {
switch h.Tier {
case armour.TierLeather:
return 1
case armour.TierGold, armour.TierChain, armour.TierIron:
return 2
case armour.TierDiamond, armour.TierNetherite:
return 3
}
panic("invalid helmet tier")
}
// KnockBackResistance ...
func (h Helmet) KnockBackResistance() float64 {
return h.Tier.KnockBackResistance
}
// DurabilityInfo ...
func (h Helmet) DurabilityInfo() DurabilityInfo {
return DurabilityInfo{
MaxDurability: int(h.Tier.BaseDurability),
BrokenItem: simpleItem(Stack{}),
}
}
// Helmet ...
func (h Helmet) Helmet() bool {
return true
}
// EncodeItem ...
func (h Helmet) EncodeItem() (name string, meta int16) {
return "minecraft:" + h.Tier.Name + "_helmet", 0
}