Advertisement
9551

a good code lmao

Jun 29th, 2021
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.89 KB | None | 0 0
  1. local wait = sleep
  2. local posX = 0
  3. local mining = true
  4. local facingForward = true
  5.  
  6. -- Ores list
  7. local ores = {
  8.     ["minecraft:gold_ore"] = true,
  9.     ["minecraft:iron_ore"] = true,
  10.     ["minecraft:diamond_ore"] = true,
  11.     ["minecraft:emerald_ore"] = true,
  12.     ["minecraft:lapis_ore"] = true,
  13.     ["minecraft:redstone_ore"] = true,
  14.     ["create:copper_ore"] = true,
  15.     ["create:zinc_ore"] = true
  16. }
  17.  
  18. local function checkInvFull()
  19.     for i = 1, 16 do
  20.         if not turtle.getItemDetail(i) then
  21.             return false -- not full
  22.         end
  23.     end
  24.  
  25.     return true --full
  26. end
  27.  
  28. local function checkInvEmpty()
  29.     for i = 1, 16 do
  30.         if turtle.getItemDetail(i) then
  31.             return false
  32.         end
  33.     end
  34.  
  35.     return true
  36. end
  37.  
  38. local function fuelStop()
  39.     if turtle.getFuelLevel() <= 500 then
  40.         os.setComputerLabel("Refulling")
  41.         turtle.suckDown(64)
  42.         turtle.refuel(64)
  43.         os.setComputerLabel("Refueled with a level of: " .. turtle.getFuelLevel())
  44.     else
  45.         os.setComputerLabel("No refulling needed")
  46.         wait(3)
  47.         os.setComputerLabel("fuel level is: " .. turtle.getFuelLevel())
  48.     end
  49.  
  50.     wait(3)
  51.     os.setComputerLabel("miner")
  52. end
  53.  
  54. local function turnAround()
  55.     turtle.turnLeft()
  56.     turtle.turnLeft()
  57.  
  58.     facingForward = not facingForward
  59. end
  60.  
  61. local function dumpInventory()
  62.     if posX == 0 then
  63.         if facingForward then
  64.             turtle.back()
  65.             turtle.up()
  66.  
  67.             for i = 1, 16 do
  68.                 turtle.select(i)
  69.                 local amount = turtle.getItemCount(i)
  70.                 turtle.dropUp(amount)
  71.             end
  72.  
  73.             turtle.down()
  74.             turtle.forward()
  75.         else
  76.             turnAround()
  77.         end
  78.     end
  79. end
  80.  
  81. local function returnHome(reason)
  82.     mining = false
  83.     turnAround()
  84.  
  85.     os.setComputerLabel("Returning home" .. reason)
  86.     while posX > 0 do
  87.         turtle.forward()
  88.         posX = posX - 1
  89.     end
  90.     turnAround()
  91. end
  92.  
  93. local function diggy()
  94.     turtle.dig("right")
  95.  
  96.     local ok, name = turtle.inspectUp()
  97.  
  98.     if ok and ores[name] then
  99.         turtle.digUp("right")
  100.     end
  101.  
  102.     local ok, name = turtle.inspectDown()
  103.  
  104.     if ok and ores[name] then
  105.         turtle.digDown("right")
  106.     end
  107. end
  108.  
  109. fuelStop()
  110.  
  111. while true do
  112.     if mining then
  113.         if turtle.detect() == false then
  114.             turtle.forward()
  115.             posX = posX + 1
  116.         else
  117.             if checkInvFull == false then
  118.                 if posX > turtle.getFuelLevel() + 10 then
  119.                     diggy()
  120.                 else
  121.                     returnHome("no fuel")
  122.                 end
  123.             else
  124.                 returnHome("inventory full")
  125.             end
  126.         end
  127.     else
  128.         if checkInvEmpty() == false then
  129.             dumpInventory()
  130.         end
  131.         fuelStop()
  132.         mining = true
  133.     end
  134. end
  135.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement