From 10ec47611b9958bdcc5fdeb196a57bd83df69faf Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Mon, 16 Mar 2026 00:07:20 -0400 Subject: [PATCH] Add crafting turtle script to listen for craft commands via modem --- craftingTurtle.lua | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 craftingTurtle.lua diff --git a/craftingTurtle.lua b/craftingTurtle.lua new file mode 100644 index 0000000..0a55a4d --- /dev/null +++ b/craftingTurtle.lua @@ -0,0 +1,45 @@ +-- Crafting Turtle Script +-- Run this on the crafting turtle (turtle with crafting table). +-- Listens for craft commands from the master computer via wired modem. + +local CRAFT_CHANNEL = 4203 +local CRAFT_REPLY_CHANNEL = 4204 + +-- Find modem (wired or wireless) +local modem = peripheral.find("modem") +if not modem then + print("[ERR] No modem found! Attach a wired modem.") + return +end + +modem.open(CRAFT_CHANNEL) + +print("=================================") +print(" Crafting Turtle (Listener)") +print("=================================") +print("") +print("Listening on channel " .. CRAFT_CHANNEL) +print("Ready for craft commands from master.") +print("") + +while true do + local event, side, channel, replyChannel, message = os.pullEvent("modem_message") + if channel == CRAFT_CHANNEL and type(message) == "table" and message.type == "craft" then + local count = message.count or 1 + print(string.format("[CRAFT] Received craft request (count=%d)", count)) + + local ok, err = turtle.craft(count) + + if ok then + print("[CRAFT] Success!") + else + print("[CRAFT] Failed: " .. tostring(err)) + end + + modem.transmit(replyChannel, CRAFT_CHANNEL, { + type = "craft_result", + success = ok, + error = not ok and tostring(err) or nil, + }) + end +end