Maschini

rc

Feb 24th, 2023
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 KB | None | 0 0
  1. local mttp = require("mttp")
  2. local modem = peripheral.wrap("back")
  3.  
  4. local lastInput = ""
  5. local selectedSlot = turtle.getSelectedSlot()
  6. local selectedSlotData = {}
  7.  
  8. local function printUsage()
  9.     print("Controls:")
  10.     print("Move:", "w", "a", "s", "d")
  11.     print("Up/Down:", "space, ctrl")
  12.     print("Dig(F/U/D):", "f", "r", "v")
  13.     print("Place(F/U/D):", "g", "t", "b")
  14.     print("Attack(Front):", "q")
  15. end
  16.  
  17. local function renderUI()
  18.     term.clear()
  19.     term.setCursorPos(1,1)
  20.  
  21.     print("last input:", lastInput)
  22.     print("selected", selectedSlot)
  23.     print("        ", selectedSlotData["count"] or 0, selectedSlotData["name"] or "-")
  24.     print("---")
  25.     printUsage()
  26. end
  27.  
  28. while true do
  29.     local event, key, is_held = os.pullEvent("key")
  30.     lastInput = keys.getName(key)
  31.     renderUI()
  32.     if keys["w"] == key then
  33.         mttp.get(modem, "/forward")
  34.     end
  35.     if keys["a"] == key then
  36.         mttp.get(modem, "/turn/left")
  37.     end
  38.     if keys["s"] == key then
  39.         mttp.get(modem, "/back")
  40.     end
  41.     if keys["d"] == key then
  42.         mttp.get(modem, "/turn/right")
  43.     end
  44.     if keys["space"] == key then
  45.         mttp.get(modem, "/up")
  46.     end
  47.     if keys["leftCtrl"] == key then
  48.         mttp.get(modem, "/down")
  49.     end
  50.     if keys["f"] == key then
  51.         mttp.get(modem, "/dig")    
  52.     end
  53.     if keys["r"] == key then
  54.         mttp.get(modem, "/dig/up")
  55.     end
  56.     if keys["v"] == key then
  57.         mttp.get(modem, "/dig/down")
  58.     end
  59.     if keys["up"] == key then
  60.         local status, response = mttp.get(modem, "/inv/up")
  61.         if status == 200 then
  62.             selectedSlot = response["slot"]
  63.             selectedSlotData = response["data"]
  64.         end
  65.     end
  66.     if keys["down"] == key then
  67.         mttp.get(modem, "/inv/down")
  68.     end
  69.     if keys["i"] == key then
  70.         local status, response = mttp.get(modem, "/inv")
  71.         term.clear()
  72.         term.setCursorPos(1,1)
  73.         for i = 1, 16, 1 do
  74.             print(("%2s"):format(i), ("%2s"):format(response[i]["count"] or 0), response[i]["name"] or "-")
  75.         end
  76.     end
  77.  
  78.     renderUI()
  79. end
  80.  
  81.  
Advertisement
Add Comment
Please, Sign In to add comment