--declare all variables
--configuration
--chest coontaining the presses and the circuits. This is also the output(highest slot in gui)
local configPressChest = "container_chest_9"
--the chest containing the printed silicon (lowest slot in the gui)
local configSiliconChest = "container_chest_8"
--the chest containing the other materials(the middle slot in the gui)
local configMaterialChest = "container_chest_11"
--not yet implemented
local sleepTime = 1
--time in seconds needed to craft
local craftTime = 10
--need better implementation (for all chests)
local materialChestSide = "west"
--amount of slots in the machine(inscriber has 4)
local machineSlots = 4
--get all the peripherals
local chests={}
chests['top'] = peripheral.wrap(configPressChest)
chests['bottom'] = peripheral.wrap(configSiliconChest)
chests[materialChestSide] = peripheral.wrap(configMaterialChest)
--tables
--crafting recipes
local crafting={}
--silicon
crafting['printedSilicon'] ={'Inscriber Silicon Press',"Silicon"}
--printed circuits
crafting['printedLogic'] ={'Inscriber Logic Press','Gold Ingot'}
crafting['printedCalculation'] ={'Inscriber Calculation Press','Pure Certus Quartz Crystal'}
crafting['printedEngineering'] ={'Inscriber Engineering Press','Diamond'}
--processors
crafting['logicProcessor'] ={'Printed Logic Circuit','Redstone','Printed Silicon'}
crafting['calculationProcessor']={'Printed Calculation Circuit','Redstone','Printed Silicon'}
crafting['EngineeringProcessor']={'Printed Engineering Circuit','Redstone','Printed Silicon'}
--used to get the direction items need to be pushed or pulled from
local useableDirection={north="SOUTH",east="WEST",south="NORTH",west="EAST",top="DOWN",bottom="UP"}
--functions
function craft(ingredients)
local items={}
local amount=0
local errorMessage=nil
local succes=nil
local errorMessage=nil
--remove all items from the machine
cleanup(machineSlots)
--loop over all the items that need to be inserted
for key,value in pairs(ingredients) do
--insert the item
succes,errorMessage=itemToInscriber(key,value)
--if something went wrong give the error message
if not succes then
print(errorMessage)
return false, errorMessage
end
end
--wait until it is done and then all the items need to be removed from the machine
sleep(craftTime)
cleanup(machineSlots)
return true
end
--put the item in the inscriber
function itemToInscriber(slot,needed)
print("inserting ",needed)
local pushed=0
--loop over all the chests, to look if it has the needed items and insert them
for chestKey, chest in pairs (chests) do
--get a table with all the items in the current chest
local items =chest.getAllStacks(false)
--loop over all the items
for key,value in pairs(items) do
--check if the needed item is found
if value['display_name']==needed then
--if the current chests place does not match one of the possibilities give an error
if useableDirection[chestKey] ==nil then
return false , chestKey.." is not a valid place for the chest to be."
end
--push the item to the machine, and get the amount of items that got pushed
pushed=chest.pushItem(useableDirection[chestKey],key,1)
--the amount of pushed items does match one, stop return true and no error message as there was no error to be seen
if pushed==1 then
return true, nil
end
end
end
end
--the needed item was not found or was found but couldn't be inserted, give error + error message
return false,needed.." was not found in the chests"
end
--used to clean the inscriber up
function cleanup (slots)
print("cleaning the machine")
--loop over all the chests
for chestKey,chest in pairs(chests) do
--loop over all the items the machine has
for times=1,slots do
--make sure the chest has an usable direction
if useableDirection[chestKey]~=nil then
chest.pullItem(useableDirection[chestKey],times,64)
end
end
end
end
--other variables
local what=nil
--main loop
while true do
print("Welcome to LC's inscribe'omatic. How can I help you?")
what=io.read()
if crafting[what]~=nil then
print("How much do you want to be made?")
amount=io.read()
print("I'm on it. Making this would require ",((craftTime*amount)+(sleepTime*amount))," seconds to make. Sorry for the inconvenience, I hope you can forgive me.")
for make=1,amount do
craft(crafting[what])
sleep(sleepTime)
end
print("Sir, I am happy to say that your order is done. Look in the press chest to find your crafted items.")
else
print("I am so sorry sir, but I don't know how to make ",what,". I however do know how to make the following:")
for key,value in pairs(crafting)do
print(key)
end
print("I hope you can forgive me.")
end
end