-
Notifications
You must be signed in to change notification settings - Fork 141
/
tool.go
86 lines (77 loc) · 3.83 KB
/
tool.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
package item
import "github.com/df-mc/dragonfly/server/world"
var (
// TypeNone is the ToolType of items that are not tools.
TypeNone = ToolType{-1}
// TypePickaxe is the ToolType for pickaxes.
TypePickaxe = ToolType{0}
// TypeAxe is the ToolType for axes.
TypeAxe = ToolType{1}
// TypeHoe is the ToolType for hoes.
TypeHoe = ToolType{2}
// TypeShovel is the ToolType for shovels.
TypeShovel = ToolType{3}
// TypeShears is the ToolType for shears.
TypeShears = ToolType{4}
// TypeSword is the ToolType for swords.
TypeSword = ToolType{5}
// ToolTierWood is the ToolTier of wood tools. This is the lowest possible tier.
ToolTierWood = ToolTier{HarvestLevel: 1, Durability: 59, BaseMiningEfficiency: 2, BaseAttackDamage: 1, Name: "wooden"}
// ToolTierGold is the ToolTier of gold tools.
ToolTierGold = ToolTier{HarvestLevel: 1, Durability: 32, BaseMiningEfficiency: 12, BaseAttackDamage: 1, Name: "golden"}
// ToolTierStone is the ToolTier of stone tools.
ToolTierStone = ToolTier{HarvestLevel: 2, Durability: 131, BaseMiningEfficiency: 4, BaseAttackDamage: 2, Name: "stone"}
// ToolTierIron is the ToolTier of iron tools.
ToolTierIron = ToolTier{HarvestLevel: 3, Durability: 250, BaseMiningEfficiency: 6, BaseAttackDamage: 3, Name: "iron"}
// ToolTierDiamond is the ToolTier of diamond tools.
ToolTierDiamond = ToolTier{HarvestLevel: 4, Durability: 1561, BaseMiningEfficiency: 8, BaseAttackDamage: 4, Name: "diamond"}
// ToolTierNetherite is the ToolTier of netherite tools. This is the highest possible tier.
ToolTierNetherite = ToolTier{HarvestLevel: 4, Durability: 2031, BaseMiningEfficiency: 9, BaseAttackDamage: 5, Name: "netherite"}
)
type (
// Tool represents an item that may be used as a tool.
Tool interface {
// ToolType returns the type of the tool. The blocks that can be mined with this tool depend on this
// tool type.
ToolType() ToolType
// HarvestLevel returns the level that this tool is able to harvest. If a block has a harvest level above
// this one, this tool won't be able to harvest it.
HarvestLevel() int
// BaseMiningEfficiency is the base efficiency of the tool, when it comes to mining blocks. This decides
// the speed with which blocks can be mined.
// Some tools have a mining efficiency that depends on the block (swords, shears). The block mined is
// passed for this behaviour.
BaseMiningEfficiency(b world.Block) float64
}
// ToolTier represents the tier, or material, that a Tool is made of.
ToolTier struct {
// HarvestLevel is the level that this tier of tools is able to harvest. If a block has a harvest level
// above this one, a tool with this tier won't be able to harvest it.
HarvestLevel int
// BaseMiningEfficiency is the base efficiency of the tier, when it comes to mining blocks. This is
// specifically used for tools such as pickaxes.
BaseMiningEfficiency float64
// BaseAttackDamage is the base attack damage to tools with this tier. All tools have a constant value
// that is added on top of this.
BaseAttackDamage float64
// BaseDurability returns the maximum durability that a tool with this tier has.
Durability int
// Name is the name of the tier.
Name string
}
// ToolType represents the type of tool. This decides the type of blocks that the tool is used for.
ToolType struct{ t }
t int
// ToolNone is a ToolType typically used in functions for items that do not function as tools.
ToolNone struct{}
)
// ToolTiers returns a ToolTier slice containing all available tiers.
func ToolTiers() []ToolTier {
return []ToolTier{ToolTierWood, ToolTierGold, ToolTierStone, ToolTierIron, ToolTierDiamond, ToolTierNetherite}
}
// ToolType ...
func (n ToolNone) ToolType() ToolType { return TypeNone }
// HarvestLevel ...
func (n ToolNone) HarvestLevel() int { return 0 }
// BaseMiningEfficiency ...
func (n ToolNone) BaseMiningEfficiency(world.Block) float64 { return 1 }