github.com/df-mc/dragonfly@v0.9.13/server/item/chestplate.go (about) 1 package item 2 3 import ( 4 "github.com/df-mc/dragonfly/server/world" 5 "image/color" 6 ) 7 8 // Chestplate is a defensive item that may be equipped in the chestplate slot. Generally, chestplates provide 9 // the most defence of all armour items. 10 type Chestplate struct { 11 // Tier is the tier of the chestplate. 12 Tier ArmourTier 13 } 14 15 // Use handles the using of a chestplate to auto-equip it in the designated armour slot. 16 func (c Chestplate) Use(_ *world.World, _ User, ctx *UseContext) bool { 17 ctx.SwapHeldWithArmour(1) 18 return false 19 } 20 21 // MaxCount always returns 1. 22 func (c Chestplate) MaxCount() int { 23 return 1 24 } 25 26 // DefencePoints ... 27 func (c Chestplate) DefencePoints() float64 { 28 switch c.Tier.Name() { 29 case "leather": 30 return 3 31 case "golden", "chainmail": 32 return 5 33 case "iron": 34 return 6 35 case "diamond", "netherite": 36 return 8 37 } 38 panic("invalid chestplate tier") 39 } 40 41 // Toughness ... 42 func (c Chestplate) Toughness() float64 { 43 return c.Tier.Toughness() 44 } 45 46 // KnockBackResistance ... 47 func (c Chestplate) KnockBackResistance() float64 { 48 return c.Tier.KnockBackResistance() 49 } 50 51 // EnchantmentValue ... 52 func (c Chestplate) EnchantmentValue() int { 53 return c.Tier.EnchantmentValue() 54 } 55 56 // DurabilityInfo ... 57 func (c Chestplate) DurabilityInfo() DurabilityInfo { 58 return DurabilityInfo{ 59 MaxDurability: int(c.Tier.BaseDurability() + c.Tier.BaseDurability()/2.2), 60 BrokenItem: simpleItem(Stack{}), 61 } 62 } 63 64 // SmeltInfo ... 65 func (c Chestplate) SmeltInfo() SmeltInfo { 66 switch c.Tier.(type) { 67 case ArmourTierIron, ArmourTierChain: 68 return newOreSmeltInfo(NewStack(IronNugget{}, 1), 0.1) 69 case ArmourTierGold: 70 return newOreSmeltInfo(NewStack(GoldNugget{}, 1), 0.1) 71 } 72 return SmeltInfo{} 73 } 74 75 // RepairableBy ... 76 func (c Chestplate) RepairableBy(i Stack) bool { 77 return armourTierRepairable(c.Tier)(i) 78 } 79 80 // Chestplate ... 81 func (c Chestplate) Chestplate() bool { 82 return true 83 } 84 85 // EncodeItem ... 86 func (c Chestplate) EncodeItem() (name string, meta int16) { 87 return "minecraft:" + c.Tier.Name() + "_chestplate", 0 88 } 89 90 // DecodeNBT ... 91 func (c Chestplate) DecodeNBT(data map[string]any) any { 92 if t, ok := c.Tier.(ArmourTierLeather); ok { 93 if v, ok := data["customColor"].(int32); ok { 94 t.Colour = rgbaFromInt32(v) 95 c.Tier = t 96 } 97 } 98 return c 99 } 100 101 // EncodeNBT ... 102 func (c Chestplate) EncodeNBT() map[string]any { 103 if t, ok := c.Tier.(ArmourTierLeather); ok && t.Colour != (color.RGBA{}) { 104 return map[string]any{"customColor": int32FromRGBA(t.Colour)} 105 } 106 return nil 107 }