/
blocktree.go
199 lines (170 loc) · 3.76 KB
/
blocktree.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// Copyright 2015 Matthew Collins
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package steven
import (
"fmt"
"image"
"reflect"
)
// Logs have 4 possible 'rotations' (more like shapes),
// one for each possible axis and a special 'none' one.
// The 'none' state causes the bark texture to be displayed
// on all sides.
type blockAxis int
const (
axisY blockAxis = iota
axisZ
axisX
axisNone
)
func (b blockAxis) String() string {
switch b {
case axisNone:
return "none"
case axisX:
return "x"
case axisY:
return "y"
case axisZ:
return "z"
}
return fmt.Sprintf("blockAxis(%d)", b)
}
// The tree variants are split across two log/leaves types
// due to the size limits of the old data field.
type treeVariant int
const (
treeOak treeVariant = iota
treeSpruce
treeBirch
treeJungle
treeAcacia
treeDarkOak
)
func (t treeVariant) String() string {
switch t {
case treeOak:
return "oak"
case treeSpruce:
return "spruce"
case treeBirch:
return "birch"
case treeJungle:
return "jungle"
case treeAcacia:
return "acacia"
case treeDarkOak:
return "dark_oak"
}
return fmt.Sprintf("treeVariant(%d)", t)
}
type blockLog struct {
baseBlock
Variant treeVariant `state:"variant,@VariantRange"`
Second bool
Axis blockAxis `state:"axis,0-3"`
}
func (l *blockLog) load(tag reflect.StructTag) {
getBool := wrapTagBool(tag)
l.Second = getBool("second", false)
}
func (l *blockLog) VariantRange() (int, int) {
if l.Second {
return 4, 5
}
return 0, 3
}
func (l *blockLog) ModelName() string {
return l.Variant.String() + "_log"
}
func (l *blockLog) ModelVariant() string {
return fmt.Sprintf("axis=%s", l.Axis)
}
func (l *blockLog) toData() int {
data := int(l.Variant)
if l.Second {
data -= 4
}
data |= int(l.Axis) << 2
return data
}
type blockLeaves struct {
baseBlock
Variant treeVariant `state:"variant,@VariantRange"`
Second bool
Decayable bool `state:"decayable"`
CheckDecay bool `state:"check_decay"`
}
func (l *blockLeaves) load(tag reflect.StructTag) {
getBool := wrapTagBool(tag)
l.Second = getBool("second", false)
l.cullAgainst = false
}
func (l *blockLeaves) VariantRange() (int, int) {
if l.Second {
return 4, 5
}
return 0, 3
}
func (l *blockLeaves) ModelName() string {
return l.Variant.String() + "_leaves"
}
func (l *blockLeaves) ForceShade() bool {
return true
}
func (l *blockLeaves) TintImage() *image.NRGBA {
return foliageBiomeColors
}
func (l *blockLeaves) toData() int {
data := int(l.Variant)
if l.Second {
data -= 4
}
if !l.Decayable {
data |= 0x4
}
if l.CheckDecay {
data |= 0x8
}
return data
}
type blockPlanks struct {
baseBlock
Variant treeVariant `state:"variant,0-5"`
}
func (b *blockPlanks) ModelName() string {
return b.Variant.String() + "_planks"
}
func (b *blockPlanks) toData() int {
return int(b.Variant)
}
type blockSapling struct {
baseBlock
Variant treeVariant `state:"type,0-5"`
Stage int `state:"stage,0-1"`
}
func (b *blockSapling) load(tag reflect.StructTag) {
b.cullAgainst = false
}
func (b *blockSapling) ModelName() string {
return b.Variant.String() + "_sapling"
}
func (b *blockSapling) ModelVariant() string {
return fmt.Sprintf("stage=%d", b.Stage)
}
func (b *blockSapling) toData() int {
data := int(b.Variant)
data |= b.Stage << 3
return data
}