diff options
Diffstat (limited to 'server')
| -rw-r--r-- | server/block_def.go | 142 | ||||
| -rw-r--r-- | server/blocks.go | 125 | ||||
| -rw-r--r-- | server/server.go | 9 |
3 files changed, 274 insertions, 2 deletions
diff --git a/server/block_def.go b/server/block_def.go new file mode 100644 index 0000000..3b0474a --- /dev/null +++ b/server/block_def.go @@ -0,0 +1,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 + } + } + } +} diff --git a/server/blocks.go b/server/blocks.go new file mode 100644 index 0000000..19880de --- /dev/null +++ b/server/blocks.go @@ -0,0 +1,125 @@ +package server + +const ( + blockAir = iota + blockStone + blockGrass + blockDirt + blockCobblestone + blockPlanks + blockSapling + blockBedrock + blockWater + blockStillWater // yep, it's still water + blockLava + blockStillLava + blockSand + blockGravel + blockGoldOre + blockIronOre + blockCoalOre + blockWood + blockLeaves + blockSponge + blockGlass + blockRedWool + blockOrangeWool + blockYellowWool + blockLimeWool + blockGreenWool + blockTealWool + blockAquaWool + blockCyanWool // sorry, heav + blockBlueWool + blockIndigoWool + blockVioletWool + blockMagentaWool + blockPinkWool + blockBlackWool + blockGrayWool + blockWhiteWool + blockDandelion + blockRose + blockBrownMushroom + blockRedMushroom + blockGold + blockIron + blockDoubleSlab + blockSlab + blockBricks + blockTnt + blockBookshelf + blockMossyRocks // because it rocks + blockObsidian + blockCobblestoneSlab + blockRope + blockSandstone + blockSnow + blockFire + blockLightPinkWool + blockForestGreenWool + blockBrownWool + blockDeepBlueWool + blockTurquoiseWool + blockIce + blockTile + blockMagma + blockPillar + blockCrate + blockStoneBricks + // custom blocks + blockMossyStoneBricks + blockCrackedStoneBricks + blockPolishedStone + blockPumpkin + blockJackOLantern + blockWoodPole + blockStonePole + blockCobblestonePole +// blockSlabTop +// blockStoneSlab +// blockStoneSlabTop +// blockWoodSlab +// blockWoodSlabTop +// blockWoodStair +// blockStoneStair +// blockCobblestoneStair +) + +var blockDefinitions = map[blockType]blockDef { + blockMossyStoneBricks: blockDef { + Name: "Mossy Stone Bricks", + Solidity: solid, + MovementSpeed: 128, + WalkSound: stoneSound, + Textures: [6]textureId {0x2d, fillTextures}, + }, + blockCrackedStoneBricks: blockDef { + Name: "Cracked Stone Bricks", + Solidity: solid, + MovementSpeed: 128, + WalkSound: stoneSound, + Textures :[6]textureId {0x2e, fillTextures}, + }, + blockPolishedStone: blockDef { + Name: "Polished Stone", + Solidity: solid, + MovementSpeed: 128, + WalkSound: stoneSound, + Textures: [6]textureId {0x06, fillTextures}, + }, + blockPumpkin: blockDef { + Name: "Pumpkin", + Solidity: solid, + MovementSpeed: 128, + WalkSound: woodSound, + Textures: [6]textureId {0x2b, 0x3b, fillTextures}, + }, + blockJackOLantern: blockDef { + Name: "Jack-o'-Lantern", + Solidity: solid, + MovementSpeed: 128, + WalkSound: woodSound, + Textures: [6]textureId {0x2b, 0x3b, 0x3b, 0x3b, 0x3c, 0x3b}, + }, +} diff --git a/server/server.go b/server/server.go index 5e3ffe9..00e7cef 100644 --- a/server/server.go +++ b/server/server.go @@ -23,12 +23,16 @@ var supportedExtensions = []string { "FullCP437", "CustomBlocks", "ExtPlayerList.2", + "BlockDefinitions", + "BlockDefinitionsExt.2", } var requiredExtensions = []string { "ExtEntityPositions", "EnvMapAspect.2", "CustomBlocks", "ExtPlayerList.2", + "BlockDefinitions", + "BlockDefinitionsExt.2", } type ServerInfo struct { @@ -543,14 +547,15 @@ func (cl *client) cpeHandshake(conn net.Conn, ext map[string]bool) bool { cl.disconnect("Missing required extension: " + req) } } - err = classic.WritePacket(conn, &classic.CustomBlocksSupportLevel { SupportLevel: 1, }) + // it doesn't matter what the client sends in response to this if cl.handleError(err) != nil { return false } - // it doesn't matter what the client sends in response to this + + cl.SendPackets(nil, getBlockDefPackets()) cl.extensions = ext return true |
