Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- the function of this program is to get rid of
- -- all of a block type attached to the block
- -- underneath
- -- crucial variables
- blockName = nil
- blockMeta = nil
- currentBlocks = 0
- killSwitch = 10000 -- How many blocks it will remove before it stops
- -- this should help prevent any huge accidents
- removedBlocks = {}
- startPoint = {}
- -- functions
- function checkForExisting(x,y,z)
- for k,v in pairs(startPoint) do
- if x == v.x and
- y == v.y and
- z == v.z then
- return true
- end
- end
- return false
- end
- function addStartPoint(x,y,z)
- for i = 1, 64 do
- if startPoint[i] == nil then
- if checkForExisting(x,y,z) == false then
- startPoint[i] = {x = x, y = y, z = z}
- break
- end
- end
- end
- end
- function condensePointList(t)
- -- credit for this function goes to CometWolf of the CCForums
- local compressed = {}
- for k,v in pairs(t) do
- compressed[#compressed+1] = {
- key = k,
- value = v
- }
- end
- table.sort(
- compressed,
- function(v1,v2)
- return v1.key < v2.key
- end
- )
- local ordered = {}
- for i=1,#compressed do
- ordered[i] = compressed[i].value
- end
- return compressed
- end
- function checkforBLock()
- for i = 1, #startPoint do
- local block = commands.getBlockInfo(startPoint[i].x,startPoint[i].y,startPoint[i].z)
- local name, meta
- for k,v in pairs(block) do
- if k == "name" then
- name = v
- elseif k == "metadata" then
- meta = v
- end
- end
- if name == "minecraft:air" then
- table.remove(startPoint, i)
- end
- end
- end
- function getBlockToRemove()
- local ccx, ccy, ccz = commands.getBlockPosition()
- -- get block type
- local block = commands.getBlockInfo(ccx, ccy-1, ccz)
- for k,v in pairs(block) do
- if k == "name" then
- blockName = v
- elseif k == "metadata" then
- blockMeta = v
- end
- end
- -- error if block below is air
- if blockName == "minecraft:air" then
- error("The block below is air!")
- end
- -- add start point
- addStartPoint(ccx, ccy-1, ccz)
- end
- function checkSides(x,y,z)
- for i = -1, 1, 2 do
- local block = commands.getBlockInfo(x+i,y,z)
- local name, meta
- for k,v in pairs(block) do
- if k == "name" then
- name = v
- elseif k == "metadata" then
- meta = v
- end
- end
- if name == blockName and meta == blockMeta then
- addStartPoint(x+i,y,z)
- end
- end
- for i = -1, 1, 2 do
- local block = commands.getBlockInfo(x,y+i,z)
- local name, meta
- for k,v in pairs(block) do
- if k == "name" then
- name = v
- elseif k == "metadata" then
- meta = v
- end
- end
- if name == blockName and meta == blockMeta then
- addStartPoint(x,y+i,z)
- end
- end
- for i = -1, 1, 2 do
- local block = commands.getBlockInfo(x,y,z+i)
- local name, meta
- for k,v in pairs(block) do
- if k == "name" then
- name = v
- elseif k == "metadata" then
- meta = v
- end
- end
- if name == blockName and meta == blockMeta then
- addStartPoint(x,y,z+i)
- end
- end
- end
- function removeBlock(spNumb)
- checkSides(startPoint[spNumb].x, startPoint[spNumb].y, startPoint[spNumb].z)
- commands.setBlock(startPoint[spNumb].x, startPoint[spNumb].y, startPoint[spNumb].z, "minecraft:air")
- -- animation?
- commands.say(#startPoint)
- table.remove(startPoint, spNumb)
- currentBlocks = currentBlocks + 1
- if currentBlocks >= killSwitch then
- commands.say("Kill Switch Reached!")
- error("Kill Switch limit reached!")
- end
- end
- function deleteBlocks()
- for i = 1, 64 do
- if startPoint[i] then
- removeBlock(i)
- end
- end
- condensePointList(startPoint)
- end
- function debug()
- end
- function removeBlockLoop()
- -- needs to know what direction it was detected from
- while #startPoint > 0 do
- deleteBlocks()
- -- sleep(.01)
- --break -- temporary
- -- checkforBLock()
- end
- end
- -- main
- debug()
- commands.gamerule("commandBlockOutput", false)
- getBlockToRemove()
- removeBlockLoop()
- commands.gamerule("commandBlockOutput", true)
- commands.say("I have removed the vein!")
Advertisement
Add Comment
Please, Sign In to add comment