JJSax

vein miner

May 27th, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.93 KB | None | 0 0
  1. -- the function of this program is to get rid of
  2. --  all of a block type attached to the block
  3. --  underneath
  4.  
  5. -- crucial variables
  6. blockName = nil
  7. blockMeta = nil
  8.  
  9. currentBlocks = 0
  10. killSwitch = 10000 -- How many blocks it will remove before it stops
  11. -- this should help prevent any huge accidents
  12.  
  13. removedBlocks   = {}
  14. startPoint = {}
  15.  
  16. -- functions
  17.  
  18. function checkForExisting(x,y,z)
  19.     for k,v in pairs(startPoint) do
  20.         if x == v.x and
  21.         y == v.y and
  22.         z == v.z then
  23.             return true
  24.         end
  25.     end
  26.     return false
  27. end
  28.  
  29. function addStartPoint(x,y,z)
  30.     for i = 1, 64 do
  31.         if startPoint[i] == nil then
  32.             if checkForExisting(x,y,z) == false then
  33.                 startPoint[i] = {x = x, y = y, z = z}
  34.                 break
  35.             end
  36.         end
  37.     end
  38. end
  39.  
  40. function condensePointList(t)
  41.     -- credit for this function goes to CometWolf of the CCForums
  42.     local compressed = {}
  43.     for k,v in pairs(t) do
  44.       compressed[#compressed+1] = {
  45.             key = k,
  46.             value = v
  47.       }
  48.     end
  49.     table.sort(
  50.       compressed,
  51.       function(v1,v2)
  52.             return v1.key < v2.key
  53.       end
  54.     )
  55.     local ordered = {}
  56.     for i=1,#compressed do
  57.       ordered[i] = compressed[i].value
  58.     end
  59.     return compressed
  60. end
  61.  
  62. function checkforBLock()
  63.     for i = 1, #startPoint do
  64.         local block = commands.getBlockInfo(startPoint[i].x,startPoint[i].y,startPoint[i].z)
  65.         local name, meta
  66.         for k,v in pairs(block) do
  67.             if k == "name" then
  68.                 name = v
  69.             elseif k == "metadata" then
  70.                 meta = v
  71.             end
  72.         end
  73.         if name == "minecraft:air" then
  74.             table.remove(startPoint, i)
  75.         end
  76.     end
  77. end
  78.  
  79. function getBlockToRemove()
  80.     local ccx, ccy, ccz = commands.getBlockPosition()
  81.     -- get block type
  82.     local block = commands.getBlockInfo(ccx, ccy-1, ccz)
  83.     for k,v in pairs(block) do
  84.         if k == "name" then
  85.             blockName = v
  86.         elseif k == "metadata" then
  87.             blockMeta = v
  88.         end
  89.     end
  90.  
  91.     -- error if block below is air
  92.     if blockName == "minecraft:air" then
  93.         error("The block below is air!")
  94.     end
  95.     -- add start point
  96.     addStartPoint(ccx, ccy-1, ccz)
  97. end
  98.  
  99. function checkSides(x,y,z)
  100.  
  101.     for i = -1, 1, 2 do
  102.         local block = commands.getBlockInfo(x+i,y,z)
  103.         local name, meta
  104.         for k,v in pairs(block) do
  105.             if k == "name" then
  106.                 name = v
  107.             elseif k == "metadata" then
  108.                 meta = v
  109.             end
  110.         end
  111.         if name == blockName and meta == blockMeta then
  112.             addStartPoint(x+i,y,z)
  113.         end
  114.     end
  115.     for i = -1, 1, 2 do
  116.         local block = commands.getBlockInfo(x,y+i,z)
  117.         local name, meta
  118.         for k,v in pairs(block) do
  119.             if k == "name" then
  120.                 name = v
  121.             elseif k == "metadata" then
  122.                 meta = v
  123.             end
  124.         end
  125.         if name == blockName and meta == blockMeta then
  126.             addStartPoint(x,y+i,z)
  127.         end
  128.     end
  129.     for i = -1, 1, 2 do
  130.         local block = commands.getBlockInfo(x,y,z+i)
  131.         local name, meta
  132.         for k,v in pairs(block) do
  133.             if k == "name" then
  134.                 name = v
  135.             elseif k == "metadata" then
  136.                 meta = v
  137.             end
  138.         end
  139.         if name == blockName and meta == blockMeta then
  140.             addStartPoint(x,y,z+i)
  141.         end
  142.     end
  143. end
  144.  
  145. function removeBlock(spNumb)
  146.     checkSides(startPoint[spNumb].x, startPoint[spNumb].y, startPoint[spNumb].z)
  147.     commands.setBlock(startPoint[spNumb].x, startPoint[spNumb].y, startPoint[spNumb].z, "minecraft:air")
  148.     -- animation?
  149.  
  150.     commands.say(#startPoint)
  151.     table.remove(startPoint, spNumb)
  152.  
  153.     currentBlocks = currentBlocks + 1
  154.     if currentBlocks >= killSwitch then
  155.         commands.say("Kill Switch Reached!")
  156.         error("Kill Switch limit reached!")
  157.     end
  158. end
  159.  
  160. function deleteBlocks()
  161.     for i = 1, 64 do
  162.         if startPoint[i] then
  163.             removeBlock(i)
  164.         end
  165.     end
  166.     condensePointList(startPoint)
  167. end
  168.  
  169. function debug()
  170. end
  171.  
  172. function removeBlockLoop()
  173.     -- needs to know what direction it was detected from
  174.     while #startPoint > 0 do
  175.         deleteBlocks()
  176.         -- sleep(.01)
  177.         --break -- temporary
  178.         -- checkforBLock()
  179.     end
  180. end
  181.  
  182. -- main
  183.  
  184. debug()
  185. commands.gamerule("commandBlockOutput", false)
  186. getBlockToRemove()
  187. removeBlockLoop()
  188. commands.gamerule("commandBlockOutput", true)
  189. commands.say("I have removed the vein!")
Advertisement
Add Comment
Please, Sign In to add comment