github.com/df-mc/dragonfly@v0.9.13/server/item/axe.go (about) 1 package item 2 3 import ( 4 "github.com/df-mc/dragonfly/server/block/cube" 5 "github.com/df-mc/dragonfly/server/world" 6 "github.com/df-mc/dragonfly/server/world/sound" 7 "github.com/go-gl/mathgl/mgl64" 8 "time" 9 ) 10 11 // Axe is a tool generally used for mining wood-like blocks. It may also be used to break some plant-like 12 // blocks at a faster pace such as pumpkins. 13 type Axe struct { 14 // Tier is the tier of the axe. 15 Tier ToolTier 16 } 17 18 // UseOnBlock handles the stripping of logs when a player clicks a log with an axe. 19 func (a Axe) UseOnBlock(pos cube.Pos, _ cube.Face, _ mgl64.Vec3, w *world.World, _ User, ctx *UseContext) bool { 20 if s, ok := w.Block(pos).(strippable); ok { 21 if res, ok := s.Strip(); ok { 22 w.SetBlock(pos, res, nil) 23 w.PlaySound(pos.Vec3(), sound.ItemUseOn{Block: res}) 24 25 ctx.DamageItem(1) 26 return true 27 } 28 } 29 return false 30 } 31 32 // strippable represents a block that can be stripped. 33 type strippable interface { 34 // Strip returns a block that is the result of stripping it. Alternatively, the bool returned may be false to 35 // indicate the block couldn't be stripped. 36 Strip() (world.Block, bool) 37 } 38 39 // MaxCount always returns 1. 40 func (a Axe) MaxCount() int { 41 return 1 42 } 43 44 // DurabilityInfo ... 45 func (a Axe) DurabilityInfo() DurabilityInfo { 46 return DurabilityInfo{ 47 MaxDurability: a.Tier.Durability, 48 BrokenItem: simpleItem(Stack{}), 49 AttackDurability: 2, 50 BreakDurability: 1, 51 } 52 } 53 54 // SmeltInfo ... 55 func (a Axe) SmeltInfo() SmeltInfo { 56 switch a.Tier { 57 case ToolTierIron: 58 return newOreSmeltInfo(NewStack(IronNugget{}, 1), 0.1) 59 case ToolTierGold: 60 return newOreSmeltInfo(NewStack(GoldNugget{}, 1), 0.1) 61 } 62 return SmeltInfo{} 63 } 64 65 // FuelInfo ... 66 func (a Axe) FuelInfo() FuelInfo { 67 if a.Tier == ToolTierWood { 68 return newFuelInfo(time.Second * 10) 69 } 70 return FuelInfo{} 71 } 72 73 // AttackDamage ... 74 func (a Axe) AttackDamage() float64 { 75 return a.Tier.BaseAttackDamage + 2 76 } 77 78 // ToolType ... 79 func (a Axe) ToolType() ToolType { 80 return TypeAxe 81 } 82 83 // HarvestLevel ... 84 func (a Axe) HarvestLevel() int { 85 return a.Tier.HarvestLevel 86 } 87 88 // BaseMiningEfficiency ... 89 func (a Axe) BaseMiningEfficiency(world.Block) float64 { 90 return a.Tier.BaseMiningEfficiency 91 } 92 93 // RepairableBy ... 94 func (a Axe) RepairableBy(i Stack) bool { 95 return toolTierRepairable(a.Tier)(i) 96 } 97 98 // EnchantmentValue ... 99 func (a Axe) EnchantmentValue() int { 100 return a.Tier.EnchantmentValue 101 } 102 103 // EncodeItem ... 104 func (a Axe) EncodeItem() (name string, meta int16) { 105 return "minecraft:" + a.Tier.Name + "_axe", 0 106 }