-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinventory.lua
More file actions
47 lines (41 loc) · 1.07 KB
/
inventory.lua
File metadata and controls
47 lines (41 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
local inventory = {}
local totalSlots = 16
function inventory.isFull()
for slot = 1, totalSlots do
if turtle.getItemCount(slot) == 0 then
return false
end
end
return true
end
function inventory.selectSlotWithItem(itemName)
for slot = 1, totalSlots do
if turtle.getItemCount(slot) > 0 then
local item = turtle.getItemDetail(slot)
if item.name == itemName then
return turtle.select(slot)
end
end
end
return false
end
local function isItemExcluded(excludedItems, itemName)
for k, v in pairs(excludedItems) do
if v == itemName then
return true
end
end
return false
end
function inventory.dropAllBut(excludedItems)
for slot = 1, totalSlots do
if turtle.getItemCount(slot) > 0 then
local item = turtle.getItemDetail(slot)
if not isItemExcluded(excludedItems, item.name) then
turtle.select(slot)
turtle.drop()
end
end
end
end
return inventory