Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Variables
- local MaxFuel = 0
- local Fuel = 0
- local IsDigging = false
- local Slot = 1
- local AutoRefuel = true
- function Draw()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.white)
- term.clear()
- paintutils.drawFilledBox(1,1, 39, 13, colors.black)
- -- Fuel bar
- term.setCursorPos(2,1)
- print("Fuel level")
- paintutils.drawLine(2,2, 38, 2, colors.gray)
- if (((Fuel/MaxFuel) * 38) > 2) then
- paintutils.drawLine(2,2, ((Fuel/MaxFuel) * 38), 2, colors.green)
- end
- if (IsDigging) then
- term.setTextColor(colors.green)
- else
- term.setTextColor(colors.red)
- end
- -- Up button
- paintutils.drawPixel(5,4, colors.yellow)
- term.setCursorPos(5,4)
- print("\24")
- -- Down button
- paintutils.drawPixel(5,8, colors.yellow)
- term.setCursorPos(5,8)
- print("\25")
- -- Dig button
- paintutils.drawPixel(5,6, colors.yellow)
- term.setCursorPos(5,6)
- print("\7")
- -- Left button
- paintutils.drawPixel(3,6, colors.yellow)
- term.setCursorPos(3,6)
- print("\17")
- -- Right button
- paintutils.drawPixel(7,6, colors.yellow)
- term.setCursorPos(7,6)
- print("\16")
- -- Refuel button
- paintutils.drawLine(16,4, 21,4, colors.yellow)
- term.setCursorPos(16,4)
- print("Refuel")
- -- Refuel button
- if (AutoRefuel) then
- term.setTextColor(colors.green)
- else
- term.setTextColor(colors.red)
- end
- paintutils.drawLine(16,6, 24,6, colors.yellow)
- term.setCursorPos(16,6)
- print("Auto-Fuel")
- end
- function GetData()
- MaxFuel = turtle.getFuelLimit()
- Fuel = turtle.getFuelLevel()
- -- Refuel when it has lava around
- if (AutoRefuel) then
- AutoFuel()
- end
- end
- function Button(x,y)
- while (true) do
- local event, button, x, y = os.pullEvent("mouse_click")
- -- Button clicks here
- if (y == 4 and x>=16 and x<=21) then
- turtle.refuel()
- elseif (y == 6 and x>=16 and x<=24) then
- if (AutoRefuel) then
- AutoRefuel = false
- else
- AutoRefuel = true
- end
- elseif (x == 5 and y == 6) then
- if (IsDigging) then
- IsDigging = false
- else
- IsDigging = true
- end
- elseif (x == 3 and y == 6) then
- turtle.turnLeft()
- elseif (x == 7 and y == 6) then
- turtle.turnRight()
- elseif (x == 5 and y == 4) then
- if (turtle.detectUp()) then
- turtle.digUp()
- end
- turtle.up()
- elseif (x == 5 and y == 8) then
- if (turtle.detectDown()) then
- turtle.digDown()
- end
- turtle.down()
- end
- end
- end
- function Wireless()
- while (true) do
- local event, sender, message, protocol = os.pullEvent("rednet_message")
- message = tostring(message)
- if (message == "Go") then
- IsDigging = true
- elseif (message == "Stop") then
- IsDigging = false
- elseif (message == "Left") then
- turtle.turnLeft()
- elseif (message == "Right") then
- turtle.turnRight()
- elseif (message == "Up") then
- if (turtle.detectUp()) then
- turtle.digUp()
- end
- turtle.up()
- elseif (message == "Down") then
- if (turtle.detectDown()) then
- turtle.digDown()
- end
- turtle.down()
- end
- end
- end
- function AutoFuel()
- local has_block, data = turtle.inspect()
- if (data ~= nil and data.name == "minecraft:lava") then
- turtle.place()
- turtle.refuel()
- end
- has_block, data = turtle.inspectUp()
- if (data ~= nil and data.name == "minecraft:lava") then
- turtle.placeUp()
- turtle.refuel()
- end
- has_block, data = turtle.inspectDown()
- if (data ~= nil and data.name == "minecraft:lava") then
- turtle.placeDown()
- turtle.refuel()
- end
- end
- function Scroll()
- while (true) do
- local event, dir, x, y = os.pullEvent("mouse_scroll")
- Slot = Slot + dir
- if (Slot > 16) then
- Slot = 1
- elseif (Slot < 1) then
- Slot = 16
- end
- turtle.select(Slot)
- end
- end
- function main()
- while (true) do
- GetData()
- Draw()
- if (IsDigging) then
- if (turtle.detect()) then
- turtle.dig()
- end
- turtle.forward()
- if (turtle.detectUp()) then
- turtle.digUp()
- end
- end
- sleep(0.1)
- end
- end
- peripheral.find("modem", rednet.open)
- --"Threads"
- parallel.waitForAny(
- function()
- main()-- Main loop
- end,
- function()
- Wireless() --Rednet orders
- end,
- function()
- Button() -- Screen click
- end,
- function()
- Scroll() --Scroll wheel
- end
- )
Advertisement
Add Comment
Please, Sign In to add comment