Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ship = peripheral.find("warpdriveShipController")
- local ship_front, ship_right, ship_up = ship.dim_positive()
- local ship_back, ship_left, ship_down = ship.dim_negative()
- local ship_isInHyper = ship.isInHyperspace()
- local ship_movement = { ship.movement() }
- local ship_rotationSteps = ship.rotationSteps()
- -- Open rednet on the modem side (adjust "left" as needed)
- rednet.open("top")
- print("Waiting for coordinate broadcasts when redstone is active on the front...")
- while true do
- -- Only process messages when redstone signal on the "front" is on.
- if redstone.getInput("front") then
- -- Use a timeout (0.5 seconds) so the call doesn't block indefinitely and allows rechecking the redstone state.
- local senderID, message, protocol = rednet.receive("coordBroadcast", 0.5)
- if senderID then
- if message and message.x and message.y and message.z then
- print("Received coordinates from computer " .. senderID .. ":")
- print("X: " .. message.x .. ", Y: " .. message.y .. ", Z: " .. message.z)
- local lastLx = tonumber(message.x)
- local lastLy = tonumber(message.y) -- if needed for future use
- local lastLz = tonumber(message.z)
- print("Jumping to X:" .. lastLx .. ", Z:" .. lastLz)
- local rx, ry, rz = ship.getOrientation()
- local minForwardBack = math.abs(ship_front + ship_back + 1)
- local minLeftRight = math.abs(ship_left + ship_right + 1)
- local mx, my, mz = ship.getLocalPosition()
- local dx = lastLx - mx
- local dz = lastLz - mz
- local forwardBackMov = 0
- local leftRightMov = 0
- -- Determine movement based on ship's orientation.
- if rx == 1 then
- forwardBackMov = dx
- leftRightMov = dz
- elseif rx == -1 then
- forwardBackMov = -dx
- leftRightMov = -dz
- elseif rz == 1 then
- forwardBackMov = dz
- leftRightMov = -dx
- elseif rz == -1 then
- forwardBackMov = -dz
- leftRightMov = dx
- end
- if math.abs(forwardBackMov) < minForwardBack and math.abs(leftRightMov) < minLeftRight then
- print("The movement is too small!")
- else
- ship.movement(forwardBackMov, 0, leftRightMov)
- ship.rotationSteps(0)
- ship.command("MANUAL", true)
- end
- else
- print("Received invalid data from computer " .. senderID)
- end
- end
- else
- -- Optionally, you can print a message when redstone is off or simply sleep quietly.
- -- print("Redstone is off on the front; not receiving messages.")
- sleep(0.1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement