-- #################################
-- auto_craft <recipe_number>
-- version 0.4.2 (Collaborate with Applied Energistics)
-- http://hevohevo.hatena.com/
-- #################################
-- Turtle position (Side view)
-- E: ME Precious Export Bus (Redstone Mode: "Active without signal"),
-- c: cable for sending redstone signal (use MFR2\'s rednet-cable, or RedPower\'s cable)
-- B: chest for materials (buffer), T: this crafty turtle, I: ME Interface
-- EB
-- CT
-- I
-- ################################
-- Config
-- item slots
MATERIAL_SLOT = 1
PRODUCT_SLOT = 4
-- Waits for items to accumulate in the material chest
SUSPENDED_TIME = 30 -- (sec)
-- For Minefactory Reloaded2 RedNet cable
-- Sets a redstone signal while crafting
CABLE_DIR = "left"
CABLE_COLOR = colors.white --Colors API
-- For setting recipe
-- RECIPE[<number>] = table: <numbers of slots>
N_DEFAULT_RECIPE = 1
RECIPE = {}
RECIPE[1] = {1} -- 1x1
RECIPE[2] = {1,2,5,6} -- 2x2
RECIPE[3] = {1,2,3,5,6,7,9,10,11} -- 3x3
RECIPE[4] = {1,2,3,5,7,9,10,11} -- 3x3donut
-- ################################
-- functions
function dropItems(begin_slot, end_slot)
print(\'drop items: slots \',begin_slot,\'-\',end_slot)
for i=begin_slot, end_slot do
turtle.select(i)
turtle.dropDown()
end
turtle.select(1)
end
function getMaterials()
turtle.select(MATERIAL_SLOT)
if turtle.getItemCount(MATERIAL_SLOT) ==0 and turtle.suckUp() then
print(\' Success: suckUp items\')
return true
else
print(\' Failed: suckUp items\')
return false
end
end
-- distMaterials({1,2,5,6}) -- 2x2
-- distMaterials({1,2,3,5,7,9,10,11}) -- 3x3donut
function distMaterials(slots)
local nTotal = turtle.getItemCount(MATERIAL_SLOT)
local n = nTotal/(#slots)
turtle.select(MATERIAL_SLOT)
if n >=1 then -- succeed
for i,v in pairs(slots) do
turtle.transferTo(v,n)
end
return true
else -- failed
turtle.dropDown()
return false
end
end
function auto_craft()
while turtle.getItemCount(MATERIAL_SLOT) >0 do
if turtle.craft(0) == false then break end
turtle.select(PRODUCT_SLOT)
turtle.craft()
turtle.dropDown()
sleep(0) -- sleep 1 tick(0.05sec)
end
end
-- #################################
-- main
args = {...}
if args[1] and RECIPE[tonumber(args[1])] then
slots_pattern = RECIPE[tonumber(args[1])]
print(\'Recipe No.\',args[1])
else
slots_pattern = RECIPE[N_DEFAULT_RECIPE]
print("Use Default Recipe.")
end
print("Push CTRL+T to terminate.")
dropItems(1,16)
while true do
rs.setBundledOutput(CABLE_DIR, CABLE_COLOR) -- turn ON
while getMaterials() and distMaterials(slots_pattern) do
auto_craft()
dropItems(1,4)
sleep(0)
end
rs.setBundledOutput(CABLE_DIR, 0) -- turn OFF
sleep(SUSPENDED_TIME)
end