Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- --slot id:
- --1 = mining well, 2=tesseract wtih shiny dust, 3 pipes
- print("Dont forget to shiny dust the tesseract to retain their setting upon destroy");
- local zz=turtle
- local args = {...}
- local currentX=0 -- hoz
- local currentY=0 -- height
- local currentZ=0 -- depth
- local isUndroppable={};
- function setCurrentItemsUndroppable()
- isUndroppable={};
- for undroppableItems=1,16 do
- local data = turtle.getItemDetail(undroppableItems);
- if data then
- isUndroppable[data.name..data.damage]=true;
- end
- end
- end
- local memorizedItemInventory={};
- function memorizeItemSlot()
- memorizedItemInventory={};
- for slotIDMemory=1,16 do
- local data = turtle.getItemDetail(slotIDMemory);
- if data then
- memorizedItemInventory[data.name..data.damage]=slotIDMemory;
- end
- end
- end
- function sortInventoryByMemory()
- for slotIDMemory=1,16 do
- local data = turtle.getItemDetail(slotIDMemory);
- if data and memorizedItemInventory[data.name..data.damage] > 0 then
- turtle.select(slotIDMemory);
- turtle.transferTo(memorizedItemInventory[data.name..data.damage]);
- end
- end
- end
- function unloadSystems()
- placeAt(1,0,0,1);--well
- turnLeft();
- placeAt(1,0,0,1);--well
- turnLeft();
- placeAt(1,0,0,1);--well
- turnLeft();
- placeAt(1,0,0,1);--well
- turnLeft();
- placeDownAt(1,0,0,1);--bottom well
- goToCord(2,0,0);--turtle resting spot
- placeDownAt(2,0,0,2);--tesseract
- end
- function loadSystems()
- end
- function dumpAllItems()
- for i=1,16 do
- if true then
- local data = turtle.getItemDetail(i);
- if data and not isUndroppable[data.name..data.damage] then
- goToCord(2,0,0);
- repeat
- turtle.select(i);
- until turtle.dropDown();
- end
- end
- end
- end
- function dumpAllItemsAndReturnToWork()
- local rememberCordX=currentX;
- local rememberCordY=currentY;
- local rememberCordZ=currentZ;
- for iDropReturn=1,16 do
- if true then
- local data = turtle.getItemDetail(iDropReturn);
- if data and not isUndroppable[data.name..data.damage] then
- print("trying at "..iDropReturn,currentX,currentY,currentZ);
- goToCord(2,0,0);
- repeat
- turtle.select(iDropReturn);
- until turtle.dropDown();
- end
- end
- end
- goToCord(rememberCordY,rememberCordX,rememberCordZ);
- end
- function isStillWorking()
- return peripheral.call("bottom","hasWork")
- end
- local currRad=1 -- 0 is the right, 1 is default (original direction), 2 is the left, 3 is the back
- local cacheSlot = {}
- function place(slotID)
- zz.select(slotID)
- if zz.getItemCount()>0 then
- return zz.place()
- end
- return false
- end
- function placeUp(slotID)
- zz.select(slotID)
- if zz.getItemCount()>0 then
- return zz.placeUp()
- end
- return false
- end
- function placeDown(slotID)
- zz.select(slotID)
- if zz.getItemCount()>0 then
- return zz.placeDown()
- end
- return false
- end
- function refuel(amount)
- while zz.getFuelLevel()<=math.abs(amount) do
- zz.select(16)
- zz.refuel(1)
- print("Refueling")
- end
- end
- function turnRight()
- while zz.turnRight() do
- currRad=(currRad-1)%4
- break
- end
- end
- function turnLeft()
- while zz.turnLeft() do
- currRad=(currRad+1)%4
- break
- end
- end
- function turnToRad(r)
- if currRad==r then
- return true
- end
- while currRad~=r do
- if currRad>r then
- turnRight()
- elseif currRad<r then
- turnLeft()
- end
- end
- end
- function alertForProblem(stringCauseOfProblem)
- zz.turnRight()
- zz.turnRight()
- zz.turnRight()
- zz.turnRight()
- print(stringCauseOfProblem)
- end
- function moveByX(ox)
- local x=currentX+ox
- turnToRad(0)
- refuel(ox)
- while ox~=0 do
- if ox<0 then
- if zz.back() then
- ox=ox+1
- currentX=currentX-1
- else
- alertForProblem("can not move - check fuel or obstacle")
- moveByX(ox)
- break
- end
- else
- if zz.forward() then
- ox=ox-1
- currentX=currentX+1
- else
- alertForProblem("can not move - check fuel or obstacle")
- moveByX(ox)
- break
- end
- end
- end
- end
- function moveByZ(oz)
- local z=currentZ+oz
- turnToRad(1)
- refuel(oz)
- while oz~=0 do
- if oz<0 then
- if zz.back() then
- oz=oz+1
- currentZ=currentZ-1
- else
- alertForProblem("can not move - check fuel or obstacle")
- moveByZ(oz)
- break
- end
- else
- if zz.forward() then
- oz=oz-1
- currentZ=currentZ+1
- else
- alertForProblem("can not move - check fuel or obstacle")
- moveByZ(oz)
- break
- end
- end
- end
- end
- function moveByY(oy)
- local y=currentY+oy
- refuel(oy)
- while oy~=0 do
- if oy<0 then
- if zz.down() then
- oy=oy+1
- currentY=currentY-1
- else
- alertForProblem("can not move down - check fuel or obstacle")
- moveByY(oy)
- break
- end
- else
- if zz.up() then
- oy=oy-1
- currentY=currentY+1
- else
- alertForProblem("can not move up - check fuel or obstacle")
- moveByY(oy)
- break
- end
- end
- end
- end
- function goToCord(y,x,z)
- local differenceX=x-(currentX)
- local differenceY=y-currentY
- local differenceZ=z-currentZ
- if differenceX~=0 then moveByX(differenceX) end
- if differenceY~=0 then moveByY(differenceY) end
- if differenceZ~=0 then moveByZ(differenceZ) end
- end
- function placeAt(y,x,z,slotID)
- goToCord(y,x,z)
- if place(slotID) then return true
- else
- alertForProblem("can not place ahead - must be air ahead or do I have a material to place")
- placeAt(y,x,z,slotID)
- end
- end
- function placeUpAt(y,x,z,slotID)
- goToCord(y,x,z)
- if placeUp(slotID) then return true
- else
- alertForProblem("can not place up - must be air ahead or do I have a material to place")
- placeUpAt(y,x,z,slotID)
- end
- end
- function placeDownAt(y,x,z,slotID)
- goToCord(y,x,z)
- if placeDown(slotID) then return true
- else
- alertForProblem("can not place down - must be air ahead or do I have a material to place")
- placeUpAt(y,x,z,slotID)
- end
- end
- local repeatUntil=1;
- setCurrentItemsUndroppable();
- memorizeItemSlot();
- if (#args==1) and tonumber(args[1])>1 then
- repeatUntil=tonumber(args[1]);
- end
- for zd=1,repeatUntil do
- unloadSystems();
- turtle.select(4);
- goToCord(2,1,0);
- repeat
- os.sleep(1);
- until not isStillWorking();
- --finished work, lets pack it up here
- dumpAllItemsAndReturnToWork();
- turtle.select(1);
- turtle.digDown();
- goToCord(2,0,1);
- repeat
- os.sleep(1);
- until not isStillWorking();
- dumpAllItemsAndReturnToWork();
- turtle.select(1);
- turtle.digDown();
- goToCord(2,-1,0);
- repeat
- os.sleep(1);
- until not isStillWorking();
- dumpAllItemsAndReturnToWork();
- turtle.select(1);
- turtle.digDown();
- goToCord(2,0,-1);
- repeat
- os.sleep(1);
- until not isStillWorking();
- dumpAllItemsAndReturnToWork();
- turtle.select(1);
- turtle.digDown();
- goToCord(2,0,0);
- turtle.select(2);
- turtle.digDown();
- goToCord(1,0,0);
- turtle.select(1);
- turtle.digDown();--destroying bottom well
- goToCord(0,0,0);
- if repeatUntil>1 then
- local moveForward=0;
- repeat
- if turtle.forward() then moveForward=moveForward+1; end
- until moveForward==3;
- end
- end
- print("done");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement