Advertisement
BungoEntertainment

Untitled

Mar 30th, 2021 (edited)
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.26 KB | None | 0 0
  1. local args = {...}
  2.  
  3. function split (inputstr, sep)
  4.     if sep == nil then
  5.             sep = "%s"
  6.     end
  7.     local t={}
  8.     for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  9.             table.insert(t, str)
  10.     end
  11.     return t
  12. end
  13.  
  14. local commands = {}
  15.  
  16. commands["w"] = function()
  17.     return turtle.forward()
  18. end
  19.  
  20. commands["up"] = function()
  21.     return turtle.up()
  22. end
  23.  
  24. commands["down"] = function()
  25.     return turtle.down()
  26. end
  27.  
  28. commands["a"] = function()
  29.     return turtle.turnLeft()
  30. end
  31.  
  32. commands["d"] = function()
  33.     return turtle.turnRight()
  34. end
  35.  
  36. commands["dig"] = function()
  37.     return turtle.dig()
  38. end
  39.  
  40. commands["digup"] = function()
  41.     return turtle.digUp()
  42. end
  43.  
  44. commands["digdown"] = function()
  45.     return turtle.digDown()
  46. end
  47.  
  48. commands["place"] = function()
  49.     return turtle.place()
  50. end
  51.  
  52. commands["placeup"] = function()
  53.     return turtle.placeUp()
  54. end
  55.  
  56. commands["placedown"] = function()
  57.     return turtle.placeDown()
  58. end
  59.  
  60. commands["refuel"] = function()
  61.     turtle.refuel()
  62.     return "Fuel: " .. turtle.getFuelLevel()
  63. end
  64.  
  65. local cnum = 1
  66. commands["nextslot"] = function()
  67.     cnum = cnum + 1
  68.     if turtle.select(cnum) then
  69.         if turtle.getItemDetail(turtle.getSelectedSlot()) == nil then
  70.             return "Empty Slot " .. turtle.getSelectedSlot()
  71.         end
  72.         return turtle.getItemDetail(turtle.getSelectedSlot()).name .. ": " .. turtle.getSelectedSlot()
  73.     end
  74. end
  75.  
  76. commands["prevslot"] = function()
  77.     cnum = cnum - 1
  78.     if turtle.select(cnum) then
  79.         if turtle.getItemDetail(turtle.getSelectedSlot()) == nil then
  80.             return "Empty Slot " .. turtle.getSelectedSlot()
  81.         end
  82.         return turtle.getItemDetail(turtle.getSelectedSlot()).name .. ": " .. turtle.getSelectedSlot()
  83.     end
  84. end
  85.  
  86. local side = args[1]
  87. if side == nil then
  88.     side = "left"
  89. end
  90.  
  91.  
  92. rednet.open(side)
  93. while true do
  94.     senderID, message, distance = rednet.receive()
  95.    
  96.     local cmds = split(message, " ")
  97.     for i,v in pairs(cmds) do
  98.         local toExec = commands[v]
  99.         if toExec then
  100.             local rmsg = toExec()
  101.             rednet.send(senderID, rmsg)
  102.         else
  103.             rednet.send(senderID, "Invalid command!")
  104.         end
  105.     end
  106. end
  107. rednet.close(side)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement