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
|
package server
import (
"iter"
"git.citrons.xyz/metronode/classic"
)
type blockType int16
const (
walkThrough = classic.WalkThrough
swimThrough = classic.SwimThrough
solid = classic.Solid
partiallySlippery = classic.PartiallySlippery
fullySlippery = classic.FullySlippery
water = classic.Water
lava = classic.Lava
rope = classic.Rope
)
type blockSolidity byte
const (
noSound = classic.NoSound
woodSound = classic.WoodSound
gravelSound = classic.GravelSound
grassSound = classic.GrassSound
stoneSound = classic.StoneSound
metalSound = classic.MetalSound
glassSound = classic.GlassSound
woolSound = classic.WoolSound
sandSound = classic.SandSound
snowSound = classic.SnowSound
)
type blockSound byte
const (
opaque = classic.Opaque
transparentGlass = classic.TransparentGlass
transparentLeaves = classic.TransparentLeaves
translucent = classic.Translucent
invisible = classic.Invisible
)
type blockOpacity byte
const (
cubeShape = iota
spriteShape
cuboidShape
)
type blockShape byte
type textureId int
const fillTextures = -1
type blockDef struct {
Name string
Solidity blockSolidity
MovementSpeed byte
Textures [6]textureId
TransmitsLight bool
WalkSound blockSound
FullBright bool
Shape blockShape
Min [3]byte
Max [3]byte
Opacity blockOpacity
FogDensity byte
FogColor [3]byte
}
func getBlockDefPackets() iter.Seq[classic.Packet] {
return func(yield func(classic.Packet) bool) {
for id, def := range blockDefinitions {
var packet classic.Packet
var (
transmitsLight byte
fullBright byte
)
if def.TransmitsLight {
transmitsLight = 1
}
if def.FullBright {
fullBright = 1
}
if def.Shape != spriteShape {
var (i int; texture textureId)
for i, texture = range def.Textures {
if texture == fillTextures {
break
}
}
if texture == fillTextures {
for i = i; i < len(def.Textures); i++ {
def.Textures[i] = def.Textures[i - 1]
}
}
if def.Shape == cubeShape {
def.Min = [3]byte {0, 0, 0}
def.Max = [3]byte {16, 16, 16}
}
packet = &classic.DefineBlockExt {
BlockId: byte(id),
Name: classic.PadString(def.Name),
Solidity: byte(def.Solidity),
MovementSpeed: def.MovementSpeed,
TopTextureId: byte(def.Textures[0]),
LeftTextureId: byte(def.Textures[1]),
RightTextureId: byte(def.Textures[2]),
FrontTextureId: byte(def.Textures[3]),
BackTextureId: byte(def.Textures[4]),
BottomTextureId: byte(def.Textures[5]),
TransmitsLight: transmitsLight,
WalkSound: byte(def.WalkSound),
FullBright: fullBright,
Min: def.Min,
Max: def.Max,
BlockDraw: byte(def.Opacity),
FogDensity: def.FogDensity,
FogColor: def.FogColor,
}
} else {
packet = &classic.DefineBlock {
BlockId: byte(id),
Name: classic.PadString(def.Name),
Solidity: byte(def.Solidity),
MovementSpeed: def.MovementSpeed,
SideTextureId: byte(def.Textures[0]),
TransmitsLight: transmitsLight,
WalkSound: byte(def.WalkSound),
FullBright: fullBright,
Shape: 0,
BlockDraw: byte(def.Opacity),
FogDensity: def.FogDensity,
FogColor: def.FogColor,
}
}
if !yield(packet) {
return
}
}
}
}
|