ekothefof141

ooga booga

Dec 4th, 2021 (edited)
836
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local expect = require("cc.expect").expect
  2. local slot = tonumber(turtle.getSelectedSlot())
  3. local direction = {[0] = "north", "east", "south", "west"}
  4. local d = 0
  5. local maxSlots = 16
  6. local coords = {x = 0, y = 0, z = 0}
  7. local start = coords
  8. local length = arg[1]
  9. local fuelList = {
  10.   "minecraft:coal",
  11.   "minecraft:coal_block",
  12.   "minecraft:charcoal",
  13.   "minecraft:lava_bucket",
  14. }
  15.  
  16. function findItem(name)
  17.   for i=1,maxSlots do
  18.     local item = turtle.getItemDetail(i)
  19.     if item ~= nil then
  20.       if item.name == name then
  21.         turtle.select(i)
  22.         slot = tonumber(i)
  23.         return true
  24.       end
  25.     end
  26.   end
  27.   return false
  28. end
  29.  
  30. function refuel(skip)
  31.     if skip ~= true then
  32.         skip = false
  33.     end
  34.   if turtle.getFuelLevel() <= 10 or skip then
  35.     for i=1,#fuelList do
  36.       if findItem(fuelList[i]) then
  37.         turtle.refuel(1)
  38.         return true
  39.       end
  40.     end
  41.     return false, turtle.getFuelLevel()
  42.   else
  43.     return false, turtle.getFuelLevel()
  44.   end
  45. end
  46.  
  47. function face(dir)
  48.   if dir == "north" or "east" or "south" or "west" then
  49.     for k,v in pairs(direction) do
  50.       if v == arg then
  51.       dir = k
  52.       break
  53.       end
  54.     end
  55.   end
  56.   if dir == (d + 2) % 4 then
  57.     turnAround()
  58.   elseif dir == (d - 1) % 4 then
  59.     turnLeft()
  60.   elseif dir == (d + 1) % 4 then
  61.     turnRight()
  62.   end
  63. end
  64.  
  65. function turnLeft()
  66.   turtle.turnLeft()
  67.   d = (d - 1) % 4
  68. end
  69.  
  70. function turnRight()
  71.   turtle.turnRight()
  72.   d = (d + 1) % 4
  73. end
  74.  
  75. function turnAround()
  76.   turtle.turnRight()
  77.   turtle.turnRight()
  78.   d = (d + 2) % 4
  79. end
  80.  
  81. function forward(times)
  82.   times = times or 1
  83.   if times < 0 then
  84.     backward(-times)
  85.   end
  86.   for i=1,times do
  87.     refuel()
  88.     while not turtle.forward() do
  89.       local inspect = {turtle.inspect()}
  90.       if inspect[1] and inspect[2].name == "minecraft:bedrock" then
  91.         return false
  92.       elseif inspect[1] and inspect[2].name ~= "minecraft:bedrock" then
  93.         turtle.dig()
  94.       else
  95.         turtle.attack()
  96.       end
  97.     end
  98.     if d == 0 then
  99.       coords.z = coords.z - 1
  100.     elseif d == 1 then
  101.       coords.x = coords.x + 1
  102.     elseif d == 2 then
  103.       coords.z = coords.z + 1
  104.     elseif d == 3 then
  105.       coords.x = coords.x - 1
  106.     end
  107.   end
  108.   return true
  109. end
  110.  
  111. function backward(times)
  112.   times = times or 1
  113.   if times < 0 then
  114.     forward(-times)
  115.   end
  116.   for i=1,times do
  117.     refuel()
  118.     turtle.back()
  119.     if d == 0 then
  120.       coords.z = coords.z + 1
  121.     elseif d == 1 then
  122.       coords.x = coords.x - 1
  123.     elseif d == 2 then
  124.       coords.z = coords.z - 1
  125.     elseif d == 3 then
  126.       coords.x = coords.x + 1
  127.     end
  128.   end
  129. end
  130.  
  131. function up(times)
  132.   times = times or 1
  133.   if times < 0 then
  134.     down(-times)
  135.   end
  136.   for i=1,times do
  137.     refuel()
  138.     while not turtle.up() do
  139.       local inspect = {turtle.inspectUp()}
  140.       if inspect[1] and inspect[2].name == "minecraft:bedrock" then
  141.         return false
  142.       elseif inspect[1] and inspect[2].name ~= "minecraft:bedrock" then
  143.         turtle.digUp()
  144.       else
  145.         turtle.attackUp()
  146.       end
  147.     end
  148.     coords.y = coords.y + 1
  149.   end
  150.   return true
  151. end
  152.  
  153. function down(times)
  154.   times = times or 1
  155.   if times < 0 then
  156.     up(-times)
  157.   end
  158.   for i=1,times do
  159.     refuel()
  160.     while not turtle.down() do
  161.       local inspect = {turtle.inspectDown()}
  162.       if inspect[1] and inspect[2].name == "minecraft:bedrock" then
  163.         return false
  164.       elseif inspect[1] and inspect[2].name ~= "minecraft:bedrock" then
  165.         turtle.digDown()
  166.       else
  167.         turtle.attackDown()
  168.       end
  169.     end
  170.     coords.y = coords.y - 1
  171.   end
  172.   return true
  173. end
  174.  
  175. function moveTo(x, y, z)
  176.   if x == "~" then
  177.     x = coords.x
  178.   end
  179.   if y == "~" then
  180.     y = coords.y
  181.   end
  182.   if z == "~" then
  183.     z = coords.z
  184.   end
  185.   if y > coords.y then
  186.     up(y - coords.y)
  187.   end
  188.   if x < coords.x then
  189.     face("west")
  190.     forward(coords.x - x)
  191.   elseif x > coords.x then
  192.     face("east")
  193.     forward(x - coords.x)
  194.   end
  195.   if z < coords.z then
  196.     face("north")
  197.     forward(coords.z - z)
  198.   elseif z > coords.z then
  199.     face("south")
  200.     forward(z - coords.z)
  201.   end
  202.   if y < coords.y then
  203.     down(coords.y - y)
  204.   end
  205. end
  206.  
  207. hasTorches = true
  208. function placeTorch()
  209.   if findItem("minecraft:torch") then
  210.     turtle.place()
  211.   else
  212.     hasTorches = false
  213.   end
  214. end
  215.  
  216. function inventoryToChest()
  217.   local blacklistedItems = {
  218.     "minecraft:torch",
  219.     "minecraft:coal",
  220.     "minecraft:coal_block",
  221.     "minecraft:charcoal",
  222.     "minecraft:lava_bucket",
  223.   }
  224.   for i=1,maxSlots do
  225.     local item = turtle.getItemDetail(i)
  226.     for k,v in pairs(blacklistedItems) do
  227.       if item.name ~= v then
  228.         turtle.select(i)
  229.         slot = i
  230.         turtle.drop()
  231.       end      
  232.     end
  233.   end
  234.   turtle.select(1)
  235.   slot = 1
  236. end
  237.  
  238. function checkInventory()
  239.   if turtle.getItemCount(maxSlots) >= 32 then
  240.     local current = coords
  241.     moveTo(start.x, start.y, start.z)
  242.     inventoryToChest()
  243.     moveTo(current.x, current.y, current.z)
  244.   end
  245. end
  246.  
  247. function mineSquence(amount)
  248.   for x=1,amount do
  249.     forward()
  250.     turnRight()
  251.     turtle.dig()
  252.     if x % 8 == 0 then
  253.       if hasTorches then
  254.         placeTorch()
  255.       end
  256.     end
  257.     turnAround()
  258.     turtle.dig()
  259.     if x + 4 % 8 == 0 then
  260.       if hasTorches then
  261.         placeTorch()
  262.       end
  263.     end
  264.     if x % 2 == 0 then
  265.       down()
  266.     else
  267.       up()
  268.     end
  269.     turtle.dig()
  270.     turnAround()
  271.     turtle.dig()
  272.     turnRight()
  273.     checkInventory()
  274.   end
  275.   moveTo(start.x, start.y, start.z)
  276.   inventoryToChest()
  277. end
  278.  
  279. if not expect(1, length, "number") then
  280.   print("Usage"..shell.getRunningProgram().." 42")
  281.   error("Length not a #", 0)
  282. end
  283. _, level = refuel()
  284. if level >= 10 then
  285.   mineSquence(length)
  286. else
  287.   error("Not enough Fuel to start",0)
  288. end
RAW Paste Data