Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local TURTLE_ID = 22 -- ID of Turtle that changes what item is being crafted by the ritual
- local WIRELESS_MODEM_SIDE = "top" -- Side of Computer Wireless Modem is Placed On
- local RITUAL_OUTPUT = "ender_chest_0" -- Address of Ritual Output Inventory
- rednet.open(WIRELESS_MODEM_SIDE) -- Opens rednet communication with the wireless modem
- local EnderChest = peripheral.wrap(RITUAL_OUTPUT) -- Wraps the Ritual Output as an Inventory
- local OuputSize = EnderChest.getInventorySize() -- Size of output Inventory
- local ItemCounts = {} -- Table with amount of each item in the inventory
- local ONE_X_CRAFT_LIMIT = 64 -- Lower Bound of Items That Craft 1 at a Time Before They Need To Be Crafted
- local TWO_X_CRAFT_LIMIT = 63 -- Lower Bound of items That Craft 2 at a Time Before They Need To Be Crafted
- local FOUR_X_CRAFT_LIMIT = 61 -- Lower Bound of items That Craft 4 at a Time Before They Need To Be Crafted
- --List of Items to Craft
- ItemCounts["Simple Catalyst"] = 0
- ItemCounts["Strengthened Catalyst"] = 0
- ItemCounts["Concentrated Catalyst"] = 0
- ItemCounts["Fractured Bone"] = 0
- ItemCounts["Magicales"] = 0
- ItemCounts["Tenebrae"] = 0
- ItemCounts["Terrae"] = 0
- ItemCounts["Aether"] = 0
- ItemCounts["Sanctus"] = 0
- OutputSize = 54
- --Gets the aount of the specified item in the ritual output
- function getItemCount(name)
- local count = 0
- for i=1,OutputSize,1 do
- local tmp = EnderChest.getStackInSlot(i)
- if(tmp ~= nil) then
- if(tmp.display_name == name) then
- count = count + tmp.qty
- end
- end
- end
- return count
- end
- --Updates each of the items with how much of each are in the ritual output
- function refreshItemCount()
- for k,v in pairs(ItemCounts) do
- ItemCounts[k] = getItemCount(k)
- end
- end
- --Tells Turtle to Stop Crafting Whatever Item is Being Crafted
- function stopCraft()
- local msg = {"stop"}
- rednet.send(TURTLE_ID, textutils.serialize(msg))
- end
- --Requests Turtle to being Crafting specified item
- function requestCraft(item)
- local msg = {"craft", item}
- rednet.send(TURTLE_ID, textutils.serialize(msg))
- end
- --Checks if specified item is below the limit or now
- function isBelowLimit(item)
- if(ItemCounts[item] == nil) then --returns if the item doesn't exist in list
- return
- end
- if(item == "Strengthened Catalyst") then --Grabs Strengthened Catalyst Seperatly becuase it crafts 2 at once.
- return(ItemCounts[item] < TWO_X_CRAFT_LIMIT) --Returns if QTY of Strengthened Catalyst is Below Limit For 2x Crafts
- elseif (item == "Fractured Bone") then
- return(ItemCounts[item] < FOUR_X_CRAFT_LIMIT)
- else
- return(ItemCounts[item] < ONE_X_CRAFT_LIMIT) --Returns if QTY of Strengthened Catalyst is Below Limit For 1x Crafts
- end
- end
- local currentCraft = "" --Holds Name of Currently Crafting Item
- --Main Program Loop
- while (true) do
- refreshItemCount() --At the beginning of every loop, refreshes the item count table
- if (isBelowLimit(currentCraft) == false) then --if the current crafting item has reached its limists
- print("Restocked ", currentCraft)
- currentCraft = ""
- stopCraft()
- sleep(2) --Has Progam Sleep To give Turtle Time to Remove Item From Altar
- end
- if(currentCraft == "") then --If there we aren't crafting anything currently
- for k,v in pairs(ItemCounts) do --Loops Through ItemCount Table to Check Each Item
- if(isBelowLimit(k)) then --If Item is Below the Limit
- currentCraft = k --Sets Current Craft Variable
- requestCraft(k) --Request Craft From Turtle
- print("Requesting ", k)
- break --leaves the loops so no more crafts are requested
- end
- end
- end
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment