View difference between Paste ID: eZYPJKGi and 3bvfitu3
SHOW: | | - or go back to the newest paste.
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-
sleep(0.08)
17+
18-
local state = 0
18+
    -- Check redstone input on a specific side (e.g., "back")
19-
local CMD = 0
19+
    if redstone.getInput("front") then
20-
  state, CMD = chat.pullLastCommand()
20+
        local state, CMD = chat.pullLastCommand()
21-
    string = string.lower(CMD)
21+
        
22-
 
22+
        -- Use a new variable name instead of 'string' so as not to overwrite the library
23-
      -- Match and extract X and Z
23+
        local cmdText = string.lower(CMD or "")
24-
 local x_value, y_value, z_value = string:match(".*x:(%-?%d+),%s*y:(%-?%d+),%s*z:(%-?%d+)")
24+
        
25
        -- Match and extract coordinates; allow for negative numbers with %-?
26-
    if state then
26+
        local x_value, y_value, z_value = cmdText:match(".*x:(%-?%d+),%s*y:(%-?%d+),%s*z:(%-?%d+)")
27-
        if not (x_value and y_value and z_value) then
27+
        
28-
            print("Error: Coordinates not found in command.")
28+
        if state then
29-
        else
29+
            if not (x_value and y_value and z_value) then
30-
            local lastLx = tonumber(x_value)
30+
                print("Error: Coordinates not found in command.")
31-
            local lastLy = tonumber(y_value)  -- if needed for future use
31+
32-
            local lastLz = tonumber(z_value)
32+
			else if not redstone.getInput("front") then
33-
            
33+
				print("Inactive: Redstone was not active.")
34-
            print("Jumping to X:" .. lastLx .. ", Z:" .. lastLz)
34+
35-
            
35+
                local lastLx = tonumber(x_value)
36-
            local rx, ry, rz = ship.getOrientation()
36+
                local lastLy = tonumber(y_value)  -- Currently not used; included for possible future use.
37-
            local minForwardBack = math.abs(ship_front + ship_back + 1)
37+
                local lastLz = tonumber(z_value)
38-
            local minLeftRight = math.abs(ship_left + ship_right + 1)
38+
                
39-
            local mx, my, mz = ship.getLocalPosition()
39+
                print("Jumping to X:" .. lastLx .. ", Z:" .. lastLz)
40-
            
40+
                
41-
            local dx = lastLx - mx
41+
                local rx, ry, rz = ship.getOrientation()
42-
            local dz = lastLz - mz
42+
                local minForwardBack = math.abs(ship_front + ship_back + 1)
43-
            
43+
                local minLeftRight = math.abs(ship_left + ship_right + 1)
44-
            local forwardBackMov = 0
44+
                local mx, my, mz = ship.getLocalPosition()
45-
            local leftRightMov = 0
45+
                
46-
            
46+
                local dx = lastLx - mx
47-
            -- Determine movement based on ship's orientation.
47+
                local dz = lastLz - mz
48-
            if rx == 1 then
48+
                
49-
                forwardBackMov = dx
49+
                local forwardBackMov = 0
50-
                leftRightMov = dz
50+
                local leftRightMov = 0
51-
            elseif rx == -1 then
51+
                
52-
                forwardBackMov = -dx
52+
                -- Determine movement based on the ship's orientation.
53-
                leftRightMov = -dz
53+
                if rx == 1 then
54-
            elseif rz == 1 then
54+
                    forwardBackMov = dx
55-
                forwardBackMov = dz
55+
                    leftRightMov = dz
56-
                leftRightMov = -dx
56+
                elseif rx == -1 then
57-
            elseif rz == -1 then
57+
                    forwardBackMov = -dx
58-
                forwardBackMov = -dz
58+
                    leftRightMov = -dz
59-
                leftRightMov = dx
59+
                elseif rz == 1 then
60
                    forwardBackMov = dz
61-
            
61+
                    leftRightMov = -dx
62-
            if math.abs(forwardBackMov) < minForwardBack and math.abs(leftRightMov) < minLeftRight then
62+
                elseif rz == -1 then
63-
                print("The movement is too small!")
63+
                    forwardBackMov = -dz
64
                    leftRightMov = dx
65-
                ship.movement(forwardBackMov, 0, leftRightMov)
65+
                end
66-
                ship.rotationSteps(0)
66+
                
67-
                ship.command("MANUAL", true)
67+
                if math.abs(forwardBackMov) < minForwardBack and math.abs(leftRightMov) < minLeftRight then
68
                    print("The movement is too small!")
69
                else
70-
    end
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