Advertisement
minecraft_storm

mobileControler

Jul 3rd, 2025 (edited)
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.66 KB | None | 0 0
  1. -- mobile_gui.lua
  2. local basalt = require("/basalt")
  3. local main = basalt.createFrame()
  4.  
  5. local modem = peripheral.find("modem") or error("No modem found")
  6. rednet.open(peripheral.getName(modem))
  7.  
  8. local x, y, z = gps.locate(5)
  9. if not x then error("GPS not available.") end
  10.  
  11. local statusLabel = main:addLabel()
  12.     :setText("Ready to send task")
  13.     :setPosition(2, 2)
  14.  
  15. main:addLabel():setText("Task Type:"):setPosition(2, 4)
  16. local taskType = main:addInput()
  17.     :setPosition(14, 4)
  18.     :setSize(15, 1)
  19.     :setValue("digHole")
  20.  
  21. main:addLabel():setText("Size X:"):setPosition(2, 6)
  22. local sizeX = main:addInput():setPosition(14, 6):setSize(5, 1):setValue("5")
  23.  
  24. main:addLabel():setText("Size Z:"):setPosition(2, 8)
  25. local sizeZ = main:addInput():setPosition(14, 8):setSize(5, 1):setValue("5")
  26.  
  27. main:addLabel():setText("Depth:"):setPosition(2, 10)
  28. local depth = main:addInput():setPosition(14, 10):setSize(5, 1):setValue("3")
  29.  
  30. main:addButton():setText("Send Task")
  31.     :setPosition(2, 12)
  32.     :onClick(function()
  33.         local task = {
  34.             task = taskType:getValue(),
  35.             location = { x = x, y = y, z = z },
  36.             size = {
  37.                 x = tonumber(sizeX:getValue()),
  38.                 z = tonumber(sizeZ:getValue()),
  39.                 depth = tonumber(depth:getValue())
  40.             }
  41.         }
  42.         rednet.broadcast(textutils.serialize(task))
  43.         statusLabel:setText("Sent. Waiting...")
  44.         local _, response = rednet.receive(3)
  45.         if response then
  46.             statusLabel:setText("✓ " .. response)
  47.         else
  48.             statusLabel:setText("✗ No response from base")
  49.         end
  50.     end)
  51.  
  52. basalt.autoUpdate()
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement