-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool_system.go
More file actions
126 lines (109 loc) · 3.07 KB
/
tool_system.go
File metadata and controls
126 lines (109 loc) · 3.07 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
package main
type ToolType int
const (
ToolNone ToolType = iota
ToolPickaxe
ToolShovel
ToolAxe
)
type ToolMaterial int
const (
MatNone ToolMaterial = iota
MatWood
MatStone
MatIron
MatDiamond
MatGold
)
// ToolDef defines a tool's properties
type ToolDef struct {
Type ToolType
Material ToolMaterial
}
var ToolRegistry = map[byte]ToolDef{
itemWoodPickaxe: {ToolPickaxe, MatWood},
itemStonePickaxe: {ToolPickaxe, MatStone},
itemIronPickaxe: {ToolPickaxe, MatIron},
itemDiamondPickaxe: {ToolPickaxe, MatDiamond},
itemGoldPickaxe: {ToolPickaxe, MatGold},
itemWoodShovel: {ToolShovel, MatWood},
itemStoneShovel: {ToolShovel, MatStone},
itemIronShovel: {ToolShovel, MatIron},
itemDiamondShovel: {ToolShovel, MatDiamond},
itemGoldShovel: {ToolShovel, MatGold},
itemWoodAxe: {ToolAxe, MatWood},
itemStoneAxe: {ToolAxe, MatStone},
itemIronAxe: {ToolAxe, MatIron},
itemDiamondAxe: {ToolAxe, MatDiamond},
itemGoldAxe: {ToolAxe, MatGold},
}
// BlockToolReq maps blocks to their best tool
var BlockToolReq = map[byte]ToolType{
blockStone: ToolPickaxe,
blockCobblestone: ToolPickaxe,
blockCoalOre: ToolPickaxe,
blockIronOre: ToolPickaxe,
blockGoldOre: ToolPickaxe,
blockDiamondOre: ToolPickaxe,
blockLapisOre: ToolPickaxe,
blockIronBlock: ToolPickaxe,
blockGoldBlock: ToolPickaxe,
blockDiamondBlock: ToolPickaxe,
blockObsidian: ToolPickaxe,
blockSandstone: ToolPickaxe,
blockIce: ToolPickaxe, // Actually pickaxe breaks ice fast but doesn't drop it without Silk Touch
blockDirt: ToolShovel,
blockGrass: ToolShovel,
blockSand: ToolShovel,
blockGravel: ToolShovel,
blockSnow: ToolShovel,
blockLog: ToolAxe,
blockLogBirch: ToolAxe,
blockLogSpruce: ToolAxe,
blockPlank: ToolAxe,
blockPlankOak: ToolAxe,
blockPlankBirch: ToolAxe,
blockPlankSpruce: ToolAxe,
}
// GetMiningSpeedMultiplier calculates the mining speed based on tool and block properties
func GetMiningSpeedMultiplier(toolID byte, blockID byte) float32 {
if toolID == 0 {
return 1.0
}
toolDef, ok := ToolRegistry[toolID]
if !ok {
return 1.0
}
blockDef := GetBlock(blockID)
// If effective tool matches, use tool material speed
if blockDef.EffectiveTool != ToolNone && blockDef.EffectiveTool == toolDef.Type {
switch toolDef.Material {
case MatWood:
return 2.0
case MatStone:
return 4.0
case MatIron:
return 6.0
case MatDiamond:
return 8.0
case MatGold:
return 12.0
}
}
return 1.0
}
// CanHarvest returns true if the tool can harvest the block (drop item)
// In MC this is separate from speed (e.g. Glass breaks fast by hand but drops nothing)
// But for "Effective Tool" check (1.5x vs 5x factor), we usually check if it's the "Correct Tool".
func IsCorrectTool(toolID byte, blockID byte) bool {
blockDef := GetBlock(blockID)
// If no tool required/effective, then Hand is "correct" (factor 1.5)
if blockDef.EffectiveTool == ToolNone {
return true
}
toolDef, ok := ToolRegistry[toolID]
if !ok {
return false
}
return toolDef.Type == blockDef.EffectiveTool
}