---------------------------------------------------------------------------------- |-- Module : Block-- License : Public Domain---- Maintainer : Douglas Burke-- Stability : experimental-- Portability : Haskell 98---- Block handling.---- It probably makes sense for the block types in-- "Data.MineCraft.Pi.Types" - namely `Data.MineCraft.Pi.Types.BlockType`-- and `Data.MineCraft.Pi.Types.BlockData`-- to be moved into this module.---- See <http://www.minecraftwiki.net/wiki/Data_values_(Pocket_Edition)> and-- <http://www.minecraftwiki.net/wiki/Pi_Edition_version_history>, although I-- have not cross-matched and verified all this information.----------------------------------------------------------------------------------moduleData.MineCraft.Pi.Block(-- * QueriesgetBlock,getBlockData,getBlocks-- * Commands,setBlock,setBlockData,setBlocks,setBlocksData-- * Utilities,showBlock-- * Block types,air,stone,grass,dirt,cobblestone,woodPlanks,sapling,bedrock,water,waterStationary,lava,lavaStationary,sand,gravel,goldOre,ironOre,coalOre,wood,leaves,glass,lapisLazuliOre,lapisLazuliBlock,sandstone,bed,cobweb,grassTall,wool,flowerYellow,flowerCyan,mushroomBrown,mushroomRed,goldBlock,ironBlock,stoneSlabDouble,stoneSlab,brickBlock,tnt,bookshelf,mossStone,obsidian,torch,fire,stairsWood,chest,diamondOre,diamondBlock,craftingTable,farmland,furnaceInactive,furnaceActive,doorWood,ladder,stairsCobblestone,doorIron,redstoneOre,snow,ice,snowBlock,cactus,clay,sugarCane,fence,glowstoneBlock,bedrockInvisible,stoneBrick,glassPane,melon,fenceGate,glowingObsidian,netherReactorCore)whereimportControl.Monad(liftM)importData.Maybe(fromMaybe)importData.Word(Word16)importData.MineCraft.Pi.TypesimportNetwork.MineCraft.Pi.ClientimportNetwork.MineCraft.Pi.Client.Internal-- | A type of a block.air,stone,grass,dirt,cobblestone,woodPlanks,sapling,bedrock,water,waterStationary,lava,lavaStationary,sand,gravel,goldOre,ironOre,coalOre,wood,leaves,glass,lapisLazuliOre,lapisLazuliBlock,sandstone,bed,cobweb,grassTall,wool,flowerYellow,flowerCyan,mushroomBrown,mushroomRed,goldBlock,ironBlock,stoneSlabDouble,stoneSlab,brickBlock,tnt,bookshelf,mossStone,obsidian,torch,fire,stairsWood,chest,diamondOre,diamondBlock,craftingTable,farmland,furnaceInactive,furnaceActive,doorWood,ladder,stairsCobblestone,doorIron,redstoneOre,snow,ice,snowBlock,cactus,clay,sugarCane,fence,glowstoneBlock,bedrockInvisible,stoneBrick,glassPane,melon,fenceGate,glowingObsidian,netherReactorCore::BlockTypeair=BlockType0stone=BlockType1grass=BlockType2dirt=BlockType3cobblestone=BlockType4woodPlanks=BlockType5sapling=BlockType6bedrock=BlockType7water=BlockType8waterStationary=BlockType9lava=BlockType10lavaStationary=BlockType11sand=BlockType12gravel=BlockType13goldOre=BlockType14ironOre=BlockType15coalOre=BlockType16wood=BlockType17leaves=BlockType18glass=BlockType20lapisLazuliOre=BlockType21lapisLazuliBlock=BlockType22sandstone=BlockType24bed=BlockType26cobweb=BlockType30grassTall=BlockType31wool=BlockType35flowerYellow=BlockType37flowerCyan=BlockType38mushroomBrown=BlockType39mushroomRed=BlockType40goldBlock=BlockType41ironBlock=BlockType42stoneSlabDouble=BlockType43stoneSlab=BlockType44brickBlock=BlockType45tnt=BlockType46bookshelf=BlockType47mossStone=BlockType48obsidian=BlockType49torch=BlockType50fire=BlockType51stairsWood=BlockType53chest=BlockType54diamondOre=BlockType56diamondBlock=BlockType57craftingTable=BlockType58farmland=BlockType60furnaceInactive=BlockType61furnaceActive=BlockType62doorWood=BlockType64ladder=BlockType65stairsCobblestone=BlockType67doorIron=BlockType71redstoneOre=BlockType73snow=BlockType78ice=BlockType79snowBlock=BlockType80cactus=BlockType81clay=BlockType82sugarCane=BlockType83fence=BlockType85glowstoneBlock=BlockType89bedrockInvisible=BlockType95stoneBrick=BlockType98glassPane=BlockType102melon=BlockType103fenceGate=BlockType107glowingObsidian=BlockType246netherReactorCore=BlockType247-- For now assume the table is small enough it is not-- worth using a map.blockNames::[(Word16,String)]blockNames=[(0,"Air"),(1,"Stone"),(2,"Grass"),(3,"Dirt"),(4,"Cobblestone"),(5,"Wooden Plank"),(6,"Sapling"),(7,"BedRock"),(8,"Water"),(9,"Stationary water"),(10,"Lava"),(11,"Stationary lava"),(12,"Sand"),(13,"Gravel"),(14,"Gold Ore"),(15,"Iron Ore"),(16,"Coal Ore"),(17,"Wood"),(18,"Leaves"),(20,"Glass"),(21,"Lapis Lazuli Ore"),(22,"Lapis Lazuli Block"),(24,"Sandstone"),(26,"Bed"),(30,"Cobweb"),(31,"Tall Grass"),(35,"Wool"),(37,"Yellow Flower"),(38,"Cyan Flower"),(39,"Brown Mushroom"),(40,"Brown Mushroom"),(41,"Gold Block"),(42,"Iron Block"),(43,"Double Stone Slab"),(44,"Stone Slab"),(45,"Brick Block"),(46,"TNT"),(47,"Bookshelf"),(48,"Moss Stone"),(49,"Obsidian"),(50,"Torch"),(51,"Fire"),(53,"Wooden Stairs"),(54,"Chest"),(56,"Diamond Ore"),(57,"Diamond Block"),(58,"Crafting Table"),(59,"Wheat Seeds")-- valid?,(60,"Farmland"),(61,"Furnace"),(62,"Burning Furnace"),(63,"Sign Post"),(64,"Wooden Door"),(65,"Ladder"),(67,"Cobblestone Stairs"),(68,"Wall Sign")-- valid?,(71,"Iron Door"),(73,"Redstone Ore"),(74,"Glowing Redstone Ore")-- valid?,(78,"Snow"),(79,"Ice"),(80,"Snow Block"),(81,"Cactus"),(82,"Clay"),(83,"Sugar Cane"),(85,"Fence"),(87,"Netherrack")-- valid?,(89,"Glowstone Block"),(95,"Invisible Bedrock"),(98,"Stone Brick"),(102,"Glass Pane"),(103,"Melon"),(105,"Melon Stem")-- valid?,(107,"Fence Gate"),(108,"Brick Stairs")-- valid?,(109,"Stone Brick Stairs")-- valid?,(112,"Nether Brick")-- valid?,(114,"Nether Brick Stairs")-- valid?,(128,"Sandstone Stairs")-- valid?,(155,"Block of Quartz")-- valid?,(156,"Quartz Stairs")-- valid?,(245,"Stone Cutter")-- valid?,(246,"Glowing Obsidian"),(247,"Nether Reactor Core"),(249,"Update Game Block")-- valid?,(253,"Grass Block (mimic)")-- valid?,(254,"Leaves (mysterious)")-- valid?,(255,".name")-- valid?]-- | Return a name for the block type, or "Unknown block <number>"-- if unknown.showBlock::BlockType->StringshowBlock(BlockTypen)=fromMaybe("Unknown block <"++shown++">")$lookupnblockNames-- | What is the block at this position? See also `getBlockData`.getBlock::IPos->MCPIBlockTypegetBlockpos=fromMC`liftM`query"world.getBlock"[toMCpos]-- | What is the block at this position? See also `getBlock`.getBlockData::IPos->MCPI(BlockType,BlockData)getBlockDatapos=fromMC`liftM`query"world.getBlockWithData"[toMCpos]-- | Get the blocks in the cuboid defined by the start and end positions.--getBlocks::IPos-- ^ One corner of the cuboid. ->IPos-- ^ Opposite corner.->MCPI[BlockType]-- ^ The order has not been specified.getBlockssposepos=fromMC`liftM`query"world.getBlocks"[toMCspos,toMCepos]-- | Change the block at the position. See also `setBlockData`.setBlock::IPos->BlockType->MCPI()setBlockposbt=command"world.setBlock"[toMCpos,toMCbt]-- | Change the block at the position. See also `setBlock`.setBlockData::IPos->(BlockType,BlockData)->MCPI()setBlockDatapos(bt,bd)=command"world.setBlock"[toMCpos,toMCbt,toMCbd]-- | Set all the blocks in the cuboid to the same type. See also-- `setBlocksData`.setBlocks::IPos->IPos->BlockType->MCPI()setBlockssposeposbt=command"world.setBlocks"[toMCspos,toMCepos,toMCbt]-- | Set all the blocks in the cuboid to the same type. See also-- `setBlocks`.setBlocksData::IPos->IPos->(BlockType,BlockData)->MCPI()setBlocksDatasposepos(bt,bd)=command"world.setBlocks"[toMCspos,toMCepos,toMCbt,toMCbd]