Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local wires = {
- POWER_OFF = colours.black,
- REVERSE = colours.white,
- SPEED_DOUBLE = colours.red,
- SPEED_HALF = colours.cyan,
- TRANSFER_SIDEWAYS = colours.pink,
- TRANSFER_PULLEY = colours.lightBlue,
- GRAB = colours.magenta
- }
- local speeds = {
- HALF = { wires.SPEED_HALF, "1x" },
- SINGLE = { 0, "2x" },
- DOUBLE = { wires.SPEED_DOUBLE, "4x" },
- }
- local actions = {
- NONE = { colours.combine(wires.POWER_OFF), "None" },
- FORWARD = { 0, "Forward" },
- BACKWARD = { colours.combine(wires.REVERSE), "Backward" },
- LEFT = { colours.combine(wires.TRANSFER_SIDEWAYS), "Left" },
- RIGHT = { colours.combine(wires.TRANSFER_SIDEWAYS, wires.REVERSE), "Right" },
- UP = { colours.combine(wires.TRANSFER_SIDEWAYS, wires.TRANSFER_PULLEY), "Up" },
- DOWN = { colours.combine(wires.TRANSFER_SIDEWAYS, wires.TRANSFER_PULLEY, wires.REVERSE), "Down" },
- GRAB = { colours.combine(wires.TRANSFER_SIDEWAYS, wires.TRANSFER_PULLEY, wires.GRAB), "Grab" }
- }
- local grabbing = false
- local side = "left"
- local speed = speeds.SINGLE
- local action = actions.NONE
- local resetTimer = 0
- local function setAction(newAction, newSpeed)
- if (action ~= newAction or speed ~= newSpeed) then
- action = newAction
- speed = newSpeed
- local output = colours.combine(action[1], speed[1])
- if (grabbing) then
- output = colours.combine(output, wires.GRAB)
- end
- redstone.setBundledOutput(side, output)
- end
- end
- local function grab()
- grabbing = true
- resetTimer = 10
- setAction(actions.GRAB, speed)
- end
- local function controls()
- while (true) do
- local eventData = {os.pullEvent()}
- local event = eventData[1]
- if (event == "key" and not eventData[3]) then
- local key = eventData[2]
- if (key == keys.w or key == keys.up) then setAction(actions.FORWARD, speed)
- elseif (key == keys.s or key == keys.down) then setAction(actions.BACKWARD, speed)
- elseif (key == keys.a or key == keys.left) then setAction(actions.LEFT, speed)
- elseif (key == keys.d or key == keys.right) then setAction(actions.RIGHT, speed)
- elseif (key == keys.space) then setAction(actions.UP, speed)
- elseif (key == keys.leftShift) then setAction(actions.DOWN, speed)
- elseif (key == keys.one) then setAction(action, speeds.HALF)
- elseif (key == keys.two) then setAction(action, speeds.SINGLE)
- elseif (key == keys.three) then setAction(action, speeds.DOUBLE)
- elseif (key == keys.g) then grab()
- end
- elseif (event == "key_up") then
- local key = eventData[2]
- if ((action == actions.FORWARD and (key == keys.w or key == keys.up)) or
- (action == actions.BACKWARD and (key == keys.s or key == keys.down)) or
- (action == actions.LEFT and (key == keys.a or key == keys.left)) or
- (action == actions.RIGHT and (key == keys.d or key == keys.right)) or
- (action == actions.UP and (key == keys.space)) or
- (action == actions.DOWN and (key == keys.leftShift))) then
- setAction(actions.NONE, speed)
- end
- end
- end
- end
- local function status()
- term.clear()
- while (true) do
- term.setCursorPos(1, 1)
- term.clearLine()
- print(action[2] .. " [" .. speed[2] .. "]\n")
- print(grabbing and "Attached" or "Detached")
- if (grabbing) then
- resetTimer = resetTimer - 1
- if (resetTimer <= 0) then
- resetTimer = 0
- grabbing = false
- end
- end
- sleep(0.1)
- end
- end
- parallel.waitForAll(controls, status)
Advertisement
Add Comment
Please, Sign In to add comment