Reworked irongen.lua
This commit is contained in:
parent
d5f3debf56
commit
433eff9af9
1 changed files with 24 additions and 14 deletions
38
irongen.lua
38
irongen.lua
|
|
@ -3,7 +3,8 @@
|
|||
|
||||
local store = peripheral.wrap("create:item_vault_0")
|
||||
local basins = { peripheral.find("create:basin") }
|
||||
local output = store
|
||||
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"
|
||||
|
|
@ -16,19 +17,28 @@ function find_item (inv, item_name)
|
|||
end
|
||||
end
|
||||
|
||||
while true do
|
||||
for _, b in ipairs(basins) do
|
||||
local iron_slot = find_item(store, IRON_NUGGET)
|
||||
local gravel_slot = find_item(store, GRAVEL)
|
||||
local basin_name = peripheral.getName(b)
|
||||
if gravel_slot ~= nil then
|
||||
store.pushItems(basin_name, gravel_slot)
|
||||
-- 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
|
||||
if iron_slot ~= nil then
|
||||
store.pushItems(basin_name, iron_slot)
|
||||
else
|
||||
sleep(1)
|
||||
end
|
||||
output.pullItems(basin_name, BASIN_OUT_SLOT)
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue