paramus

Turtle OS

Jan 2nd, 2026 (edited)
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.10 KB | Gaming | 0 0
  1. -- Variables
  2. local MaxFuel = 0
  3. local Fuel = 0
  4. local IsDigging = false
  5. local Slot = 1
  6. local AutoRefuel = true
  7.  
  8. function Draw()
  9.     term.setBackgroundColor(colors.white)
  10.     term.setTextColor(colors.white)
  11.     term.clear()
  12.     paintutils.drawFilledBox(1,1, 39, 13, colors.black)
  13.    
  14.     -- Fuel bar
  15.     term.setCursorPos(2,1)
  16.     print("Fuel level")
  17.     paintutils.drawLine(2,2, 38, 2, colors.gray)
  18.     if (((Fuel/MaxFuel) * 38) > 2) then
  19.         paintutils.drawLine(2,2, ((Fuel/MaxFuel) * 38), 2, colors.green)
  20.     end
  21.    
  22.     if (IsDigging) then
  23.         term.setTextColor(colors.green)
  24.     else
  25.         term.setTextColor(colors.red)
  26.     end
  27.     -- Up button
  28.     paintutils.drawPixel(5,4, colors.yellow)
  29.     term.setCursorPos(5,4)
  30.     print("\24")
  31.    
  32.     -- Down button
  33.     paintutils.drawPixel(5,8, colors.yellow)
  34.     term.setCursorPos(5,8)
  35.     print("\25")
  36.    
  37.     -- Dig button
  38.     paintutils.drawPixel(5,6, colors.yellow)
  39.     term.setCursorPos(5,6)
  40.     print("\7")
  41.    
  42.     -- Left button
  43.     paintutils.drawPixel(3,6, colors.yellow)
  44.     term.setCursorPos(3,6)
  45.     print("\17")
  46.    
  47.     -- Right button
  48.     paintutils.drawPixel(7,6, colors.yellow)
  49.     term.setCursorPos(7,6)
  50.     print("\16")
  51.    
  52.     -- Refuel button
  53.     paintutils.drawLine(16,4, 21,4, colors.yellow)
  54.     term.setCursorPos(16,4)
  55.     print("Refuel")
  56.    
  57.     -- Refuel button
  58.     if (AutoRefuel) then
  59.         term.setTextColor(colors.green)
  60.     else
  61.         term.setTextColor(colors.red)
  62.     end
  63.     paintutils.drawLine(16,6, 24,6, colors.yellow)
  64.     term.setCursorPos(16,6)
  65.     print("Auto-Fuel")
  66. end
  67.  
  68. function GetData()
  69.     MaxFuel = turtle.getFuelLimit()
  70.     Fuel = turtle.getFuelLevel()
  71.    
  72.     -- Refuel when it has lava around
  73.     if (AutoRefuel) then
  74.         AutoFuel()
  75.     end
  76. end
  77.  
  78. function Button(x,y)
  79.     while (true) do
  80.        
  81.         local event, button, x, y = os.pullEvent("mouse_click")
  82.  
  83.         -- Button clicks here
  84.         if (y == 4 and x>=16 and x<=21) then
  85.             turtle.refuel()
  86.         elseif (y == 6 and x>=16 and x<=24) then
  87.             if (AutoRefuel) then
  88.                 AutoRefuel = false
  89.             else
  90.                 AutoRefuel = true
  91.             end
  92.         elseif (x == 5 and y == 6) then
  93.             if (IsDigging) then
  94.                 IsDigging = false
  95.             else
  96.                 IsDigging = true
  97.             end
  98.         elseif (x == 3 and y == 6) then
  99.             turtle.turnLeft()
  100.         elseif (x == 7 and y == 6) then
  101.             turtle.turnRight()
  102.         elseif (x == 5 and y == 4) then
  103.             if (turtle.detectUp()) then
  104.                 turtle.digUp()
  105.             end
  106.             turtle.up()
  107.         elseif (x == 5 and y == 8) then
  108.             if (turtle.detectDown()) then
  109.                 turtle.digDown()
  110.             end
  111.             turtle.down()
  112.         end
  113.        
  114.     end
  115. end
  116.  
  117. function Wireless()
  118.     while (true) do
  119.        
  120.         local event, sender, message, protocol = os.pullEvent("rednet_message")
  121.         message = tostring(message)
  122.  
  123.         if (message == "Go") then
  124.             IsDigging = true
  125.         elseif (message == "Stop") then
  126.             IsDigging = false
  127.         elseif (message == "Left") then
  128.             turtle.turnLeft()
  129.         elseif (message == "Right") then
  130.             turtle.turnRight()
  131.         elseif (message == "Up") then
  132.             if (turtle.detectUp()) then
  133.                 turtle.digUp()
  134.             end
  135.             turtle.up()
  136.         elseif (message == "Down") then
  137.             if (turtle.detectDown()) then
  138.                 turtle.digDown()
  139.             end
  140.             turtle.down()
  141.         end
  142.        
  143.     end
  144. end
  145.  
  146. function AutoFuel()
  147.     local has_block, data = turtle.inspect()
  148.     if (data ~= nil and data.name == "minecraft:lava") then
  149.         turtle.place()
  150.         turtle.refuel()
  151.     end
  152.    
  153.     has_block, data = turtle.inspectUp()
  154.     if (data ~= nil and data.name == "minecraft:lava") then
  155.         turtle.placeUp()
  156.         turtle.refuel()
  157.     end
  158.    
  159.     has_block, data = turtle.inspectDown()
  160.     if (data ~= nil and data.name == "minecraft:lava") then
  161.         turtle.placeDown()
  162.         turtle.refuel()
  163.     end
  164. end
  165.  
  166. function Scroll()
  167.     while (true) do
  168.        
  169.         local event, dir, x, y = os.pullEvent("mouse_scroll")
  170.         Slot = Slot + dir
  171.         if (Slot > 16) then
  172.             Slot = 1
  173.         elseif (Slot < 1) then
  174.             Slot = 16
  175.         end
  176.         turtle.select(Slot)
  177.        
  178.     end
  179. end
  180.  
  181. function main()
  182.     while (true) do
  183.        
  184.         GetData()
  185.         Draw()
  186.         if (IsDigging) then
  187.             if (turtle.detect()) then
  188.                 turtle.dig()
  189.             end
  190.             turtle.forward()
  191.             if (turtle.detectUp()) then
  192.                 turtle.digUp()
  193.             end
  194.         end
  195.         sleep(0.1)
  196.        
  197.     end
  198. end
  199.  
  200. peripheral.find("modem", rednet.open)
  201. --"Threads"
  202. parallel.waitForAny(
  203.     function()
  204.         main()-- Main loop
  205.     end,
  206.     function()
  207.         Wireless() --Rednet orders
  208.     end,
  209.     function()
  210.         Button() -- Screen click
  211.     end,
  212.     function()
  213.         Scroll() --Scroll wheel
  214.     end
  215. )
Advertisement
Add Comment
Please, Sign In to add comment