github.com/df-mc/dragonfly@v0.9.13/server/item/sword.go (about) 1 package item 2 3 import ( 4 "github.com/df-mc/dragonfly/server/world" 5 "time" 6 ) 7 8 // Sword is a tool generally used to attack enemies. In addition, it may be used to mine any block slightly 9 // faster than without tool and to break cobwebs rapidly. 10 type Sword struct { 11 // Tier is the tier of the sword. 12 Tier ToolTier 13 } 14 15 // AttackDamage returns the attack damage to the sword. 16 func (s Sword) AttackDamage() float64 { 17 return s.Tier.BaseAttackDamage + 3 18 } 19 20 // MaxCount always returns 1. 21 func (s Sword) MaxCount() int { 22 return 1 23 } 24 25 // ToolType returns the tool type for swords. 26 func (s Sword) ToolType() ToolType { 27 return TypeSword 28 } 29 30 // HarvestLevel returns the harvest level of the sword tier. 31 func (s Sword) HarvestLevel() int { 32 return s.Tier.HarvestLevel 33 } 34 35 // EnchantmentValue ... 36 func (s Sword) EnchantmentValue() int { 37 return s.Tier.EnchantmentValue 38 } 39 40 // BaseMiningEfficiency always returns 1.5, unless the block passed is cobweb, in which case 15 is returned. 41 func (s Sword) BaseMiningEfficiency(world.Block) float64 { 42 // TODO: Implement cobwebs and return 15 here. 43 return 1.5 44 } 45 46 // DurabilityInfo ... 47 func (s Sword) DurabilityInfo() DurabilityInfo { 48 return DurabilityInfo{ 49 MaxDurability: s.Tier.Durability, 50 BrokenItem: simpleItem(Stack{}), 51 AttackDurability: 1, 52 BreakDurability: 2, 53 } 54 } 55 56 // SmeltInfo ... 57 func (s Sword) SmeltInfo() SmeltInfo { 58 switch s.Tier { 59 case ToolTierIron: 60 return newOreSmeltInfo(NewStack(IronNugget{}, 1), 0.1) 61 case ToolTierGold: 62 return newOreSmeltInfo(NewStack(GoldNugget{}, 1), 0.1) 63 } 64 return SmeltInfo{} 65 } 66 67 // FuelInfo ... 68 func (s Sword) FuelInfo() FuelInfo { 69 if s.Tier == ToolTierWood { 70 return newFuelInfo(time.Second * 10) 71 } 72 return FuelInfo{} 73 } 74 75 // RepairableBy ... 76 func (s Sword) RepairableBy(i Stack) bool { 77 return toolTierRepairable(s.Tier)(i) 78 } 79 80 // EncodeItem ... 81 func (s Sword) EncodeItem() (name string, meta int16) { 82 return "minecraft:" + s.Tier.Name + "_sword", 0 83 }