· 6 years ago · Mar 18, 2020, 08:28 PM
1for key, value in pairs({ ["os/programs/stripMiner/mine.lua"] = "local inMove=false\nlocal start=vector.zero:copy()local way=vector.up:copy()local move,slots,mineList,trashList,data\nui.input.term=term\nlocal _x,_y,_w,_h=1,1,term.getSize()local text_fuel,text_facing,text_distance,text_moved,text_detected=\"Fuel: \",\"Facing: \",\"Distance Moved: \",\"Total Moved: \",\"Detected Blocks: \"local function deleteFiles()fs.delete(\"os/programs/stripMiner/data/move.set\")fs.delete(\"os/programs/stripMiner/data/data.set\")fs.delete(\"os/startup/50-stripMiner.lua\")end\nlocal input=ui.input.new()local drawer=ui.drawer.new(input,_x,_y,_w,_h)for i=1,_w*_h do\nif i<=_w or i>_w* (_h-1)then\ndrawer.buffer.text[i] =\" \"drawer.buffer.textColor[i] =colors.green\ndrawer.buffer.textBackgroundColor[i] =colors.green\nelse\ndrawer.buffer.text[i] =\" \"drawer.buffer.textColor[i] =colors.white\ndrawer.buffer.textBackgroundColor[i] =colors.white\nend\nend\nlocal label_title=ui.label.new(drawer,\"Strip Miner\",theme.label1,_x,_y,_w,1)local label_pos=ui.label.new(drawer,\"Position: \",theme.label2,_x,_y+1,10,1)local label_posX=ui.label.new(drawer,\"X: 0\",theme.label2,_x+10,_y+1,8,1)local label_posY=ui.label.new(drawer,\"Y: 0\",theme.label2,_x+19,_y+1,8,1)local label_posZ=ui.label.new(drawer,\"Z: 0\",theme.label2,_x+28,_y+1,8,1)local label_fuel=ui.label.new(drawer,text_fuel..turtle.getFuelLevel() ..\" / 0\",theme.label2,_x,_y+3,_w,1)local label_facing=ui.label.new(drawer,text_facing..\"Forward\",theme.label2,_x,_y+4,_w,1)local label_distance=ui.label.new(drawer,text_distance..\"0 / 0\",theme.label2,_x,_y+5,_w,1)local label_moved=ui.label.new(drawer,text_moved..\"0\",theme.label2,_x,_y+6,_w,1)local label_detected=ui.label.new(drawer,text_detected..\"0\",theme.label2,_x,_y+7,_w,1)local label_mode=ui.label.new(drawer,\"Mine\",theme.label2,_x,_y+9,_w,3)label_mode:setGlobalRect(nil,nil,_w,3)label_mode.scaleH=false\nlabel_mode.scaleW=false\nlocal button_pause=ui.button.new(drawer,\"Pause\",theme.button1,_x,_h,8,1)if move and move.pause then\nbutton_pause.text=\"Resume\"button_pause:recalculate()button_pause:repaint(\"this\")end\nlocal button_stop=ui.button.new(drawer,\"Stop\",theme.button1,_x+_w-12,_h,6,1)local button_exit=ui.button.new(drawer,\"Exit\",theme.button1,_x+_w-6,_h,6,1)local group_mainMenu=drawer.selectionManager:addNewGroup()group_mainMenu.current=button_pause\ngroup_mainMenu:addElement(button_pause,nil,nil,button_stop,nil)group_mainMenu:addElement(button_stop,button_pause,nil,button_exit,nil)group_mainMenu:addElement(button_exit,button_stop,nil,nil,nil)drawer:draw()local function loadSlots()slots= {}slots.all=data.slots\nslots.data= {}slots.chest= {}slots.fuel= {}slots.build= {}slots.torch= {}slots.enderChest=nil\nslots.empty= {}local function waifForData(slot)while turtle.getItemCount(slot) ==0 do\nos.pullEvent(\"turtle_inventory\")end\nend\nfor i=1, #slots.all do\nlocal id=slots.all[i]if id==1 then\nlabel_mode.text= (\"Collecting chest data.\\nPlease insert chest in slot %s.\"):format(i)label_mode:recalculate()label_mode:repaint(\"this\")waifForData(i)slots.data[i] =turtle.getItemDetail(i).name\ntable.insert(slots.chest,i)elseif id==2 then\nlabel_mode.text= (\"Collecting fuel data.\\nPlease insert fuel in slot %s.\"):format(i)label_mode:recalculate()label_mode:repaint(\"this\")local right=false\nwhile right==false do\nwhile turtle.getItemCount(i) <=1 do\nos.pullEvent(\"turtle_inventory\")end\nturtle.select(i)local level=turtle.getFuelLevel()if turtle.refuel(1)then\nlevel=turtle.getFuelLevel() -turtle.getFuelLimit()slots.data[i] = {name=turtle.getItemDetail(i).name,increase=level}if turtle.getFuelLevel() ==turtle.getFuelLimit()then\nslots.data[i].increase=80\nend\nright=true\nend\nend\ntable.insert(slots.fuel,i)elseif id==3 then\nlabel_mode.text= (\"Collecting build data.\\nPlease insert blocks in slot %s.\"):format(i)label_mode:recalculate()label_mode:repaint(\"this\")waifForData(i)slots.data[i] =turtle.getItemDetail(i).name\ntable.insert(slots.build,i)elseif id==4 then\nlabel_mode.text= (\"Collecting torch data.\\nPlease insert torches in slot %s.\"):format(i)label_mode:recalculate()label_mode:repaint(\"this\")waifForData(i)slots.data[i] =turtle.getItemDetail(i).name\ntable.insert(slots.torch,i)elseif id==5 then\nlabel_mode.text= (\"Collecting ender chest data.\\nPlease insert one ender chest in slot %s.\"):format(i)label_mode:recalculate()label_mode:repaint(\"this\")waifForData(i)slots.enderChest=i\nelse\ntable.insert(slots.empty,i)end\nend\ndata.slots=slots\nend\nlocal function loadData()local success\nsuccess,move=fs.doFile(\"os/programs/stripMiner/data/move.set\")if not success then\nmove= {}move.pos=start:copy()move.facing=vector.forward:copy()move.base=start:copy()move.undone= {}move.done= {}move.mode= {name=nil,data=nil}else\nvector.convert(move.pos)vector.convert(move.facing)vector.convert(move.base)for i=1, #move.undone do\nvector.convert(move.undone[i])end\nfor i=1, #move.done do\nvector.convert(move.done[i])end\nend\nif not move.distance then\nmove.distance=0\nmove.moved=0\nmove.detected=0\nmove.pause=false\nend\nsuccess,data=fs.doFile(\"os/programs/stripMiner/data/data.set\")mineList=dofile(data.pathSearchList)if data.pathTrashList then\ntrashList=dofile(data.pathTrashList)end\nif not data.slots or not data.slots.all then\nloadSlots()table.save(data,\"os/programs/stripMiner/data/data.set\")else\nslots=data.slots\nend\nend\nloadData()local function save()table.save(move,\"os/programs/stripMiner/data/move.set\")end\nlocal function update(f,p,m)if m then\ninMove=true\nend\nif f then\nmove.facing:set(move.facing.y*f.x,move.facing.x*f.y)local facing\nif move.facing.x==1 then\nfacing=\"Forward\"elseif move.facing.x== -1 then\nfacing=\"Backward\"elseif move.facing.y==1 then\nfacing=\"Right\"else\nfacing=\"Left\"end\nsave()label_facing.text=text_facing..facing\nlabel_facing:recalculate()label_facing:repaint(\"this\")end\nif p then\nmove.pos:set(move.pos.x+ (p.x*move.facing.x+p.y*move.facing.y),move.pos.y+ (p.x*move.facing.y+p.y*move.facing.x),move.pos.z+p.z)move.moved=move.moved+math.abs(p.x) +math.abs(p.y) +math.abs(p.z)move.distance=math.max(move.distance,move.pos.x)save()label_posX.text=\"X: \" ..move.pos.x\nlabel_posY.text=\"Y: \" ..move.pos.y\nlabel_posZ.text=\"Z: \" ..move.pos.z\nlabel_moved.text=text_moved..move.moved\nlabel_distance.text=text_distance..move.distance..\" / \" ..data.length\nlabel_posX:recalculate()label_posY:recalculate()label_posZ:recalculate()label_moved:recalculate()label_distance:recalculate()label_posX:repaint(\"this\")label_posY:repaint(\"this\")label_posZ:repaint(\"this\")label_moved:repaint(\"this\")label_distance:repaint(\"this\")drawer:draw()end\ninMove=m\nend\nlocal function mine()local placeTorch=false\nlocal startMode\nlocal function fillBuild(slot)local ret=false\nlocal name=slots.data[slot]for i=1, #slots.empty do\nlocal s=slots.empty[i]local data=turtle.getItemDetail(s)if data and data.name==name then\nturtle.select(s)turtle.transferTo(slot)ret=true\nend\nif turtle.getItemSpace(slot) ==0 then\nreturn true\nend\nend\nreturn ret\nend\nlocal function checkBuild(count)count=count or 0\nfor i=1, #slots.build do\nlocal slot=slots.build[i]local slotCount=turtle.getItemCount(slot) -1\nif slotCount>count then\nreturn true\nelse\nif fillBuild(slot)then\nslotCount=turtle.getItemCount(slot) -1\nif slotCount>count then\nreturn true\nelse\ncount=count-slotCount\nend\nend\nend\nend\nreturn false\nend\nlocal function selectBuild()if checkBuild()then\nfor i=1, #slots.build do\nlocal slot=slots.build[i]if turtle.getItemCount(slot) >1 then\nturtle.select(slot)return\nend\nend\nelse\nstartMode(\"build\",move.pos)end\nend\nlocal function checkTorch()for i=1, #slots.torch do\nlocal slot=slots.torch[i]if turtle.getItemCount(slot) >0 then\nreturn true\nend\nend\nreturn false\nend\nlocal function selectTorch()if checkTorch()then\nfor i=1, #slots.torch do\nlocal slot=slots.torch[i]if turtle.getItemCount(slot) >0 then\nturtle.select(slot)return\nend\nend\nelse\nstartMode(\"torch\",move.pos)end\nend\nlocal function checkChest()for i=1, #slots.chest do\nlocal slot=slots.chest[i]if turtle.getItemCount(slot) >0 then\nreturn true\nend\nend\nreturn false\nend\nlocal function selectChest()if checkChest()then\nfor i=1, #slots.chest do\nlocal slot=slots.chest[i]if turtle.getItemCount(slot) >0 then\nturtle.select(slot)return\nend\nend\nelse\nstartMode(\"chest\",move.pos)end\nend\nlocal function fillFuel(slot)local ret=false\nlocal name=slots.data[slot].name\nfor i=1, #slots.empty do\nlocal s=slots.empty[i]local data=turtle.getItemDetail(s)if data and data.name==name then\nturtle.select(s)turtle.transferTo(slot)ret=true\nend\nif turtle.getItemSpace(slot) ==0 then\nreturn true\nend\nend\nreturn ret\nend\nlocal function getNeededFuelLevel(v1,v2)local v=v1-v2\nreturn math.abs(v.x) +math.abs(v.y) +math.abs(v.z)end\nlocal function checkFuelLevel(distance)local fuelLimit=turtle.getFuelLimit()if fuelLimit==0 then\nreturn true\nend\nlocal fuelLevel,level=turtle.getFuelLevel(),0\nfor i=1, #slots.fuel do\nif distance<fuelLevel then\nturtle.select(1)label_fuel.text=text_fuel..fuelLevel..\" / \" ..distance\nlabel_fuel:recalculate()label_fuel:repaint(\"this\")return true\nend\nlocal slot=slots.fuel[i]fillFuel(slot)local name,increase=slots.data[slot].name,slots.data[slot].increase\nlocal detail=turtle.getItemDetail(slot)if detail and name==detail.name then\nlocal refuel=math.min(detail.count-1,math.ceil((distance-fuelLevel) /increase))if refuel>0 then\nturtle.select(slot)turtle.refuel(refuel)end\nlevel=level+ (detail.count-refuel) *increase\nfuelLevel=turtle.getFuelLevel()end\nend\nturtle.select(1)label_fuel.text=text_fuel..fuelLevel+level..\" / \" ..distance\nlabel_fuel:recalculate()label_fuel:repaint(\"this\")if distance<fuelLevel+level then\nreturn true\nend\nreturn false\nend\nlocal function setCurrentPos(x,y,z)move.pos:set(x,y,z)for i=1, #move.undone do\nif move.undone[i] ==move.pos then\ntable.remove(move.undone,i)return\nend\nend\nend\nlocal function addToUndone(v)for i=1, #move.done do\nif move.done[i] ==v then\nreturn false\nend\nend\nlocal clone=v:copy()table.insert(move.done,clone)table.insert(move.undone,clone)return true\nend\nlocal function removeVector(v)for i=1, #move.undone do\nif move.undone[i] ==v then\ntable.remove(move.undone,i)break\nend\nend\nend\nlocal function clearVectorLists()table.clear(move.undone)local i=1\nlocal v1,v2=vector.new(move.base.x-5,move.base.y-1,move.base.z-1),vector.new(move.base.x+5,move.base.y+1,move.base.z+2)while i<= #move.done do\nlocal v=move.done[i]if vector.contains(v1,v2,v)then\ni=i+1\nelse\ntable.remove(move.done,i)end\nend\nend\nlocal function getDir(dir)dir:set(dir.x*move.facing.x+dir.y*move.facing.y,dir.x* -move.facing.y+dir.y*move.facing.x)return dir\nend\nlocal function orderVectorList()table.orderComplex(move.undone,function(v)local value=0\nlocal dir=getDir(v-move.pos)if dir.x>0 then\nvalue=1\nelseif dir.x<0 then\nvalue=3\nelseif dir.y~=0 then\nvalue=2\nend\nreturn(v-move.pos):sqLength(), (v-move.base).x,value\nend)end\nlocal function getConnected(v,dir)if dir==1 then\nreturn v+vector.forward\nelseif dir==2 then\nreturn v+vector.up\nelseif dir==3 then\nreturn v+vector.down\nelseif dir==4 then\nreturn v+vector.right\nelseif dir==5 then\nreturn v+vector.left\nelseif dir==6 then\nreturn v+vector.backward\nend\nend\nlocal function inspect(dir)local success,data\nif dir==1 then\nsuccess,data=turtle.inspect()elseif dir==2 then\nsuccess,data=turtle.inspectUp()elseif dir==3 then\nsuccess,data=turtle.inspectDown()end\nif success then\nlocal ret= (data.searchWhiteList==\"White List\")for _,v in ipairs(mineList)do\nif(v[1] ==data.name and IF(v[2],v[2] ==data.metadata,true))then\nreturn ret\nend\nend\nreturn not ret\nend\nreturn false\nend\nlocal function turn(dir)if dir==1 then\nif move.facing.x<0 then\nturtle.move.turnRight(update)turtle.move.turnRight(update)elseif move.facing.y>0 then\nturtle.move.turnLeft(update)elseif move.facing.y<0 then\nturtle.move.turnRight(update)end\nelseif dir==2 then\nif move.facing.y<0 then\nturtle.move.turnRight(update)turtle.move.turnRight(update)elseif move.facing.x>0 then\nturtle.move.turnRight(update)elseif move.facing.x<0 then\nturtle.move.turnLeft(update)end\nelseif dir==3 then\nif move.facing.x>0 then\nturtle.move.turnRight(update)turtle.move.turnRight(update)elseif move.facing.y>0 then\nturtle.move.turnRight(update)elseif move.facing.y<0 then\nturtle.move.turnLeft(update)end\nelseif dir==4 then\nif move.facing.y>0 then\nturtle.move.turnRight(update)turtle.move.turnRight(update)elseif move.facing.x>0 then\nturtle.move.turnLeft(update)elseif move.facing.x<0 then\nturtle.move.turnRight(update)end\nend\nend\nlocal function goToDestination(v)if not move.mode.name and not checkFuelLevel(getNeededFuelLevel(start,move.pos))then\nstartMode(\"fuel\",move.pos)end\nlocal go=v-move.pos\nlocal chest=vector.new(move.base.x,0,0)if v~=chest and((go.x<0 and move.pos.x>chest.x)or(go.x>0 and move.pos.x<chest.x))and(move.pos.y==0 and go.z~=0 and math.min(v.z,move.pos.z) <=chest.z and math.min(v.z,move.pos.z) >=chest.z)then\nif move.facing.y==0 then\nturtle.move.turnRight(update)end\nturtle.move.forward(update)goToDestination(v)else\nturtle.move.go(getDir(go),update)end\nend\nlocal function makeSpace()local free=false\nif trashList then\nlocal space=0\nfor i=1, #slots.empty do\nlocal slot=slots.empty[i]local ret= (data.trashWhiteList==\"Black List\")local data=turtle.getItemDetail(slot)if data then\nfor k,v in pairs(trashList)do\nif v[1] ==data.name and IF(v[2],v[2] ==data.damage,true)then\nret=not ret\nbreak\nend\nend\nif ret then\nturtle.select(slot)turtle.drop()space=space+1\nend\nif space>2 then\nfree=true\nend\nend\nend\nend\nreturn free\nend\nlocal function checkSpace()local free=false\nfor i=1, #slots.empty do\nif turtle.getItemCount(slots.empty[i]) ==0 then\nfree=true\nbreak\nend\nend\nfor i=1, #slots.build do\nfillBuild(slots.build[i])end\nfor i=1, #slots.fuel do\nfillFuel(slots.fuel[i])end\nfor i=1, #slots.empty do\nif turtle.getItemCount(slots.empty[i]) ==0 then\nfree=true\nbreak\nend\nend\nif not free and trashList then\nfree=makeSpace()end\nreturn free\nend\nlocal gotoChest=false\nstartMode=function(mode,position)move.mode.name=mode\nmove.mode.data=position\nsave()if mode==\"fuel\"then\nlabel_mode.text=\"Fuel is to low!\\nGo back to start and request fuel.\"label_mode:recalculate()label_mode:repaint(\"this\")goToDestination(vector.new(move.pos.x,0,way.z))goToDestination(way)label_mode.text=\"Fuel is to low!\\nPlease insert enough fuel.\"label_mode:recalculate()label_mode:repaint(\"this\")repeat\nos.pullEvent(\"turtle_inventory\")until checkFuelLevel(getNeededFuelLevel(start,move.base) +40)elseif mode==\"chest\"then\nlabel_mode.text=\"Chest is required to empty inventory!\\nGo back to start and request chest.\"label_mode:recalculate()label_mode:repaint(\"this\")goToDestination(vector.new(move.pos.x,0,way.z))goToDestination(way)label_mode.text=\"Chest is required to empty inventory!\\nPlease insert enough chests.\"label_mode:recalculate()label_mode:repaint(\"this\")repeat\nos.pullEvent(\"turtle_inventory\")until checkChest()elseif mode==\"torch\"then\nlabel_mode.text=\"Torches are required to light the way!\\nGo back to start and request torches.\"label_mode:recalculate()label_mode:repaint(\"this\")goToDestination(vector.new(move.pos.x,0,way.z))goToDestination(way)label_mode.text=\"Torches are required to light the way!\\nPlease insert enough torches.\"label_mode:recalculate()label_mode:repaint(\"this\")repeat\nos.pullEvent(\"turtle_inventory\")until checkChest()elseif mode==\"build\"then\nlabel_mode.text=\"Blocks are required to build the way!\\nGo back to start and request blocks.\"label_mode:recalculate()label_mode:repaint(\"this\")goToDestination(vector.new(move.pos.x,0,way.z))goToDestination(way)label_mode.text=\"Blocks are required to build the way!\\nPlease insert enough blocks.\"label_mode:recalculate()label_mode:repaint(\"this\")repeat\nos.pullEvent(\"turtle_inventory\")until checkChest(6)elseif mode==\"wall\"then\nlabel_mode.text=\"A safe path is being built.\"label_mode:recalculate()label_mode:repaint(\"this\")if not(move.pos.x==move.base.x and move.pos.y==0 and move.pos.z>=0 and move.pos.z<=1)then\ngoToDestination(vector.new(move.base.x,0,move.pos.z))goToDestination(vector.new(move.base.x,0,math.min(1,math.max(0,move.pos.z))))end\nif move.facing.x== -1 then\nturn(4)elseif move.facing.x==1 then\nturn(2)end\nselectBuild()turtle.place()turtle.move.turnRight(update)turtle.move.turnRight(update)selectBuild()turtle.place()if move.pos.z==0 then\nselectBuild()turtle.placeDown()goToDestination(move.pos+vector.up)selectBuild()turtle.placeUp()else\nselectBuild()turtle.placeUp()goToDestination(move.pos+vector.down)selectBuild()turtle.placeDown()end\nselectBuild()turtle.place()turtle.move.turnRight(update)turtle.move.turnRight(update)selectBuild()turtle.place()elseif mode==\"light\"then\nlabel_mode.text=\"Path is being illuminated.\"label_mode:recalculate()label_mode:repaint(\"this\")placeTorch=false\ngoToDestination(move.base+way)selectTorch()if not turtle.placeDown()then\nplaceTorch=true\nend\nelseif mode==\"clear\"and slots.enderChest then\nlabel_mode.text=\"Inventory gets cleared.\"label_mode:recalculate()label_mode:repaint(\"this\")if inspect(2)then\nif addToUndone(getConnected(position,2))then\nmove.detected=move.detected+1\nend\nlabel_detected.text=text_detected..move.detected\nlabel_detected:recalculate()label_detected:repaint(\"this\")end\nturtle.digUp()turtle.select(slots.enderChest)turtle.placeUp()for i=1, #slots.empty do\nlocal slot=slots.empty[i]turtle.select(slot)turtle.dropUp()end\nturtle.select(slots.enderChest)turtle.digUp()elseif mode==\"clear\"then\nlabel_mode.text=\"Inventory gets cleared.\"label_mode:recalculate()label_mode:repaint(\"this\")goToDestination(move.base)turn(3)if turtle.inspect()then\nturtle.dig()placeTorch=true\nend\nselectChest()turtle.place()for i=1, #slots.empty do\nlocal slot=slots.empty[i]if turtle.getItemCount(slot) >0 then\nturtle.select(slot)turtle.drop()end\nend\nend\nturtle.select(1)label_mode.text=\"Move to resume position.\"label_mode:recalculate()label_mode:repaint(\"this\")if move.pos~=position then\ngoToDestination(vector.new(position.x,0,way.z))goToDestination(position)end\nlabel_mode.text=\"Continue Mining.\"label_mode:recalculate()label_mode:repaint(\"this\")move.mode.name=nil\nmove.mode.data=nil\nend\nlocal function checkSurrounding()label_mode.text=\"Inspect surrounding blocks.\"label_mode:recalculate()label_mode:repaint(\"this\")local near= {}for i=1,6 do\nlocal add=true\nlocal v=getConnected(move.pos,i)for j=1, #move.done do\nif move.done[j] ==v then\nadd=false\nbreak\nend\nend\nif add then\ntable.insert(near,v)end\nend\nwhile#near>0 do\ntable.orderComplex(near,function(v)local dir=getDir(v-move.pos)if dir.x>0 then\nreturn 1\nelseif dir.x<0 then\nreturn 3\nelseif dir.y~=0 then\nreturn 2\nelse\nreturn 1\nend\nend)local v=near[1]local dir=getDir(v-move.pos)if dir.z>0 then\nif inspect(2)then\nif addToUndone(v)then\nmove.detected=move.detected+1\nend\nend\nelseif dir.z<0 then\nif inspect(3)then\nif addToUndone(v)then\nmove.detected=move.detected+1\nend\nend\nelse\nif dir.x<0 then\nturtle.move.turnRight(update)turtle.move.turnRight(update)elseif dir.y>0 then\nturtle.move.turnRight(update)elseif dir.y<0 then\nturtle.move.turnLeft(update)end\nif inspect(1)then\nif addToUndone(v)then\nmove.detected=move.detected+1\nend\nend\nend\nlabel_detected.text=text_detected..move.detected\nlabel_detected:recalculate()label_detected:repaint(\"this\")table.remove(near,1)end\nend\nlocal function iteration()while#move.undone>0 do\norderVectorList()local current=move.undone[1]table.remove(move.undone,1)if not(current==move.pos)then\nif not checkSpace()then\nstartMode(\"clear\",move.pos)end\nlabel_mode.text=\"Mine blocks.\"label_mode:recalculate()label_mode:repaint(\"this\")goToDestination(current)end\ncheckSurrounding()end\nclearVectorLists()end\nif#move.done==0 then\ntable.insert(move.done,getConnected(move.pos, -1))table.insert(move.done,move.pos:copy())move.base:set(move.base.x+1,move.base.y,move.base.z)addToUndone(move.base)addToUndone(move.base+vector.up)iteration()elseif move.mode.name then\nstartMode(move.mode.name,move.mode.data)else\ncheckSurrounding()end\nif#move.undone>0 then\niteration()end\nwhile move.distance<data.length or data.length==0 do\nif#slots.build>0 then\niteration()if not move.mode.name and not checkFuelLevel(getNeededFuelLevel(start,move.pos) +3)then\nstartMode(\"fuel\",move.pos)end\nif not checkBuild(6)then\nstartMode(\"build\",move.pos)end\nstartMode(\"wall\",move.pos)if#slots.torch>0 and(placeTorch or(move.base.x-1) %12==0)then\nstartMode(\"light\",move.pos)end\nturtle.select(1)move.base:set(move.base.x+1,move.base.y,move.base.z)addToUndone(move.base)addToUndone(move.base+vector.up)else\niteration()local v=vector.new(move.base.x+1,move.base.y,move.base.z)while#move.undone==0 do\naddToUndone(v)addToUndone(v+vector.up)v:set(v.x+1)end\nmove.base:set(v.x-1,v.y,v.z)end\nend\nlabel_mode.text=\"Finished Job!\\nGo back to start.\"label_mode:recalculate()label_mode:repaint(\"this\")goToDestination(way)goToDestination(start)turn(1)makeSpace()startMode(\"clear\",move.pos)deleteFiles()end\nlocal checkPause=true\nlocal function waitForPause()while checkPause or inMove==true do\ncoroutine.yield()end\nmove.pause=not move.pause\ncheckPause=true\nsave()if move.pause==true then\nbutton_pause.text=\"Resume\"button_pause:recalculate()button_pause:repaint(\"this\")else\nbutton_pause.text=\"Pause\"button_pause:recalculate()button_pause:repaint(\"this\")end\nend\nfunction button_pause:onClick(event)checkPause=false\nend\nfunction button_stop:onClick(event)data.length= -1\nbutton_pause:changeMode(2,true)button_stop:changeMode(2,true)button_exit:changeMode(2,true)end\nfunction button_exit:onClick(event)deleteFiles()input:exit()end\nlocal function execute()input:eventLoop({[term] =drawer.event})end\nwhile input._exit==false do\nif move.pause then\nparallel.waitForAny(waitForPause,execute)else\nlocal exit=parallel.waitForAny(mine,waitForPause,execute)if exit==1 then\nbutton_pause:changeMode(2,true)button_stop:changeMode(2,true)button_exit:changeMode(1,true)execute()end\nend\nend\n",["os/programs/stripMiner/main.lua"] = "ui.input.term=term\nlocal _x,_y,_w,_h=1,1,term.getSize()local success,set=fs.doFile(\"os/programs/stripMiner/data/settings.set\")set=set or{}set.length=set.length or 0\nset.searchWhiteList=set.searchWhiteList or \"White List\"if set.pathSearchList and not fs.exists(set.pathSearchList)then\nset.pathSearchList=nil\nend\nset.trashWhiteList=set.trashWhiteList or \"White List\"if set.pathTrashList and not fs.exists(set.pathTrashList)then\nset.pathTrashList=nil\nend\nset.slots=set.slots or{}set.slots[1] =set.slots[1]or 1\nset.slots[2] =set.slots[2]or 2\nset.slots[3] =set.slots[3]or 3\nset.slots[4] =set.slots[4]or 4\nfor i=5,16 do\nset.slots[i] =set.slots[i]or 0\nend\nlocal input=ui.input.new()local drawer=ui.drawer.new(input,_x,_y,_w,_h)for i=1,_w*_h do\nif i<=_w or i>_w* (_h-1)then\ndrawer.buffer.text[i] =\" \"drawer.buffer.textColor[i] =colors.green\ndrawer.buffer.textBackgroundColor[i] =colors.green\nelse\ndrawer.buffer.text[i] =\" \"drawer.buffer.textColor[i] =colors.white\ndrawer.buffer.textBackgroundColor[i] =colors.white\nend\nend\nlocal label_title=ui.label.new(drawer,\"Strip Miner\",theme.label1,_x,_y,_w-3,2)local button_exit=ui.button.new(drawer,\"<\",theme.button2,_x+_w-3,_y,3,1)local label_length=ui.label.new(drawer,\"Length: \",theme.label2,_x,_y+1,8,1)local iField_length=ui.inputField.new(drawer,nil,tostring(set.length),false,theme.iField2,_x+8,_y+1,_w-8,1)local label_searchList=ui.label.new(drawer,\"Search List\",theme.label2,_x,_y+3,12,1)local button_searchList=ui.button.new(drawer,set.searchWhiteList,theme.button1,13,_y+3,math.floor(_w/2),1)local button_pathSearchList=ui.button.new(drawer,\"Path\",theme.button1,_x,_y+4,6,1)local label_pathSearchList=ui.label.new(drawer,set.pathSearchList or \"No Selection\",theme.label2,_x+7,_y+4,_w-7,1)if not set.pathSearchList then\nlabel_pathSearchList:changeMode(2,true)end\nlocal label_trashList=ui.label.new(drawer,\"Trash List\",theme.label2,_x,_y+5,12,1)local button_trashList=ui.button.new(drawer,set.trashWhiteList,theme.button1,13,_y+5,math.floor(_w/2),1)local button_pathTrashList=ui.button.new(drawer,\"Path\",theme.button1,_x,_y+6,6,1)local label_pathTrashList=ui.label.new(drawer,set.pathTrashList or \"No Selection\",theme.label2,_x+7,_y+6,_w-7,1)if not set.pathTrashList then\nlabel_pathTrashList:changeMode(2,true)end\nlocal text_slot=ui.text.new(drawer,\"Slots:\\n1: Chest 2: Fuel\\n3: Build 4: Torch\\n5: Ender Chest\",theme.label2,_x,_y+8,26,4)local list_slots= {}for i=1,16 do\nlocal x=_x+26+ ((i-1) %4) *3\nlocal y=_y+8+math.floor((i-1) /4)local button_slot=ui.button.new(drawer,tostring(set.slots[i]),theme.button1,x,y,3,1)table.insert(list_slots,button_slot)end\nlocal button_start=ui.button.new(drawer,\"Start\",theme.button1,_x+_w-7,_h,7,1)local button_saveSettings=ui.button.new(drawer,\"Save Settings\",theme.button1,_x,_h,15,1)local group_mainMenu=drawer.selectionManager:addNewGroup()group_mainMenu.current=button_exit\nlocal group_mainUp=drawer.selectionManager:addNewGroup()group_mainUp.current=iField_length\nlocal group_slot=drawer.selectionManager:addNewGroup()group_slot.current=list_slots[1]local group_mainDown=drawer.selectionManager:addNewGroup()group_mainDown.current=button_start\ngroup_mainMenu.previous=group_slot\ngroup_mainUp.previous=group_mainMenu\ngroup_slot.previous=group_mainUp\ngroup_mainDown.previous=group_slot\ngroup_mainMenu.next=group_mainUp\ngroup_mainUp.next=group_slot\ngroup_slot.next=group_mainDown\ngroup_mainDown.next=group_mainMenu\ngroup_mainMenu:addElement(button_exit,nil,nil,nil,iField_length)group_mainUp:addElement(iField_length,nil,group_mainMenu,nil,button_searchList)group_mainUp:addElement(button_searchList,nil,iField_length,nil,button_pathSearchList)group_mainUp:addElement(button_pathSearchList,nil,button_searchList,nil,button_trashList)group_mainUp:addElement(button_trashList,nil,button_pathSearchList,nil,button_pathTrashList)group_mainUp:addElement(button_pathTrashList,nil,button_trashList,nil,group_slot)group_mainDown:addElement(button_saveSettings,nil,group_slot,button_start,nil)group_mainDown:addElement(button_start,button_saveSettings,group_slot,nil,nil)for i=1,16,4 do\ngroup_slot:addElement(list_slots[i],nil,list_slots[i-4],list_slots[i+1],list_slots[i+4])group_slot:addElement(list_slots[i+1],list_slots[i],list_slots[i-3],list_slots[i+2],list_slots[i+5])group_slot:addElement(list_slots[i+2],list_slots[i+1],list_slots[i-2],list_slots[i+3],list_slots[i+6])group_slot:addElement(list_slots[i+3],list_slots[i+2],list_slots[i-1],nil,list_slots[i+7])end\nfor i=1,4 do\nlist_slots[i].select.up=button_pathTrashList\nend\nfor i=13,16 do\nlist_slots[i].select.down=group_mainDown\nend\nlocal function updateStart()local possible=false\nlocal t= {}for i=1,5 do\nt[i] =0\nend\nfor i=1,16 do\nlocal number=tonumber(list_slots[i].text)if number>0 then\nt[number] =t[number] +1\nend\nend\nif((t[1] >0 and t[5] ==0)or(t[5] ==1 and t[1] ==0))and(t[3] >0 or t[4] ==0)and((t[2] >0) == (turtle.getFuelLimit() >0))and set.pathSearchList then\npossible=true\nend\nif possible then\nbutton_start:changeMode(1,true)group_mainDown.current=button_start\nelse\nbutton_start:changeMode(2,true)group_mainDown.current=button_saveSettings\nend\nend\nupdateStart()function button_exit:onClick(event)input:exit()end\nfunction iField_length:onTextEdit(event, ...)if event==\"char\"or event==\"text\"or event==\"paste\"then\nlocal text= ...text=text:gsub(\"[^%d]\",\"\")set.length=tonumber(self:combinedText(text))return text\nend\nend\nfunction button_searchList:onClick(event)if self.text==\"White List\"then\nself.text=\"Black List\"elseif self.text==\"Black List\"then\nself.text=\"White List\"end\nset.searchWhiteList=self.text\nupdateStart()self:recalculate()self:repaint(\"this\")button_start:repaint(\"this\")end\nfunction button_pathSearchList:onClick(event)input:callFunction(function()local file=callfile(\"os/sys/explorer/main.lua\", {select=event.name~=\"mouse_up\",mode=\"select_one\",edit=false,type=\"list\"})if file then\nset.pathSearchList=file\nlabel_pathSearchList.text=set.pathSearchList\nlabel_pathSearchList:recalculate()updateStart()end\ndrawer:draw()end)end\nfunction button_trashList:onClick(event)if self.text==\"White List\"then\nself.text=\"Black List\"elseif self.text==\"Black List\"then\nself.text=\"White List\"end\nset.trashWhiteList=self.text\nupdateStart()self:recalculate()self:repaint(\"this\")button_start:repaint(\"this\")end\nfunction button_pathTrashList:onClick(event)input:callFunction(function()local file=callfile(\"os/sys/explorer/main.lua\", {select=event.name~=\"mouse_up\",mode=\"select_one\",edit=false,type=\"list\"})if file then\nset.pathTrashList=file\nlabel_pathTrashList.text=set.pathTrashList\nlabel_pathTrashList:recalculate()end\ndrawer:draw()end)end\nfor i=1,16 do\nlocal element=list_slots[i]function element:onClick(event)local positive=true\nif(event.name==\"mouse_up\"and event.param1==2)or(event.name==\"key_up\"and event.param1==29)then\npositive=false\nend\nlocal number=tonumber(self.text)or 0\nif positive then\nnumber=number+1\nif number>5 then\nnumber=0\nend\nelse\nnumber=number-1\nif number<0 then\nnumber=5\nend\nend\nset.slots[i] =number\nself.text=tostring(number)updateStart()button_start:repaint(\"this\")self:recalculate()if not self._inAnimation then\nself:repaint(\"this\")end\nend\nend\nfunction button_saveSettings:onClick(event)table.save(set,\"os/programs/stripMiner/data/settings.set\")end\nfunction button_start:onClick(event)input:callFunction(function()term.clear()fs.delete(\"os/programs/stripMiner/data/move.set\")fs.delete(\"os/programs/stripMiner/data/data.set\")table.save(set,\"os/programs/stripMiner/data/data.set\")local file=fs.open(\"os/startup/50-stripMiner.lua\",\"w\")file.write('dofile(\"os/programs/stripMiner/mine.lua\")')file.close()dofile(\"os/programs/stripMiner/mine.lua\")drawer:draw()end)end\ndrawer.selectionManager:select(group_mainUp,\"code\",1)drawer:draw()input:eventLoop({[term] =drawer.event})\n" }) do
2local s, e = key:find(".*/")
3if s then
4local path = key:sub(s, e)
5if not fs.exists(path) then
6fs.makeDir(path)
7end
8end
9local file = io.open(key, "w+")
10file:write(value)
11file:close()
12end
13callfile("os/sys/browser/require.lua","Turtle Move API")