Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ship = peripheral.find("warpdriveShipCore")
- local miner = peripheral.find("warpdriveMiningLaser")
- local ship_front, ship_right, ship_up = ship.dim_positive()
- local ship_back, ship_left, ship_down = ship.dim_negative()
- -- Open rednet on the modem side (adjust "top" as needed)
- rednet.open("top")
- print("Waiting for coordinate broadcasts when redstone is active on the front...")
- while true do
- if redstone.getInput("front") then
- -- listen for any protocol, 0.5s timeout
- local senderID, message, protocol = rednet.receive(nil, 0.5)
- if senderID and message and message.x and message.y and message.z then
- local lastLx = tonumber(message.x)
- local lastLy = tonumber(message.y)
- local lastLz = tonumber(message.z)
- -- choose reference point based on protocol
- if protocol == "HorizontalJumpBroadcast"
- or protocol == "HorizontalJumpMinerBroadcast" then
- local mx, my, mz
- if protocol == "HorizontalJumpBroadcast" then
- mx, my, mz = ship.getLocalPosition()
- else
- mx, my, mz = miner.getLocalPosition()
- end
- print(("Received %s → X:%d, Y:%d, Z:%d")
- :format(protocol, lastLx, lastLy, lastLz))
- -- compute movement vector (X/Z plane only)
- local dx = lastLx - mx
- local dz = lastLz - mz
- local rx, ry, rz = ship.getOrientation()
- local minFB = math.abs(ship_front + ship_back + 1)
- local minLR = math.abs(ship_left + ship_right + 1)
- local forwardBackMov = 0
- local leftRightMov = 0
- if rx == 1 then forwardBackMov, leftRightMov = dx, dz
- elseif rx == -1 then forwardBackMov, leftRightMov = -dx, -dz
- elseif rz == 1 then forwardBackMov, leftRightMov = dz, -dx
- elseif rz == -1 then forwardBackMov, leftRightMov = -dz, dx
- end
- if math.abs(forwardBackMov) < minFB and math.abs(leftRightMov) < minLR then
- print("The movement is too small!")
- else
- ship.movement(forwardBackMov, 0, leftRightMov)
- ship.rotationSteps(0)
- ship.command("MANUAL", true)
- end
- end
- end
- else
- -- no redstone signal: wait before retrying
- os.sleep(0.1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment