cc-stuff/irongen.lua
2025-08-08 21:40:47 -04:00

44 lines
1.3 KiB
Lua

-- Program for managing an iron generator in create with the create: ultimate
-- factory datapack
local store = peripheral.wrap("create:item_vault_0")
local basins = { peripheral.find("create:basin") }
local output = peripheral.wrap("minecraft:chest_0")
local SLEEP_TIME = 8
local BASIN_OUT_SLOT = 10
local IRON_NUGGET = "minecraft:iron_nugget"
local GRAVEL = "minecraft:gravel"
function find_item (inv, item_name)
for i, v in pairs(inv.list()) do
if v.name == item_name then
return i
end
end
end
-- Put items into an inventory until no more can be transferred
function fill_with (src, dest_name, item_name)
local amount_sent = 0
local slot = find_item(src, item_name)
if slot ~= nil then
amount_sent = src.pushItems(dest_name, slot)
end
while amount_sent > 0 do
local slot = find_item(src, item_name)
if slot == nil then
break
end
amount_sent = src.pushItems(dest_name, slot)
end
end
while true do
for _, b in ipairs(basins) do
local basin_name = peripheral.getName(b)
fill_with(store, basin_name, IRON_NUGGET)
fill_with(store, basin_name, GRAVEL)
output.pullItems(basin_name, BASIN_OUT_SLOT)
end
sleep(SLEEP_TIME)
end