-
Notifications
You must be signed in to change notification settings - Fork 141
/
hoe.go
113 lines (98 loc) · 2.84 KB
/
hoe.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
108
109
110
111
112
113
package item
import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/world"
"github.com/df-mc/dragonfly/server/world/sound"
"github.com/go-gl/mathgl/mgl64"
"time"
)
// Hoe is a tool generally used to till dirt and grass blocks into farmland blocks for planting crops.
// Additionally, a Hoe can be used to break certain types of blocks such as Crimson and Hay Blocks.
type Hoe struct {
Tier ToolTier
}
// UseOnBlock will turn a dirt or grass block into a farmland if the necessary properties are met.
func (h Hoe) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, _ User, ctx *UseContext) bool {
if b, ok := w.Block(pos).(tillable); ok {
if res, ok := b.Till(); ok {
if face == cube.FaceDown {
// Tilled land isn't created when the bottom face is clicked.
return false
}
if w.Block(pos.Side(cube.FaceUp)) != air() {
// Tilled land can only be created if air is above the grass block.
return false
}
w.SetBlock(pos, res, nil)
w.PlaySound(pos.Vec3(), sound.ItemUseOn{Block: res})
ctx.DamageItem(1)
return true
}
}
return false
}
// tillable represents a block that can be tilled by using a hoe on it.
type tillable interface {
// Till returns a block that results from tilling it. If tilling it does not have a result, the bool returned
// is false.
Till() (world.Block, bool)
}
// MaxCount ...
func (h Hoe) MaxCount() int {
return 1
}
// AttackDamage ...
func (h Hoe) AttackDamage() float64 {
return h.Tier.BaseAttackDamage + 1
}
// ToolType ...
func (h Hoe) ToolType() ToolType {
return TypeHoe
}
// HarvestLevel returns the level that this hoe is able to harvest. If a block has a harvest level above
// this one, this hoe won't be able to harvest it.
func (h Hoe) HarvestLevel() int {
return h.Tier.HarvestLevel
}
// BaseMiningEfficiency ...
func (h Hoe) BaseMiningEfficiency(world.Block) float64 {
return h.Tier.BaseMiningEfficiency
}
// EnchantmentValue ...
func (h Hoe) EnchantmentValue() int {
return h.Tier.EnchantmentValue
}
// DurabilityInfo ...
func (h Hoe) DurabilityInfo() DurabilityInfo {
return DurabilityInfo{
MaxDurability: h.Tier.Durability,
BrokenItem: simpleItem(Stack{}),
AttackDurability: 2,
BreakDurability: 1,
}
}
// SmeltInfo ...
func (h Hoe) SmeltInfo() SmeltInfo {
switch h.Tier {
case ToolTierIron:
return newOreSmeltInfo(NewStack(IronNugget{}, 1), 0.1)
case ToolTierGold:
return newOreSmeltInfo(NewStack(GoldNugget{}, 1), 0.1)
}
return SmeltInfo{}
}
// FuelInfo ...
func (h Hoe) FuelInfo() FuelInfo {
if h.Tier == ToolTierWood {
return newFuelInfo(time.Second * 10)
}
return FuelInfo{}
}
// RepairableBy ...
func (h Hoe) RepairableBy(i Stack) bool {
return toolTierRepairable(h.Tier)(i)
}
// EncodeItem ...
func (h Hoe) EncodeItem() (name string, meta int16) {
return "minecraft:" + h.Tier.Name + "_hoe", 0
}