Advertisement
jaklsfjlsak

遥控语音制导321-25 红石

Mar 21st, 2025 (edited)
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local ship = peripheral.find("warpdriveShipController")
  2. local chat = peripheral.find("warpdriveVirtualAssistant")
  3.  
  4. -- Define chat name
  5. chat.name("[name")
  6.  
  7. local ship_front, ship_right, ship_up = ship.dim_positive()
  8. local ship_back, ship_left, ship_down = ship.dim_negative()
  9. local ship_isInHyper = ship.isInHyperspace()
  10. local ship_movement = { ship.movement() }
  11. local ship_rotationSteps = ship.rotationSteps()
  12.  
  13. print("Post Way Point in Chat to Jump Ship and Aligning the Mining Laser")
  14.  
  15. while true do
  16.     sleep(0.08)
  17.    
  18.     -- Check redstone input on a specific side (e.g., "back")
  19.     if redstone.getInput("front") then
  20.         local state, CMD = chat.pullLastCommand()
  21.        
  22.         -- Use a new variable name instead of 'string' so as not to overwrite the library
  23.         local cmdText = string.lower(CMD or "")
  24.        
  25.         -- Match and extract coordinates; allow for negative numbers with %-?
  26.         local x_value, y_value, z_value = cmdText:match(".*x:(%-?%d+),%s*y:(%-?%d+),%s*z:(%-?%d+)")
  27.        
  28.         if state then
  29.             if not (x_value and y_value and z_value) then
  30.                 print("Error: Coordinates not found in command.")
  31.  
  32.             else if not redstone.getInput("front") then
  33.                 print("Inactive: Redstone was not active.")
  34.             else
  35.                 local lastLx = tonumber(x_value)
  36.                 local lastLy = tonumber(y_value)  -- Currently not used; included for possible future use.
  37.                 local lastLz = tonumber(z_value)
  38.                
  39.                 print("Jumping to X:" .. lastLx .. ", Z:" .. lastLz)
  40.                
  41.                 local rx, ry, rz = ship.getOrientation()
  42.                 local minForwardBack = math.abs(ship_front + ship_back + 1)
  43.                 local minLeftRight = math.abs(ship_left + ship_right + 1)
  44.                 local mx, my, mz = ship.getLocalPosition()
  45.                
  46.                 local dx = lastLx - mx
  47.                 local dz = lastLz - mz
  48.                
  49.                 local forwardBackMov = 0
  50.                 local leftRightMov = 0
  51.                
  52.                 -- Determine movement based on the ship's orientation.
  53.                 if rx == 1 then
  54.                     forwardBackMov = dx
  55.                     leftRightMov = dz
  56.                 elseif rx == -1 then
  57.                     forwardBackMov = -dx
  58.                     leftRightMov = -dz
  59.                 elseif rz == 1 then
  60.                     forwardBackMov = dz
  61.                     leftRightMov = -dx
  62.                 elseif rz == -1 then
  63.                     forwardBackMov = -dz
  64.                     leftRightMov = dx
  65.                 end
  66.                
  67.                 if math.abs(forwardBackMov) < minForwardBack and math.abs(leftRightMov) < minLeftRight then
  68.                     print("The movement is too small!")
  69.                 else
  70.                     ship.movement(forwardBackMov, 0, leftRightMov)
  71.                     ship.rotationSteps(0)
  72.                     ship.command("MANUAL", true)
  73.                 end
  74.             end
  75.         end
  76. end
  77. end
  78. end
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement