From 618601cb570ca01a7f1d031daf7cc98ce7fbe0d3 Mon Sep 17 00:00:00 2001 From: raven Date: Wed, 25 Mar 2026 13:04:05 -0500 Subject: slab variants --- server/block_def.go | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 4 deletions(-) (limited to 'server/block_def.go') 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] { -- cgit v1.2.3