Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ccCoord = {}
- ccCoord["x"], ccCoord["y"], ccCoord["z"] = commands.getBlockPosition()
- local blockData = {}
- local facing = ""
- local fx = 0
- local fz = 0
- local swapxz = false
- function getFacing()
- local directions = {"unknown", "north", "south", "west", "east"}
- local blockInfo = commands.getBlockInfo( commands.getBlockPosition() )
- print( "My facing is ", directions[ blockInfo.metadata ], "." )
- facing = directions[ blockInfo.metadata ]
- --print(facing)
- end
- function setModifiers()
- if facing == "west" then
- fx = 1
- fz = 1
- swapxz = true
- elseif facing == "east" then
- fx = -1
- fz = -1
- swapxz = true
- elseif facing == "north" then
- fx = -1
- fz = 1
- swapxz = false
- elseif facing == "south" then
- fx = 1
- fz = -1
- swapxz = false
- end
- end
- function saveBlock(x,y,z)
- local data = commands.getBlockInfo(x,y,z)
- if not blockData[x] then
- blockData[x] = {}
- end
- if not blockData[x][y] then
- blockData[x][y] = {}
- end
- if not blockData[x][y][z] then
- blockData[x][y][z] = {}
- end
- blockData[x][y][z]["name"] = data["name"]
- blockData[x][y][z]["metadata"] = data["metadata"]
- end
- function writeBlocks()
- file = io.open("blocks", "w")
- file:write(textutils.serialize(blockData))
- file:close()
- end
- function saveSpace(xStart, xEnd, yStart, yEnd, zStart, zEnd)
- --print(xStart..xEnd..yStart..yEnd..zStart..zEnd)
- for x = xStart, xEnd,fx do
- for y = yStart, yEnd do
- for z = zStart, zEnd,fz do
- saveBlock(x,y,z)
- end
- end
- end
- writeBlocks()
- end
- function relXYZnoswap(x,y,z)
- --print("NoSwap: "..ccCoord["x"]+(x+1)*fx..":"..ccCoord["y"]+(y)..":"..ccCoord["z"]+(z+1)*fz)
- return ccCoord["x"]+(x+1)*fx, ccCoord["y"]+(y), ccCoord["z"]+(z+1)*fz
- end
- function relXYZ(x,y,z)
- if not swapxz then
- return ccCoord["x"]+(x+1)*fx, ccCoord["y"]+(y), ccCoord["z"]+(z+1)*fz
- else
- return ccCoord["x"]+(z+1)*fz, ccCoord["y"]+(y), ccCoord["z"]+(x+1)*fx
- end
- end
- function saveBoardArea()
- print("Saving board area, this may take a moment....")
- local x,y,z,x2,y2,z2
- x,y,z = relXYZnoswap(0,-1,0)
- x2,y2,z2 = relXYZnoswap(9,5,9)
- print("Save: "..x..":"..x2..", "..y..":"..y2..", "..z..":"..z2)
- saveSpace(x,x2,y,y2,z,z2)
- print("Saving board area complete.")
- end
- getFacing()
- setModifiers()
- saveBoardArea()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement