Last active
August 29, 2015 14:20
-
-
Save Keridos/0ef14d8da59a43e09db8 to your computer and use it in GitHub Desktop.
OpenComputers AE Controller example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local comp = require("component") | |
local term = require("term") | |
local event = require("event") | |
local gpu = comp.gpu | |
local ae = comp.getPrimary("mekanism_machine") | |
local craftingList = {} | |
local craftingLog = {} | |
local crafting = {} | |
local toCraft = { | |
["Stick"] = 1000, | |
["Oak Wood Planks"] = 512, | |
["Piston"] = 100 , | |
["Sticky Piston"] = 100, | |
--["Conduit Binder"] = 250, | |
["Chest"] = 128, | |
["Blaze Powder"] = 64, | |
["Gold Nugget"] = 400, | |
--["Electrical Steel"] = 256, | |
--["Energetic Alloy"] = 256, | |
--["Vibrant Alloy"] = 256, | |
--["Redstone Alloy"] = 256, | |
["Pure Certus Quartz Crystal"] = 256, | |
["Pure Nether Quartz Crystal"] = 256, | |
["Pure Fluix Crystal"] = 256, | |
["Certus Quartz Dust"] = 256, | |
["Fluix Dust"] = 256, | |
["Quartz Fiber"] = 64, | |
["ME Dense Cable - Fluix"] = 64, | |
["ME Smart Cable - Fluix"] = 64, | |
["Logic Processor"] = 256, | |
["Calculation Processor"] = 128, | |
["Engineering Processor"] = 64, | |
["Formation Core"] = 32, | |
["Annihilation Core"] = 32, | |
["ME Interface"] = 32, | |
["Hardened Glass"] = 256, | |
["Electrum Ingot"] = 256, | |
["Invar Ingot"] = 256, | |
["Signalum Ingot"] = 64, | |
["Lumium Ingot"] = 64, | |
["Enderium Ingot"] = 256, | |
["Bronze Ingot"] = 256, | |
["Steel Ingot"] = 256 | |
} | |
function printTerm(text) | |
term.setCursor(1,5) | |
term.write(" ") | |
term.setCursor(1,5) | |
term.write(text) | |
end | |
function printJobs() | |
local i = 5 | |
for k,v in pairs(craftingList) do | |
term.setCursor(40,i) | |
term.write(" ") | |
term.setCursor(40,i) | |
term.write(k.." x "..v) | |
i = i + 1 | |
end | |
for j=i,25 do | |
term.setCursor(40,j) | |
term.write(" ") | |
end | |
end | |
function addCraftingToList(name, number) | |
craftingList[name] = number | |
printJobs() | |
end | |
function removeCraftingFromList(name) | |
for k,v in pairs(craftingList) do | |
if k == name then craftingList[k] = nil end | |
end | |
printJobs() | |
end | |
function checkCrafting(label) | |
if crafting[label] == nil then | |
removeCraftingFromList(label) | |
return true | |
elseif crafting[label].isDone() then | |
printTerm(label.." done") | |
crafting[label] = nil | |
removeCraftingFromList(label) | |
return false | |
elseif crafting[label].isCanceled() then | |
printTerm(label.." canceled") | |
crafting[label] = nil | |
removeCraftingFromList(label) | |
return false | |
else | |
return false | |
end | |
end | |
function craftingManager() | |
for labelString,number in pairs(toCraft) do | |
filter = { label = labelString } | |
if ae.getCraftables(filter)[1] ~= nil then | |
craft = ae.getCraftables(filter)[1] | |
else | |
break | |
end | |
if ae.getItemsInNetwork(filter)[1] ~= nil then | |
itemsInAE = ae.getItemsInNetwork(filter)[1] | |
else | |
itemsInAE= { size = 0 } | |
end | |
if number-itemsInAE.size > 0 then | |
if checkCrafting(labelString) then | |
crafting[labelString] = craft.request(number-itemsInAE.size) | |
if crafting[labelString] == nil or crafting[labelString].isCanceled() == true then | |
printTerm("fail "..number-itemsInAE.size .. " x " .. labelString) | |
crafting[labelString] = nil | |
else | |
printTerm("success "..number-itemsInAE.size .. " x " .. labelString) | |
addCraftingToList(labelString,number-itemsInAE.size) | |
end | |
end | |
end | |
end | |
end | |
function main() | |
gpu.setResolution(80,25) | |
term.clear() | |
term.write("CraftingManager by Keridos") | |
term.setCursor(1,4) | |
term.write("Last Log:") | |
term.setCursor(40,4) | |
term.write("Current Jobs:") | |
while true do | |
craftingManager() | |
for k,v in pairs(craftingList) do | |
checkCrafting(k) | |
end | |
term.setCursor(1,3) | |
term.write(" ") | |
os.sleep(1) | |
end | |
end | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
comp = require("component") | |
ae = comp.getPrimary("mekanism_machine") | |
filesystem = require("filesystem") | |
local craftables = ae.getCraftables() | |
os.remove("craftables") | |
file = io.open("craftables","w") | |
for i,j in pairs(craftables) do | |
if not(i == "n") then | |
file:write(i .. " " .. j.getItemStack().name .. " "..j.getItemStack().damage .." " .. j.getItemStack().label .."\n") | |
end | |
end | |
file:close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment