Advertisement
Imgoodisher

CopyBlock

May 26th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.48 KB | None | 0 0
  1. local p
  2. for i,v in pairs(rs.getSides()) do
  3.     if peripheral.getType(v) == "adventure map interface" then
  4.         p = peripheral.wrap(v)
  5.         break
  6.     end
  7. end
  8.  
  9. function loadChunk(_x, _y, _z, sx, sy, sz, slow)
  10.     local chunk = {}
  11.  
  12.     local world = p.getWorld(p.getPeripheralWorldID())
  13.     _x = _x - 1
  14.     _z = _z - 1
  15.  
  16.     for x = 0, sx-1 do
  17.         chunk[x] = {}
  18.         for y = 0, sy-1 do
  19.             chunk[x][y] = {}
  20.             for z = 0, sz-1 do
  21.                 local id = world.getBlockID(x + _x, y + _y, z + _z)
  22.                 local md = world.getMetadata(x + _x, y + _y, z + _z)
  23.                 chunk[x][y][z] = {id, md}
  24.                 if slow and id ~= 0 then
  25.                     world.setBlockWithoutNotify(x + _x, y + _y, z + _z, 0, 0)
  26.                     sleep(0)
  27.                 end
  28.             end
  29.         end
  30.     end
  31.  
  32.     if slow then
  33.         buildChunk(chunk, _x, _y, _z)
  34.     end
  35.  
  36.     return chunk
  37. end
  38.  
  39. function buildChunk(chunk, px, py, pz, slow)
  40.  
  41.     local world = p.getWorld(p.getPeripheralWorldID())
  42.  
  43.     for x, _y in pairs(chunk) do
  44.         for y, _z in pairs(_y) do
  45.             for z, block in pairs(_z) do
  46.                 world.setBlockWithoutNotify(px + x - 1, py + y, pz + z - 1, unpack(block))
  47.                 if slow and block[1] ~= 0 then sleep(0) end
  48.             end
  49.         end
  50.     end
  51.  
  52. end
  53.  
  54. function clearChunk(_x, _y, _z, sx, sy, sz, slow)
  55.     local world = p.getWorld(p.getPeripheralWorldID())
  56.     _x = _x - 1
  57.     _z = _z - 1
  58.  
  59.     for x = 0, sx-1 do
  60.         for y = 0, sy-1 do
  61.             for z = 0, sz-1 do
  62.                 if slow and world.getBlockID(x + _x, y + _y, z + _z) ~= 0 then
  63.                     sleep(0)
  64.                 end
  65.                 world.setBlockWithoutNotify(x + _x, y + _y, z + _z, 0, 0)
  66.             end
  67.         end
  68.     end
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement