Skip to content

Instantly share code, notes, and snippets.

@ZeekDaGeek
Created July 23, 2015 11:54
Show Gist options
  • Save ZeekDaGeek/2e25ed3439969f437835 to your computer and use it in GitHub Desktop.
Save ZeekDaGeek/2e25ed3439969f437835 to your computer and use it in GitHub Desktop.
-- Designed to automatically manage a blood alter.
-- v0.1 - Not finished.
-- By: ZeekDaGeek
local component = require("component")
local sides = require("sides")
local term = require("term")
local inv = component.inventory_controller
local robot = component.robot
local bloodAlter = {}
local ingredients = {}
-- Config
bloodAlter.side = sides.bottom -- (Required) The side with the Blood Alter
ingredients.input_side = nil -- (Optional) Input side for mass crafting
ingredients.output_side = sides.top -- (Optional) Output side for mass crafting
ingredients.inputItem_slot = 1 -- (Required) The internal slot containing the input item for reference.
ingredients.outputItem_slot = 2 -- (Required) The internal slot containing the output item for reference.
-- Don't change these.
bloodAlter.slot = 1
-- Validate info.
function validateConfig()
local invSize,_ = inv.getInventorySize(bloodAlter.side)
if (type(invSize) == "nil") then
term.clear()
term.write("Unable to find an inventory on the Blood Alter side.")
return false
end
end
-- Attempt to process an ingredient through the Blood Alter.
function attemptAlterPush()
local inputItem = inv.getStackInInternalSlot(ingredients.inputItem_slot)
-- Check if there's items in input slot comparison.
if (inputItem == nil) then
term.clear()
term.write(string.format("An input item should be in slot %i, none was found.", ingredients.inputItem_slot))
return false
end
inputItem.slot = ingredients.inputItem_slot
-- Check if there's extra items in the input slot, use them if available.
if (inputItem.size > 1) then
robot.select(inputItem.slot)
inv.dropIntoSlot(bloodAlter.side, bloodAlter.slot, 1)
return true
end
-- Check if there are any input items anywhere in the inventory.
for i=1,16 do
if (i ~= ingredients.inputItem_slot and i ~= ingredients.outputItem_slot) then
local checkItem = inv.getStackInInternalSlot(i)
if (checkItem ~= nil) then
checkItem.slot = i
if (inputItem.name == checkItem.name and inputItem.damage == checkItem.damage) then
robot.select(checkItem.slot)
inv.dropIntoSlot(bloodAlter.side, bloodAlter.slot, 1)
return true
end
end
end
end
return false
end
-- Attempt to pull the output item from the Blood Alter.
function attemptAlterPull()
local outputItem = inv.getStackInInternalSlot(ingredients.outputItem_slot)
-- Check if there's items in input slot comparison.
if (outputItem == nil) then
term.clear()
term.write(string.format("An output item should be in slot %i, none was found.", ingredients.outputItem_slot))
return false
end
outputItem.slot = ingredients.outputItem_slot
local alterItem = inv.getStackInSlot(bloodAlter.side, bloodAlter.slot)
if (alterItem == nil) then
return false
end
if (alterItem.name == outputItem.name and alterItem.damage == outputItem.damage) then
robot.select(outputItem.slot)
inv.suckFromSlot(bloodAlter.side, bloodAlter.slot)
return true
end
return false
end
-- Pull input items from the input inventory if it exists, as well as push output items if output inventory exists.
function doInputOutput()
-- Check if an Input Inventory exists.
--if (ingredients.input_side ~= nil)
end
while true do
if (validateConfig() == false) then return false end
-- Get item in Blood Alter.
bloodAlter.item = inv.getStackInSlot(bloodAlter.side, 1)
-- Check if the Blood Alter is empty
-- If the slot is empty attempt to fill it.
if (type(bloodAlter.item) == "nil") then
attemptAlterPush()
else
attemptAlterPull()
end
os.sleep(0.5);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment