summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/block_def.go49
-rw-r--r--server/blocks.go8
2 files changed, 52 insertions, 5 deletions
diff --git a/server/block_def.go b/server/block_def.go
index 3b0474a..a5adb40 100644
--- a/server/block_def.go
+++ b/server/block_def.go
@@ -66,6 +66,49 @@ type blockDef struct {
Opacity blockOpacity
FogDensity byte
FogColor [3]byte
+ Variants map[any]blockType
+}
+
+type rotateVariant int
+
+var rotationNames = []string {"-N", "-E", "-S", "-W"}
+func makeRotations(block blockType) {
+ var variants = make(map[any]blockType)
+ oldDef := blockDefinitions[block]
+ for i := 0; i < 4; i++ {
+ newBlock := block + blockType(i)
+ if _, ok := blockDefinitions[newBlock]; i != 0 && ok {
+ panic("variant would override existing block")
+ }
+ newDef := oldDef
+ for j := 0; j < 4; j++ {
+ k := (j + i) % 4
+ newDef.Textures[j + 1] = oldDef.Textures[k + 1]
+ }
+ var minX, minZ, maxX, maxZ byte
+ switch i {
+ case 1:
+ minX = oldDef.Min[2]
+ minZ = 16 - oldDef.Min[0]
+ maxX = oldDef.Max[2]
+ maxZ = 16 - oldDef.Max[0]
+ case 2:
+ minX = 16 - oldDef.Min[0]
+ minZ = 16 - oldDef.Min[2]
+ maxX = 16 - oldDef.Max[0]
+ maxZ = 16 - oldDef.Max[2]
+ case 3:
+ minX = oldDef.Min[2]
+ minZ = 16 - oldDef.Min[0]
+ maxX = oldDef.Max[2]
+ maxZ = 16 - oldDef.Max[0]
+ }
+ newDef.Min = [3]byte {byte(minX), oldDef.Min[1], byte(minZ)}
+ newDef.Max = [3]byte {byte(maxX), oldDef.Max[1], byte(maxZ)}
+ newDef.Name = newDef.Name + rotationNames[i]
+ newDef.Variants = variants
+ blockDefinitions[newBlock] = newDef
+ }
}
func getBlockDefPackets() iter.Seq[classic.Packet] {
@@ -104,10 +147,10 @@ func getBlockDefPackets() iter.Seq[classic.Packet] {
Solidity: byte(def.Solidity),
MovementSpeed: def.MovementSpeed,
TopTextureId: byte(def.Textures[0]),
- LeftTextureId: byte(def.Textures[1]),
+ LeftTextureId: byte(def.Textures[4]),
RightTextureId: byte(def.Textures[2]),
FrontTextureId: byte(def.Textures[3]),
- BackTextureId: byte(def.Textures[4]),
+ BackTextureId: byte(def.Textures[1]),
BottomTextureId: byte(def.Textures[5]),
TransmitsLight: transmitsLight,
WalkSound: byte(def.WalkSound),
@@ -124,7 +167,7 @@ func getBlockDefPackets() iter.Seq[classic.Packet] {
Name: classic.PadString(def.Name),
Solidity: byte(def.Solidity),
MovementSpeed: def.MovementSpeed,
- SideTextureId: byte(def.Textures[0]),
+ SideTextureId: byte(def.Textures[1]),
TransmitsLight: transmitsLight,
WalkSound: byte(def.WalkSound),
FullBright: fullBright,
diff --git a/server/blocks.go b/server/blocks.go
index 19880de..2d2ed20 100644
--- a/server/blocks.go
+++ b/server/blocks.go
@@ -72,7 +72,7 @@ const (
blockCrackedStoneBricks
blockPolishedStone
blockPumpkin
- blockJackOLantern
+ blockJackOLantern; _; _; _
blockWoodPole
blockStonePole
blockCobblestonePole
@@ -120,6 +120,10 @@ var blockDefinitions = map[blockType]blockDef {
Solidity: solid,
MovementSpeed: 128,
WalkSound: woodSound,
- Textures: [6]textureId {0x2b, 0x3b, 0x3b, 0x3b, 0x3c, 0x3b},
+ Textures: [6]textureId {0x2b, 0x3c, 0x3b, 0x3b, 0x3b, 0x3b},
},
}
+
+func init() {
+ makeRotations(blockJackOLantern)
+}