Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --this is a quarry program that uses external inventories, as well as deposit chests
- --it does not refuel automatically, however
- local logFile=true
- local chestWhitelist={
- ["minecraft:chest"]=true
- }
- local slotBlacklist={
- [16]=true
- }
- --"Unbreakable block detected"
- local argv={...}
- local pos={x=0,y=0,z=0,d=2} --relative (start facing "south")
- local function log(message,file)
- io.write("{")
- io.write(pos.x..",")
- io.write(pos.y..",")
- io.write(pos.z..";")
- io.write(pos.d.."}: ")
- io.write(message.."\n")
- if file then
- file:write("{")
- file:write(pos.x..",")
- file:write(pos.y..",")
- file:write(pos.z..";")
- file:write(pos.d.."}: ")
- file:write(message.."\n")
- end
- end
- local function turnTo(d,od)
- pos.d=od or pos.d
- if d<0 or d>3 then return true end
- local turnAction,dMod=turtle.turnRight,1
- local lTurnTab={["03"]=true,["10"]=true,["21"]=true,["32"]=true} --lol
- if lTurnTab[tostring(pos.d)..tostring(d)] then
- turnAction,dMod=turtle.turnLeft,-1
- end
- while pos.d ~= d do
- turnAction()
- pos.d=(pos.d+dMod)%4
- if pos.d < 0 then pos.d=pos.d+4 end
- end
- return true
- end
- local function move0(moveAction,msgA,digAction,msgD,file)
- local s,e=digAction()
- log(msgD.."; ("..tostring(e)..")",file)
- if tostring(e) == "Unbreakable block detected" then return s,e end
- s,e=moveAction()
- log(msgA.."; ("..tostring(e)..")",file)
- if not s then os.sleep(0.5) end
- return s,e
- end
- local function moveA(md,doRepeat,file)
- turnTo(md)
- local s,e
- if md==4 then --down -y
- s,e=move0(turtle.down,"down",turtle.digDown,"digDown",file)
- if tostring(e) == "Unbreakable block detected" then return s,e end
- while doRepeat and not s do
- s,e=move0(turtle.down,"down",turtle.digDown,"digDown",file)
- end
- if s then pos.y=pos.y-1 end
- elseif md==5 then --up +y
- s,e=move0(turtle.up,"up",turtle.digUp,"digUp",file)
- if tostring(e) == "Unbreakable block detected" then return s,e end
- while doRepeat and not s do
- s,e=move0(turtle.up,"up",turtle.digUp,"digUp",file)
- end
- if s then pos.y=pos.y+1 end
- elseif md==0 then --north -z
- s,e=move0(turtle.forward,"north",turtle.dig,"digNorth",file)
- if tostring(e) == "Unbreakable block detected" then return s,e end
- while doRepeat and not s do
- s,e=move0(turtle.forward,"north",turtle.dig,"digNorth",file)
- end
- if s then pos.z=pos.z-1 end
- elseif md==1 then --east +x
- s,e=move0(turtle.forward,"east",turtle.dig,"digEast",file)
- if tostring(e) == "Unbreakable block detected" then return s,e end
- while doRepeat and not s do
- s,e=move0(turtle.forward,"east",turtle.dig,"digEast",file)
- end
- if s then pos.x=pos.x+1 end
- elseif md==2 then --south +z
- s,e=move0(turtle.forward,"south",turtle.dig,"digSouth",file)
- if tostring(e) == "Unbreakable block detected" then return s,e end
- while doRepeat and not s do
- s,e=move0(turtle.forward,"south",turtle.dig,"digSouth",file)
- end
- if s then pos.z=pos.z+1 end
- elseif md==3 then --west -x
- s,e=move0(turtle.forward,"west",turtle.dig,"digWest",file)
- if tostring(e) == "Unbreakable block detected" then return s,e end
- while doRepeat and not s do
- s,e=move0(turtle.forward,"west",turtle.dig,"digWest",file)
- end
- if s then pos.x=pos.x-1 end
- end
- return s,e
- end
- local function moveB(md,amount,doRepeat,file)
- local s,e
- if amount < 0 then
- if md==4 then md=5
- elseif md==5 then md=4
- else md=(md+2)%4 end
- amount=-amount
- end
- for i=1,amount do
- s,e=moveA(md,doRepeat,file)
- if tostring(e) == "Unbreakable block detected" then return s,e end
- if not s and not doRepeat then break end
- end
- return s,e
- end
- local function getOffset(posA,posB)
- posB=posB or pos
- local offset={}
- offset.x=posA.x-posB.x
- offset.y=posA.y-posB.y
- offset.z=posA.z-posB.z
- return offset
- end
- local function moveC(newPos,oldPos,doRepeat,file)
- if oldPos then
- pos.x=oldPos.x
- pos.y=oldPos.y
- pos.z=oldPos.z
- end
- local offset=getOffset(newPos)
- local s,e=moveB(5,offset.y,doRepeat,file) --y
- if s then
- s,e=moveB(1,offset.x,doRepeat,file) --x
- end
- if s then
- s,e=moveB(2,offset.z,doRepeat,file) --z
- end
- return s,e
- end
- local function isChest(whitelist)
- local s=false
- local si,t=turtle.inspect()
- if si and whitelist[t.name] then s=true end
- return s
- end
- local function freeSlots(blacklist)
- local count=16
- for i=1,16 do
- if not blacklist[i] and turtle.getItemCount(i) > 0 then
- count=count-1
- end
- end
- return count
- end
- local function withdrawInt(slot,doRepeat,file)
- log("withdrawing from slot "..tostring(slot).."...",file)
- local s,e=turtle.digUp()
- while doRepeat and tostring(e) ~= "Nothing to dig here" do
- s,e=turtle.digUp()
- end
- s=tostring(e)=="Nothing to dig here"
- for i=1,16 do if i~=slot then
- if turtle.getItemCount(i) == 0 then
- turtle.select(i)
- s,e=turtle.suckUp()
- if not s then break end
- end
- end end
- return s,e
- end
- local function depositChest(chestsInt,doRepeat,file)
- return true
- end
- local function depositAll(chestsExt,chestsInt,doRepeat,file)
- local ms,me=moveC({x=0,y=0,z=0},nil,doRepeat)
- turnTo(0)
- local chestCount,temp=0,true
- log("checking # of chests...",file)
- while true do
- temp=isChest(chestsExt)
- if temp then chestCount=chestCount+1
- else break end
- ms,me=moveA(5,doRepeat)
- end
- ms,me=moveC({x=0,y=0,z=0},nil,doRepeat)
- if chestCount == 0 then
- log("no chests found!")
- return nil,"No chests found"
- end
- --
- ms,me=moveC({x=0,y=0,z=0},nil,doRepeat)
- turnTo(2)
- return true
- end
- --tbd detect for bedrock
- --depositAll(chestWhitelist,slotBlacklist,true,nil)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement