-
Notifications
You must be signed in to change notification settings - Fork 141
/
chestplate.go
107 lines (92 loc) · 2.41 KB
/
chestplate.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package item
import (
"github.com/df-mc/dragonfly/server/world"
"image/color"
)
// Chestplate is a defensive item that may be equipped in the chestplate slot. Generally, chestplates provide
// the most defence of all armour items.
type Chestplate struct {
// Tier is the tier of the chestplate.
Tier ArmourTier
}
// Use handles the using of a chestplate to auto-equip it in the designated armour slot.
func (c Chestplate) Use(_ *world.World, _ User, ctx *UseContext) bool {
ctx.SwapHeldWithArmour(1)
return false
}
// MaxCount always returns 1.
func (c Chestplate) MaxCount() int {
return 1
}
// DefencePoints ...
func (c Chestplate) DefencePoints() float64 {
switch c.Tier.Name() {
case "leather":
return 3
case "golden", "chainmail":
return 5
case "iron":
return 6
case "diamond", "netherite":
return 8
}
panic("invalid chestplate tier")
}
// Toughness ...
func (c Chestplate) Toughness() float64 {
return c.Tier.Toughness()
}
// KnockBackResistance ...
func (c Chestplate) KnockBackResistance() float64 {
return c.Tier.KnockBackResistance()
}
// EnchantmentValue ...
func (c Chestplate) EnchantmentValue() int {
return c.Tier.EnchantmentValue()
}
// DurabilityInfo ...
func (c Chestplate) DurabilityInfo() DurabilityInfo {
return DurabilityInfo{
MaxDurability: int(c.Tier.BaseDurability() + c.Tier.BaseDurability()/2.2),
BrokenItem: simpleItem(Stack{}),
}
}
// SmeltInfo ...
func (c Chestplate) SmeltInfo() SmeltInfo {
switch c.Tier.(type) {
case ArmourTierIron, ArmourTierChain:
return newOreSmeltInfo(NewStack(IronNugget{}, 1), 0.1)
case ArmourTierGold:
return newOreSmeltInfo(NewStack(GoldNugget{}, 1), 0.1)
}
return SmeltInfo{}
}
// RepairableBy ...
func (c Chestplate) RepairableBy(i Stack) bool {
return armourTierRepairable(c.Tier)(i)
}
// Chestplate ...
func (c Chestplate) Chestplate() bool {
return true
}
// EncodeItem ...
func (c Chestplate) EncodeItem() (name string, meta int16) {
return "minecraft:" + c.Tier.Name() + "_chestplate", 0
}
// DecodeNBT ...
func (c Chestplate) DecodeNBT(data map[string]any) any {
if t, ok := c.Tier.(ArmourTierLeather); ok {
if v, ok := data["customColor"].(int32); ok {
t.Colour = rgbaFromInt32(v)
c.Tier = t
}
}
return c
}
// EncodeNBT ...
func (c Chestplate) EncodeNBT() map[string]any {
if t, ok := c.Tier.(ArmourTierLeather); ok && t.Colour != (color.RGBA{}) {
return map[string]any{"customColor": int32FromRGBA(t.Colour)}
}
return nil
}