-
Notifications
You must be signed in to change notification settings - Fork 141
/
shovel.go
114 lines (98 loc) · 2.82 KB
/
shovel.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
114
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"
)
// Shovel is a tool generally used for mining ground-like blocks, such as sand, gravel and dirt. Additionally,
// shovels may be used to turn grass into dirt paths.
type Shovel struct {
// Tier is the tier of the shovel.
Tier ToolTier
}
// UseOnBlock handles the creation of dirt path blocks from dirt or grass blocks.
func (s Shovel) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, _ User, ctx *UseContext) bool {
if b, ok := w.Block(pos).(shovellable); ok {
if res, ok := b.Shovel(); ok {
if face == cube.FaceDown {
// Dirt paths are not created when the bottom face is clicked.
return false
}
if w.Block(pos.Side(cube.FaceUp)) != air() {
// Dirt paths 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
}
// shovellable represents a block that can be changed by using a shovel on it.
type shovellable interface {
// Shovel returns a block that results from using a shovel on it, or false if it could not be changed using
// a shovel.
Shovel() (world.Block, bool)
}
// MaxCount always returns 1.
func (s Shovel) MaxCount() int {
return 1
}
// AttackDamage returns the attack damage to the shovel.
func (s Shovel) AttackDamage() float64 {
return s.Tier.BaseAttackDamage
}
// ToolType returns the tool type for shovels.
func (s Shovel) ToolType() ToolType {
return TypeShovel
}
// HarvestLevel ...
func (s Shovel) HarvestLevel() int {
return s.Tier.HarvestLevel
}
// BaseMiningEfficiency ...
func (s Shovel) BaseMiningEfficiency(world.Block) float64 {
return s.Tier.BaseMiningEfficiency
}
// EnchantmentValue ...
func (s Shovel) EnchantmentValue() int {
return s.Tier.EnchantmentValue
}
// DurabilityInfo ...
func (s Shovel) DurabilityInfo() DurabilityInfo {
return DurabilityInfo{
MaxDurability: s.Tier.Durability,
BrokenItem: simpleItem(Stack{}),
AttackDurability: 2,
BreakDurability: 1,
}
}
// SmeltInfo ...
func (s Shovel) SmeltInfo() SmeltInfo {
switch s.Tier {
case ToolTierIron:
return newOreSmeltInfo(NewStack(IronNugget{}, 1), 0.1)
case ToolTierGold:
return newOreSmeltInfo(NewStack(GoldNugget{}, 1), 0.1)
}
return SmeltInfo{}
}
// FuelInfo ...
func (s Shovel) FuelInfo() FuelInfo {
if s.Tier == ToolTierWood {
return newFuelInfo(time.Second * 10)
}
return FuelInfo{}
}
// RepairableBy ...
func (s Shovel) RepairableBy(i Stack) bool {
return toolTierRepairable(s.Tier)(i)
}
// EncodeItem ...
func (s Shovel) EncodeItem() (name string, meta int16) {
return "minecraft:" + s.Tier.Name + "_shovel", 0
}