Advertisement
sapbot

Mining script for ComputerCraft turtle

Dec 6th, 2024 (edited)
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- ComputerCraft command:
  2. -- bg pastebin run UUGAiRx1
  3.  
  4. -- SETTINGS -------------------------------------------
  5. local fuel = {'minecraft:lava_bucket', 'minecraft:coal', 'minecraft:blaze_rod', 'minecraft:stick', 'minecraft:oak_log', 'minecraft:oak_planks', 'minecraft:birch_log', 'minecraft:birch_planks', 'minecraft:birch_door', 'minecraft:oak_door', 'minecraft:charcoal', 'minecraft:bamboo_block'}
  6. -------------------------------------------------------
  7.  
  8. local function has_value (tab, val)
  9.     for index, value in ipairs(tab) do
  10.         if value == val then
  11.             return true
  12.         end
  13.     end
  14.  
  15.     return false
  16. end
  17.  
  18.  
  19. local slot = 1
  20. shell.run("label", "set", "miningturtle")
  21. while true do
  22.  
  23. turtle.digUp()
  24. turtle.digDown()
  25. turtle.suck()
  26. turtle.suckUp()
  27. turtle.suckDown()
  28.  
  29. local has_block, data = turtle.inspect()
  30. if has_block then
  31.   if (data["name"] == "computercraft:turtle_advanced") then
  32.     if not turtle.back() then
  33.       turtle.turnRight()
  34.     end
  35.   else
  36.     turtle.dig()
  37.     turtle.forward()
  38.   end
  39. else
  40.   turtle.turnRight()
  41.   local rightblk = turtle.detect()
  42.   turtle.turnLeft()
  43.   if (rightblk) or (not (turtle.back())) then
  44.     turtle.turnRight()
  45.   end
  46. end
  47.  
  48. -- Infinity life code
  49. for slot=1,16 do
  50.   local item = turtle.getItemDetail(slot)
  51.   if not (item == nil) then
  52.     if (not has_value(fuel, item["name"])) then
  53.       turtle.select(slot)
  54.       turtle.drop()
  55.     end
  56.     if turtle.getFuelLevel() < 10 then
  57.       turtle.select(slot)
  58.       turtle.refuel(1)
  59.     end
  60.   end
  61. end
  62.  
  63. -- Debug
  64. shell.run("clear")
  65. print("--- Debug ---")
  66. print("Fuel: " .. tostring(turtle.getFuelLevel()) .. "/" .. tostring(turtle.getFuelLimit()))
  67. --
  68.  
  69. end
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement