github.com/df-mc/dragonfly@v0.9.13/server/item/hoe.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 // Hoe is a tool generally used to till dirt and grass blocks into farmland blocks for planting crops. 12 // Additionally, a Hoe can be used to break certain types of blocks such as Crimson and Hay Blocks. 13 type Hoe struct { 14 Tier ToolTier 15 } 16 17 // UseOnBlock will turn a dirt or grass block into a farmland if the necessary properties are met. 18 func (h Hoe) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, _ User, ctx *UseContext) bool { 19 if b, ok := w.Block(pos).(tillable); ok { 20 if res, ok := b.Till(); ok { 21 if face == cube.FaceDown { 22 // Tilled land isn't created when the bottom face is clicked. 23 return false 24 } 25 if w.Block(pos.Side(cube.FaceUp)) != air() { 26 // Tilled land can only be created if air is above the grass block. 27 return false 28 } 29 w.SetBlock(pos, res, nil) 30 w.PlaySound(pos.Vec3(), sound.ItemUseOn{Block: res}) 31 ctx.DamageItem(1) 32 return true 33 } 34 } 35 return false 36 } 37 38 // tillable represents a block that can be tilled by using a hoe on it. 39 type tillable interface { 40 // Till returns a block that results from tilling it. If tilling it does not have a result, the bool returned 41 // is false. 42 Till() (world.Block, bool) 43 } 44 45 // MaxCount ... 46 func (h Hoe) MaxCount() int { 47 return 1 48 } 49 50 // AttackDamage ... 51 func (h Hoe) AttackDamage() float64 { 52 return h.Tier.BaseAttackDamage + 1 53 } 54 55 // ToolType ... 56 func (h Hoe) ToolType() ToolType { 57 return TypeHoe 58 } 59 60 // HarvestLevel returns the level that this hoe is able to harvest. If a block has a harvest level above 61 // this one, this hoe won't be able to harvest it. 62 func (h Hoe) HarvestLevel() int { 63 return h.Tier.HarvestLevel 64 } 65 66 // BaseMiningEfficiency ... 67 func (h Hoe) BaseMiningEfficiency(world.Block) float64 { 68 return h.Tier.BaseMiningEfficiency 69 } 70 71 // EnchantmentValue ... 72 func (h Hoe) EnchantmentValue() int { 73 return h.Tier.EnchantmentValue 74 } 75 76 // DurabilityInfo ... 77 func (h Hoe) DurabilityInfo() DurabilityInfo { 78 return DurabilityInfo{ 79 MaxDurability: h.Tier.Durability, 80 BrokenItem: simpleItem(Stack{}), 81 AttackDurability: 2, 82 BreakDurability: 1, 83 } 84 } 85 86 // SmeltInfo ... 87 func (h Hoe) SmeltInfo() SmeltInfo { 88 switch h.Tier { 89 case ToolTierIron: 90 return newOreSmeltInfo(NewStack(IronNugget{}, 1), 0.1) 91 case ToolTierGold: 92 return newOreSmeltInfo(NewStack(GoldNugget{}, 1), 0.1) 93 } 94 return SmeltInfo{} 95 } 96 97 // FuelInfo ... 98 func (h Hoe) FuelInfo() FuelInfo { 99 if h.Tier == ToolTierWood { 100 return newFuelInfo(time.Second * 10) 101 } 102 return FuelInfo{} 103 } 104 105 // RepairableBy ... 106 func (h Hoe) RepairableBy(i Stack) bool { 107 return toolTierRepairable(h.Tier)(i) 108 } 109 110 // EncodeItem ... 111 func (h Hoe) EncodeItem() (name string, meta int16) { 112 return "minecraft:" + h.Tier.Name + "_hoe", 0 113 }