Advertisement
Kitomas

falloutServerTurtle

Dec 5th, 2022 (edited)
1,484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.74 KB | Gaming | 0 0
  1. --this is a quarry program that uses external inventories, as well as deposit chests
  2. --it does not refuel automatically, however
  3. local logFile=true
  4. local chestWhitelist={
  5.   ["minecraft:chest"]=true
  6. }
  7. local slotBlacklist={
  8.   [16]=true
  9. }
  10. --"Unbreakable block detected"
  11. local argv={...}
  12. local pos={x=0,y=0,z=0,d=2} --relative (start facing "south")
  13. local function log(message,file)
  14.   io.write("{")
  15.   io.write(pos.x..",")
  16.   io.write(pos.y..",")
  17.   io.write(pos.z..";")
  18.   io.write(pos.d.."}: ")
  19.   io.write(message.."\n")
  20.   if file then
  21.     file:write("{")
  22.     file:write(pos.x..",")
  23.     file:write(pos.y..",")
  24.     file:write(pos.z..";")
  25.     file:write(pos.d.."}: ")
  26.     file:write(message.."\n")
  27.   end
  28. end
  29. local function turnTo(d,od)
  30.   pos.d=od or pos.d
  31.   if d<0 or d>3 then return true end
  32.   local turnAction,dMod=turtle.turnRight,1
  33.   local lTurnTab={["03"]=true,["10"]=true,["21"]=true,["32"]=true} --lol
  34.   if lTurnTab[tostring(pos.d)..tostring(d)] then
  35.     turnAction,dMod=turtle.turnLeft,-1
  36.   end
  37.   while pos.d ~= d do
  38.     turnAction()
  39.     pos.d=(pos.d+dMod)%4
  40.     if pos.d < 0 then pos.d=pos.d+4 end
  41.   end
  42.   return true
  43. end
  44. local function move0(moveAction,msgA,digAction,msgD,file)
  45.   local s,e=digAction()
  46.   log(msgD.."; ("..tostring(e)..")",file)
  47.   if tostring(e) == "Unbreakable block detected" then return s,e end
  48.   s,e=moveAction()
  49.   log(msgA.."; ("..tostring(e)..")",file)
  50.   if not s then os.sleep(0.5) end
  51.   return s,e
  52. end
  53. local function moveA(md,doRepeat,file)
  54.   turnTo(md)
  55.   local s,e
  56.   if md==4 then      --down -y
  57.     s,e=move0(turtle.down,"down",turtle.digDown,"digDown",file)
  58.     if tostring(e) == "Unbreakable block detected" then return s,e end
  59.     while doRepeat and not s do
  60.       s,e=move0(turtle.down,"down",turtle.digDown,"digDown",file)
  61.     end
  62.     if s then pos.y=pos.y-1 end
  63.   elseif md==5 then  --up +y
  64.     s,e=move0(turtle.up,"up",turtle.digUp,"digUp",file)
  65.     if tostring(e) == "Unbreakable block detected" then return s,e end
  66.     while doRepeat and not s do
  67.       s,e=move0(turtle.up,"up",turtle.digUp,"digUp",file)
  68.     end
  69.     if s then pos.y=pos.y+1 end
  70.   elseif md==0 then --north -z
  71.     s,e=move0(turtle.forward,"north",turtle.dig,"digNorth",file)
  72.     if tostring(e) == "Unbreakable block detected" then return s,e end
  73.     while doRepeat and not s do
  74.       s,e=move0(turtle.forward,"north",turtle.dig,"digNorth",file)
  75.     end
  76.     if s then pos.z=pos.z-1 end
  77.   elseif md==1 then --east +x
  78.     s,e=move0(turtle.forward,"east",turtle.dig,"digEast",file)
  79.     if tostring(e) == "Unbreakable block detected" then return s,e end
  80.     while doRepeat and not s do
  81.       s,e=move0(turtle.forward,"east",turtle.dig,"digEast",file)
  82.     end
  83.     if s then pos.x=pos.x+1 end
  84.   elseif md==2 then --south +z
  85.     s,e=move0(turtle.forward,"south",turtle.dig,"digSouth",file)
  86.     if tostring(e) == "Unbreakable block detected" then return s,e end
  87.     while doRepeat and not s do
  88.       s,e=move0(turtle.forward,"south",turtle.dig,"digSouth",file)
  89.     end
  90.     if s then pos.z=pos.z+1 end
  91.   elseif md==3 then --west -x
  92.     s,e=move0(turtle.forward,"west",turtle.dig,"digWest",file)
  93.     if tostring(e) == "Unbreakable block detected" then return s,e end
  94.     while doRepeat and not s do
  95.       s,e=move0(turtle.forward,"west",turtle.dig,"digWest",file)
  96.     end
  97.     if s then pos.x=pos.x-1 end
  98.   end
  99.   return s,e
  100. end
  101. local function moveB(md,amount,doRepeat,file)
  102.   local s,e
  103.   if amount < 0 then
  104.     if md==4 then md=5
  105.     elseif md==5 then md=4
  106.     else md=(md+2)%4 end
  107.     amount=-amount
  108.   end
  109.   for i=1,amount do
  110.     s,e=moveA(md,doRepeat,file)
  111.     if tostring(e) == "Unbreakable block detected" then return s,e end
  112.     if not s and not doRepeat then break end
  113.   end
  114.   return s,e
  115. end
  116. local function getOffset(posA,posB)
  117.   posB=posB or pos
  118.   local offset={}
  119.   offset.x=posA.x-posB.x
  120.   offset.y=posA.y-posB.y
  121.   offset.z=posA.z-posB.z
  122.   return offset
  123. end
  124. local function moveC(newPos,oldPos,doRepeat,file)
  125.   if oldPos then
  126.     pos.x=oldPos.x
  127.     pos.y=oldPos.y
  128.     pos.z=oldPos.z
  129.   end
  130.   local offset=getOffset(newPos)
  131.   local s,e=moveB(5,offset.y,doRepeat,file) --y
  132.   if s then
  133.     s,e=moveB(1,offset.x,doRepeat,file) --x
  134.   end
  135.   if s then
  136.     s,e=moveB(2,offset.z,doRepeat,file) --z
  137.   end
  138.   return s,e
  139. end
  140.  
  141. local function isChest(whitelist)
  142.   local s=false
  143.   local si,t=turtle.inspect()
  144.   if si and whitelist[t.name] then s=true end
  145.   return s
  146. end
  147. local function freeSlots(blacklist)
  148.   local count=16
  149.   for i=1,16 do
  150.     if not blacklist[i] and turtle.getItemCount(i) > 0 then
  151.       count=count-1
  152.     end
  153.   end
  154.   return count
  155. end
  156. local function withdrawInt(slot,doRepeat,file)
  157.   log("withdrawing from slot "..tostring(slot).."...",file)
  158.   local s,e=turtle.digUp()
  159.   while doRepeat and tostring(e) ~= "Nothing to dig here" do
  160.     s,e=turtle.digUp()
  161.   end
  162.   s=tostring(e)=="Nothing to dig here"
  163.   for i=1,16 do if i~=slot then
  164.     if turtle.getItemCount(i) == 0 then
  165.       turtle.select(i)
  166.       s,e=turtle.suckUp()
  167.       if not s then break end
  168.     end
  169.   end end
  170.   return s,e
  171. end
  172. local function depositChest(chestsInt,doRepeat,file)
  173.  
  174.   return true
  175. end
  176. local function depositAll(chestsExt,chestsInt,doRepeat,file)
  177.   local ms,me=moveC({x=0,y=0,z=0},nil,doRepeat)
  178.   turnTo(0)
  179.   local chestCount,temp=0,true
  180.   log("checking # of chests...",file)
  181.   while true do
  182.     temp=isChest(chestsExt)
  183.     if temp then chestCount=chestCount+1
  184.     else break end
  185.     ms,me=moveA(5,doRepeat)
  186.   end
  187.   ms,me=moveC({x=0,y=0,z=0},nil,doRepeat)
  188.   if chestCount == 0 then
  189.     log("no chests found!")
  190.     return nil,"No chests found"
  191.   end
  192.  
  193.   --
  194.  
  195.   ms,me=moveC({x=0,y=0,z=0},nil,doRepeat)
  196.   turnTo(2)
  197.   return true
  198. end
  199. --tbd detect for bedrock
  200. --depositAll(chestWhitelist,slotBlacklist,true,nil)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement