summaryrefslogtreecommitdiff
path: root/server/block_def.go
diff options
context:
space:
mode:
authorraven <citrons@mondecitronne.com>2026-03-25 13:04:05 -0500
committerraven <citrons@mondecitronne.com>2026-03-25 13:04:05 -0500
commit618601cb570ca01a7f1d031daf7cc98ce7fbe0d3 (patch)
treec3f039977adf9e6618de49a48051169afdb380a0 /server/block_def.go
parent7ec7b199afc963f3e87a704d26bfeabe99189de9 (diff)
slab variants
Diffstat (limited to 'server/block_def.go')
-rw-r--r--server/block_def.go70
1 files changed, 66 insertions, 4 deletions
diff --git a/server/block_def.go b/server/block_def.go
index a5adb40..cbd4596 100644
--- a/server/block_def.go
+++ b/server/block_def.go
@@ -70,15 +70,36 @@ type blockDef struct {
}
type rotateVariant int
+type slabMaterial struct{}
+type slabVariant bool
+
+func markVariants(variants map[any]blockType) {
+ for _, block := range variants {
+ def := blockDefinitions[block]
+ if def.Variants == nil {
+ def.Variants = make(map[any]blockType)
+ blockDefinitions[block] = def
+ }
+ for variation, block := range variants {
+ def.Variants[variation] = block
+ }
+ }
+}
+
+func assertNoDef(block blockType) {
+ if _, ok := blockDefinitions[block]; ok {
+ panic("variant would override existing block")
+ }
+}
var rotationNames = []string {"-N", "-E", "-S", "-W"}
func makeRotations(block blockType) {
- var variants = make(map[any]blockType)
oldDef := blockDefinitions[block]
+ variants := make(map[any]blockType)
for i := 0; i < 4; i++ {
newBlock := block + blockType(i)
- if _, ok := blockDefinitions[newBlock]; i != 0 && ok {
- panic("variant would override existing block")
+ if i != 0 {
+ assertNoDef(newBlock)
}
newDef := oldDef
for j := 0; j < 4; j++ {
@@ -106,9 +127,50 @@ func makeRotations(block blockType) {
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
+ variants[rotateVariant(i)] = newBlock
blockDefinitions[newBlock] = newDef
}
+ markVariants(variants)
+}
+
+func makeSlabs(material blockType, slab blockType, name string) {
+ materialDef := blockDefinitions[material]
+ variants := make(map[any]blockType)
+ variants[slabMaterial{}] = material
+
+ if name == "" {
+ name = materialDef.Name + " Slab"
+ }
+
+ bottomSlab := materialDef
+ bottomSlab.Name = name + "-D"
+ bottomSlab.Shape = cuboidShape
+ bottomSlab.Min = [3]byte {0, 0, 0}
+ bottomSlab.Max = [3]byte {16, 8, 16}
+ switch material {
+ default:
+ assertNoDef(slab)
+ variants[slabVariant(false)] = slab
+ blockDefinitions[slab] = bottomSlab
+ case blockDoubleSlab:
+ variants[slabVariant(false)] = blockSlab
+ blockDefinitions[blockSlab] = bottomSlab
+ slab--
+ case blockCobblestone:
+ variants[slabVariant(false)] = blockCobblestoneSlab
+ blockDefinitions[blockCobblestoneSlab] = bottomSlab
+ slab--
+ }
+ topSlab := materialDef
+ topSlab.Name = name + "-U"
+ topSlab.Shape = cuboidShape
+ topSlab.Min = [3]byte {0, 8, 0}
+ topSlab.Max = [3]byte {16, 16, 16}
+ assertNoDef(slab + 1)
+ variants[slabVariant(true)] = slab + 1
+ blockDefinitions[slab + 1] = topSlab
+
+ markVariants(variants)
}
func getBlockDefPackets() iter.Seq[classic.Packet] {