-
Notifications
You must be signed in to change notification settings - Fork 143
/
axe.go
106 lines (90 loc) · 2.45 KB
/
axe.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
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"
)
// Axe is a tool generally used for mining wood-like blocks. It may also be used to break some plant-like
// blocks at a faster pace such as pumpkins.
type Axe struct {
// Tier is the tier of the axe.
Tier ToolTier
}
// UseOnBlock handles the stripping of logs when a player clicks a log with an axe.
func (a Axe) UseOnBlock(pos cube.Pos, _ cube.Face, _ mgl64.Vec3, w *world.World, _ User, ctx *UseContext) bool {
if s, ok := w.Block(pos).(strippable); ok {
if res, ok := s.Strip(); ok {
w.SetBlock(pos, res, nil)
w.PlaySound(pos.Vec3(), sound.ItemUseOn{Block: res})
ctx.DamageItem(1)
return true
}
}
return false
}
// strippable represents a block that can be stripped.
type strippable interface {
// Strip returns a block that is the result of stripping it. Alternatively, the bool returned may be false to
// indicate the block couldn't be stripped.
Strip() (world.Block, bool)
}
// MaxCount always returns 1.
func (a Axe) MaxCount() int {
return 1
}
// DurabilityInfo ...
func (a Axe) DurabilityInfo() DurabilityInfo {
return DurabilityInfo{
MaxDurability: a.Tier.Durability,
BrokenItem: simpleItem(Stack{}),
AttackDurability: 2,
BreakDurability: 1,
}
}
// SmeltInfo ...
func (a Axe) SmeltInfo() SmeltInfo {
switch a.Tier {
case ToolTierIron:
return newOreSmeltInfo(NewStack(IronNugget{}, 1), 0.1)
case ToolTierGold:
return newOreSmeltInfo(NewStack(GoldNugget{}, 1), 0.1)
}
return SmeltInfo{}
}
// FuelInfo ...
func (a Axe) FuelInfo() FuelInfo {
if a.Tier == ToolTierWood {
return newFuelInfo(time.Second * 10)
}
return FuelInfo{}
}
// AttackDamage ...
func (a Axe) AttackDamage() float64 {
return a.Tier.BaseAttackDamage + 2
}
// ToolType ...
func (a Axe) ToolType() ToolType {
return TypeAxe
}
// HarvestLevel ...
func (a Axe) HarvestLevel() int {
return a.Tier.HarvestLevel
}
// BaseMiningEfficiency ...
func (a Axe) BaseMiningEfficiency(world.Block) float64 {
return a.Tier.BaseMiningEfficiency
}
// RepairableBy ...
func (a Axe) RepairableBy(i Stack) bool {
return toolTierRepairable(a.Tier)(i)
}
// EnchantmentValue ...
func (a Axe) EnchantmentValue() int {
return a.Tier.EnchantmentValue
}
// EncodeItem ...
func (a Axe) EncodeItem() (name string, meta int16) {
return "minecraft:" + a.Tier.Name + "_axe", 0
}