You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
miner/chest.lua

50 lines
1.1 KiB

local component = require("component")
local robot = require("robot")
local sides = require("sides")
local inventory = component.inventory_controller;
local function contains(arr, val)
for _, value in ipairs(arr) do
if value == val then
return true
end
end
return false
end
local function store_stack(slot)
robot.select(slot)
local slots = inventory.getInventorySize(sides.forward)
for s = 1, slots do
local result, _ = inventory.dropIntoSlot(sides.forward, s)
if result then
local stack = inventory.getStackInInternalSlot(slot)
if stack == nil then
break
end
end
end
end
local function store(whitelist)
local slots = robot.inventorySize()
for slot = 2, slots do
local item = inventory.getStackInInternalSlot(slot)
if item then
if whitelist ~= nil then
if contains(whitelist, item.name) then
store_stack(slot)
end
else
store_stack(slot)
end
end
end
end
return {
store = store,
}