forked from df-mc/dragonfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
116 lines (103 loc) · 3.26 KB
/
log.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
115
116
package block
import (
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/block/cube"
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/item"
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/world"
"github.com/go-gl/mathgl/mgl64"
"time"
)
// Log is a naturally occurring block found in trees, primarily used to create planks. It comes in six
// species: oak, spruce, birch, jungle, acacia, and dark oak.
// Stripped log is a variant obtained by using an axe on a log.
type Log struct {
solid
bass
// Wood is the type of wood of the log. This field must have one of the values found in the material
// package.
Wood WoodType
// Stripped specifies if the log is stripped or not.
Stripped bool
// Axis is the axis which the log block faces.
Axis cube.Axis
}
// FlammabilityInfo ...
func (l Log) FlammabilityInfo() FlammabilityInfo {
if !l.Wood.Flammable() {
return newFlammabilityInfo(0, 0, false)
}
return newFlammabilityInfo(5, 5, true)
}
// BreakInfo ...
func (l Log) BreakInfo() BreakInfo {
b := newBreakInfo(2, alwaysHarvestable, axeEffective, oneOf(l))
if l.Wood == CrimsonWood() || l.Wood == WarpedWood() {
b = b.withBlastResistance(1.5)
}
return b
}
// SmeltInfo ...
func (Log) SmeltInfo() item.SmeltInfo {
return newSmeltInfo(item.NewStack(item.Charcoal{}, 1), 0.15)
}
// FuelInfo ...
func (Log) FuelInfo() item.FuelInfo {
return newFuelInfo(time.Second * 15)
}
// UseOnBlock handles the rotational placing of logs.
func (l Log) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) (used bool) {
pos, face, used = firstReplaceable(w, pos, face, l)
if !used {
return
}
l.Axis = face.Axis()
place(w, pos, l, user, ctx)
return placed(ctx)
}
// Strip ...
func (l Log) Strip() (world.Block, bool) {
return Log{Axis: l.Axis, Wood: l.Wood, Stripped: true}, !l.Stripped
}
// EncodeItem ...
func (l Log) EncodeItem() (name string, meta int16) {
if !l.Stripped {
switch l.Wood {
case CrimsonWood(), WarpedWood():
return "minecraft:" + l.Wood.String() + "_stem", 0
default:
return "minecraft:" + l.Wood.String() + "_log", 0
}
}
switch l.Wood {
case CrimsonWood(), WarpedWood():
return "minecraft:stripped_" + l.Wood.String() + "_stem", 0
default:
return "minecraft:stripped_" + l.Wood.String() + "_log", 0
}
}
// EncodeBlock ...
func (l Log) EncodeBlock() (name string, properties map[string]any) {
if !l.Stripped {
switch l.Wood {
case CrimsonWood(), WarpedWood():
return "minecraft:" + l.Wood.String() + "_stem", map[string]any{"pillar_axis": l.Axis.String()}
default:
return "minecraft:" + l.Wood.String() + "_log", map[string]any{"pillar_axis": l.Axis.String()}
}
}
switch l.Wood {
case CrimsonWood(), WarpedWood():
return "minecraft:stripped_" + l.Wood.String() + "_stem", map[string]any{"pillar_axis": l.Axis.String()}
default:
return "minecraft:stripped_" + l.Wood.String() + "_log", map[string]any{"pillar_axis": l.Axis.String()}
}
}
// allLogs returns a list of all possible log states.
func allLogs() (logs []world.Block) {
for _, w := range WoodTypes() {
for axis := cube.Axis(0); axis < 3; axis++ {
logs = append(logs, Log{Axis: axis, Stripped: true, Wood: w})
logs = append(logs, Log{Axis: axis, Stripped: false, Wood: w})
}
}
return
}