Skip to content

Instantly share code, notes, and snippets.

@bananasov
Created August 7, 2023 15:52
Show Gist options
  • Save bananasov/07137937d32aa26ad71fcdc0d3f7b725 to your computer and use it in GitHub Desktop.
Save bananasov/07137937d32aa26ad71fcdc0d3f7b725 to your computer and use it in GitHub Desktop.
Industrial Revolution + CC: Tweaked auto farming thing for the farmer machine
local sides = {
barrel = "top",
machine = "bottom"
}
local barrel = peripheral.wrap(sides.barrel)
local machine = peripheral.wrap(sides.machine)
local input_slots = {
2, 3,
4, 5
}
local output_slots = {
6, 7, 8,
9, 10, 11,
12, 13, 14,
}
---@param name string
local function is_seed(name)
return name:lower():find("seed") and true or false
end
--- Returns the total count of seeds in the input slots.
---@return number
local function check_seed_input_count()
local count = 0
for _, slot in pairs(input_slots) do
local detail = machine.getItemDetail(slot)
if detail then
count = count + detail.count
end
end
return count
end
while true do
for _, slot in pairs(output_slots) do
local detail = machine.getItemDetail(slot)
if detail then
if is_seed(detail.name) then
-- Check if theres 3 stacks of seeds inside the input slots
if check_seed_input_count() >= 192 then
print("input slots are at 3 stacks, sending 3 stacks to barrel")
local slots = {3, 4, 5}
for _, ohyeahaslot in pairs(slots) do
barrel.pullItems(sides.machine, ohyeahaslot, 64)
end
end
print(("Seed: slot=%d; count=%d"):format(slot, detail.count))
-- pushItems(toName, fromSlot [, limit [, toSlot]])
machine.pushItems(sides.machine, slot, detail.count)
else
print(("%s: slot=%d; count=%d"):format(detail.displayName, slot, detail.count))
-- pullItems(fromName, fromSlot [, limit [, toSlot]])
barrel.pullItems(sides.machine, slot, detail.count)
end
end
end
sleep(1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment