Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- ~ List of Keys ~
- W - Move Forward / Move Up (holding left shift) / Move Down (holding left control)
- S - Move Back / Move Down (holding left shift) / Move Up (holding left control)
- A - Turn Left
- D - Turn Right
- N - Break In Front / Above (holding left shift) / Below (holding left control)
- M - Place In Front / Above (holding left shift) / Below (holding left control)
- Arrow Keys - Move Inventory Cursor
- R - Refuel
- F - Check Fuel Level
- E - Exit
- ]]
- local forwardKey = keys.w
- local backKey = keys.s
- local turnLeftKey = keys.a
- local turnRightKey = keys.d
- local upModKey = keys.leftShift
- local downModKey = keys.leftCtrl
- local breakKey = keys.n
- local placeKey = keys.m
- local inventoryKey = keys.i
- local exitKey = keys.e
- local refuelKey = keys.r
- local checkFuelKey = keys.f
- local selectUpKey = keys.up
- local selectDownKey = keys.down
- local selectLeftKey = keys.left
- local selectRightKey = keys.right
- local dropKey = keys.q
- local suckKey = keys.z
- local upMod = false
- local downMod = false
- local blocks =
- {
- top = {
- name = "Empty",
- completeName = "Empty",
- modName = "minecraft",
- metadata = 0,
- state = {}
- },
- front = {
- name = "Empty",
- completeName = "Empty",
- modName = "minecraft",
- metadata = 0,
- state = {}
- },
- bottom = {
- name = "Empty",
- completeName = "Empty",
- modName = "minecraft",
- metadata = 0,
- state = {}
- }
- }
- local function updateBlocks()
- if turtle.detectUp() then
- local _, inspect = turtle.inspectUp()
- inspect.modName = inspect.name:match(".-:"):sub(1, -2)
- inspect.name = inspect.name:match(":.+"):sub(2, -1):gsub("_", " "):gsub("(%a)(%a+)", function(a, b) return string.upper(a) .. string.lower(b) end)
- inspect.completeName = inspect.name
- if inspect.state.variant then
- inspect.completeName = inspect.completeName.." ("..inspect.state.variant:gsub("_", " "):gsub("(%a)(%a+)", function(a, b) return string.upper(a) .. string.lower(b) end)..")"
- end
- if inspect.state.color then
- inspect.completeName = inspect.completeName.." ("..inspect.state.color:gsub("_", " "):gsub("(%a)(%a+)", function(a, b) return string.upper(a) .. string.lower(b) end)..")"
- end
- blocks.top = inspect
- else
- blocks.top = {name = "Empty", completeName = "Empty", modName = "minecraft", metadata = 0, state = {}}
- end
- if turtle.detect() then
- local _, inspect = turtle.inspect()
- inspect.modName = inspect.name:match(".-:"):sub(1, -2)
- inspect.name = inspect.name:match(":.+"):sub(2, -1):gsub("_", " "):gsub("(%a)(%a+)", function(a, b) return string.upper(a) .. string.lower(b) end)
- inspect.completeName = inspect.name
- if inspect.state.variant then
- inspect.completeName = inspect.completeName.." ("..inspect.state.variant:gsub("_", " "):gsub("(%a)(%a+)", function(a, b) return string.upper(a) .. string.lower(b) end)..")"
- end
- if inspect.state.color then
- inspect.completeName = inspect.completeName.." ("..inspect.state.color:gsub("_", " "):gsub("(%a)(%a+)", function(a, b) return string.upper(a) .. string.lower(b) end)..")"
- end
- blocks.front = inspect
- else
- blocks.front = {name = "Empty", completeName = "Empty", modName = "minecraft", metadata = 0, state = {}}
- end
- if turtle.detectDown() then
- local _, inspect = turtle.inspectDown()
- inspect.modName = inspect.name:match(".-:"):sub(1, -2)
- inspect.name = inspect.name:match(":.+"):sub(2, -1):gsub("_", " "):gsub("(%a)(%a+)", function(a, b) return string.upper(a) .. string.lower(b) end)
- inspect.completeName = inspect.name
- if inspect.state.variant then
- inspect.completeName = inspect.completeName.." ("..inspect.state.variant:gsub("_", " "):gsub("(%a)(%a+)", function(a, b) return string.upper(a) .. string.lower(b) end)..")"
- end
- if inspect.state.color then
- inspect.completeName = inspect.completeName.." ("..inspect.state.color:gsub("_", " "):gsub("(%a)(%a+)", function(a, b) return string.upper(a) .. string.lower(b) end)..")"
- end
- blocks.bottom = inspect
- else
- blocks.bottom = {name = "Empty", completeName = "Empty", modName = "minecraft", metadata = 0, state = {}}
- end
- end
- local function getInv()
- end
- local function checkFuel()
- print( (turtle.getFuelLevel() / turtle.getFuelLimit()) * 100 .. "% (" .. turtle.getFuelLevel() .. "/" .. turtle.getFuelLimit() .. ")" )
- end
- local function refuel()
- if turtle.refuel(0) then
- turtle.refuel(1)
- end
- checkFuel()
- end
- local function hasValue (tab, val)
- for index, value in ipairs(tab) do
- if value == val then
- return true
- end
- end
- return false
- end
- local function init()
- term.clear()
- term.setCursorPos(1,1)
- updateBlocks()
- end
- local run = true
- init()
- while run do
- e, p1, p2, p3, p4, p5 = os.pullEvent()
- if e == "key_up" then
- if p1 == upModKey then
- upMod = false
- end
- if p1 == downModKey then
- downMod = false
- end
- if p1 == forwardKey then
- if turtle.getFuelLevel() <= 0 then
- print("out of fuel")
- else
- if upMod and not downMod then
- if turtle.up() then
- print("up")
- else
- print("block in the way")
- end
- elseif downMod and not upMod then
- if turtle.down() then
- print("down")
- else
- print("block in the way")
- end
- else
- if turtle.forward() then
- print("forward")
- else
- print("block in the way")
- end
- end
- end
- end
- if p1 == backKey then
- if turtle.getFuelLevel() <= 0 then
- print("out of fuel")
- else
- if upMod and not downMod then
- if turtle.down() then
- print("down")
- else
- print("block in the way")
- end
- elseif downMod and not upMod then
- if turtle.up() then
- print("up")
- else
- print("block in the way")
- end
- else
- if turtle.back() then
- print("back")
- else
- print("block in the way")
- end
- end
- end
- end
- if p1 == breakKey then
- if upMod and not downMod then
- if turtle.digUp() then
- print("Broke Above Block")
- else
- print("Unable To Break")
- end
- elseif downMod and not upMod then
- if turtle.digDown() then
- print("Broke Below Block")
- else
- print("Unable To Break")
- end
- else
- if turtle.dig() then
- print("Broke Front Block")
- else
- print("Unable To Break")
- end
- end
- end
- if p1 == placeKey then
- if upMod and not downMod then
- if turtle.placeUp() then
- print("Placed Above Block")
- else
- print("Unable To Place")
- end
- elseif downMod and not upMod then
- if turtle.placeDown() then
- print("Placed Below Block")
- else
- print("Unable To Place")
- end
- else
- if turtle.place() then
- print("Placed Front Block")
- else
- print("Unable To Place")
- end
- end
- end
- if p1 == turnLeftKey then
- if turtle.turnLeft() then
- print("Turn left")
- end
- end
- if p1 == turnRightKey then
- if turtle.turnRight() then
- print("Turn right")
- end
- end
- if p1 == selectUpKey then
- turtle.select( (((turtle.getSelectedSlot()-1) - 4) % 16) + 1 )
- end
- if p1 == selectDownKey then
- turtle.select( (((turtle.getSelectedSlot()-1) + 4) % 16) + 1 )
- end
- if p1 == selectLeftKey then
- turtle.select( (((turtle.getSelectedSlot()-1) - 1) % 16) + 1 )
- end
- if p1 == selectRightKey then
- turtle.select( (((turtle.getSelectedSlot()-1) + 1) % 16) + 1 )
- end
- if p1 == checkFuelKey then
- checkFuel()
- end
- if p1 == refuelKey then
- refuel()
- end
- if p1 == exitKey then
- run = false
- term.clear()
- term.setCursorPos(1,1)
- end
- if hasValue({forwardKey, backKey, turnLeftKey, turnRightKey, placeKey, breakKey}, p1) then
- updateBlocks()
- print(blocks.top.completeName)
- print(blocks.front.completeName)
- print(blocks.bottom.completeName)
- end
- elseif e == "key" then
- if p1 == upModKey then
- upMod = true
- end
- if p1 == downModKey then
- downMod = true
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment