Guest User

saveArea

a guest
Sep 21st, 2015
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.28 KB | None | 0 0
  1. p,o,s = 8,3,8
  2.  
  3. function getFacing()
  4.   directions = {"unknown","north","south","west","east"}
  5.   blockInfo = commands.getBlockInfo(commands.getBlockPosition())
  6.   print("My facing is ", directions[blockInfo.metadata],".")
  7.   facing = directions[blockInfo.metadata]
  8. --  print(facing)
  9. end
  10.  
  11. function setModifiers()
  12.   fx,fz,swapxz = 0,0,false
  13.   if facing == "west" then fx,fz,swapxz = 1,1,true
  14.     elseif facing == "east" then fx,fz,swapxz = -1,-1,true
  15.     elseif facing == "north" then fx,fz,swapxz = -1,1,false
  16.     elseif facing == "south" then fx,fz,swapxz = 1,-1,false
  17.   end
  18. end
  19.  
  20. function relXYZ(x,y,z)
  21.   cx,cy,cz = commands.getBlockPosition()
  22. --  print(cx+fx+(x*fx),",",cy+y,",",cz+fz+(z*fz))
  23. --  commands.setblock(cx+fx+(x*fx),cy+y,cz+fz+(z*fz),"minecraft:stone")
  24.   return (cx+fx+(x*fx)), (cy+y), (cz+fz+(z*fz))
  25. end
  26.  
  27. function saveBlock(x,y,z)
  28. --  print(textutils.serialize(blockData))
  29.   data = commands.getBlockInfo(x,y,z)
  30. --  if not blockData[x] then blockData[x] = {} end
  31. --  if not blockData[x][y] then blockData[x][y] = {} end
  32. --  if not blockData[x][y][z] then blockData[x][y][z] = {} end
  33. --  blockData[x][y][z]["name"] = data["name"]
  34. --  blockData[x][y][z]["metadata"] = data["metadata"]
  35.     blockData = {
  36.       [x] = {
  37.         [y] = {
  38.           [z] = {
  39.             name=data["name"],
  40.             metadata=data["metadata"]
  41.                  } or {}
  42.                } or {}
  43.              } or {}
  44.            }
  45.  
  46. --  blockData = {[x]={[y]={[z]={name=data["name"],metadata=data["metadata"]}}}}
  47. --  print(textutils.serialize(blockData))
  48. end
  49.  
  50. function writeBlocks()
  51.   print("Saving to file...")
  52.   file = io.open("blocks","w")
  53.   file:write(textutils.serialize(blockData))
  54.   file:close()
  55.   print("Saving Complete!")
  56.   textutils.pagedPrint(textutils.serialize(blockData))
  57. end
  58.  
  59. function saveArea(x,y,z, x2,y2,z2)
  60.   print("Saving Area, this may take a moment...")
  61.   print(x,"x:",x2,"x2 ",y,"y:",y2,"y2 ",z,"z:",z2,"z2")
  62.   xStart, yStart, zStart = relXYZ(x,y,z)
  63.   xEnd, yEnd, zEnd = relXYZ(x2,y2,z2)
  64.   print("Scanning Area...")
  65.   blockData = {}
  66.   for x = xStart, xEnd,fx do
  67.     for y = yStart, yEnd do
  68.       for z = zStart, zEnd, fz do
  69.         saveBlock(x,y,z)
  70.       end
  71.     end
  72.   end
  73.   writeBlocks()
  74. end
  75.  
  76. getFacing()
  77. setModifiers()
  78. --relXYZ(p,o,s)
  79. saveArea(0,3,0,8,3,8)
Advertisement
Add Comment
Please, Sign In to add comment