Advertisement
SamzFerg

Computercraft 1.7.10 Alchemy Automation - Turtle

May 8th, 2019
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.71 KB | None | 0 0
  1. local COMPUTER_ID = 21                  -- ID Of Computer That Acts as a Logic Controller for the Turtle
  2. local WIRELESS_MODEM_SIZE = "left"      -- Side that has Wireless Modem Equipped
  3. local ANTENNA_SIDE = "right"            -- Side of Turtle that has the duck antenna from openperipheraladdons equipped
  4.  
  5. rednet.open(WIRELESS_MODEM_SIZE)                -- Opens Rednet Communications with Equipped Modem
  6. local Inventory = peripheral.wrap(ANTENNA_SIDE) -- Wraps Turtle's Inventory for Easy Access
  7. local InvSize = Inventory.getInventorySize()    -- Stores Turtle's Inventory Size
  8. local CommandList = {}                          -- Table that will hold the funcations for each command that is send across Rednet
  9.  
  10.  
  11. --Starts the Ritual Crafting by inserting Target Item
  12. function craftItem(name)
  13.     for i=1,InvSize,1 do
  14.         local tmp = Inventory.getStackInSlot(i)
  15.         if(tmp ~= nil) then
  16.             if(tmp.display_name == name) then
  17.                 turtle.select(i)
  18.                 return turtle.drop()
  19.             end
  20.         end
  21.     end
  22.     return false
  23. end
  24.  
  25. --Stops the Ritual from Crafting by removing target item
  26. function stopCraft()
  27.     return turtle.suck()
  28. end
  29.  
  30. CommandList["craft"] = craftItem(x) -- Adds CraftItem to command list with parameter
  31. CommandList["stop"]  = stopCraft()  -- Adds StopCraft to command list
  32.  
  33.  
  34. --Main Control Loop
  35. while(true) do
  36.     local event, id, msg = os.pullEvent("rednet_message") --Waits for Rednet Message From Logic Computer
  37.     local cmd = textutils.unserialize(msg)                --Unserializes Command Table from Rednet Message
  38.    
  39.  
  40.     if(cmd[1] == "craft") then                            --Runs Command and passes parameter with it
  41.         print("Crafting ", cmd[2])
  42.         craftItem(cmd[2])
  43.     elseif (cmd[1] == "stop") then
  44.         print("Craft Finished")
  45.         stopCraft()
  46.     end
  47.  
  48.     sleep(1)                                              --Sleeps for a second
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement