-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathinv.lua
More file actions
102 lines (78 loc) · 2.33 KB
/
inv.lua
File metadata and controls
102 lines (78 loc) · 2.33 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
function isInventoryFull()
for i=1, 16 do
if turtle.getItemCount(i) == 0 then
return false
end
end
return true
end
-- Fixes inventory scattering.
function stackItems()
-- Remember seen items
m = {}
for i=1, 16 do
local this = turtle.getItemDetail(i)
if this ~= nil then
-- Slot is not empty
local saved = m[this.name .. (this.damage or "")]
if saved ~= nil then
-- We've seen this item before in the inventory
local ammount = this.count
turtle.select(i)
turtle.transferTo(saved.slot)
if ammount > saved.space then
-- We have leftovers, and now the
-- saved slot is full, so we replace
-- it by the current one
saved.slot = i
saved.count = ammount - saved.space
-- Update on table.
m[this.name .. (this.damage or "")] = saved
elseif ammount == saved.space then
-- Just delete the entry
m[this.name .. (this.damage or "")] = nil
end
else
-- There isn't another slot with this
-- item so far, so sign this one up.
this.slot = i
this.space = turtle.getItemSpace(i)
m[this.name .. (this.damage or "")] = this
end
end
end
end
function selectItem(name)
for i=1, 16 do
local data = turtle.getItemDetail(i)
if data and data.name == name then
turtle.select(i)
return true
end
end
return false
end
function getItemCount(name)
local count = 0
for i=1, 16 do
local data = turtle.getItemDetail(i)
if data and data.name == name then
count = count + data.count
end
end
return count
end
function dropThrash()
local thrash = {"minecraft:stone", "minecraft:granite", "minecraft:andesite", "minecraft:diorite", "minecraft:cobbled_deepslate", "minecraft:tuff", "minecraft:dirt", "minecraft:coarse_dirt", "minecraft:gravel", "minecraft:sand", "minecraft:red_sand", "minecraft:cobblestone", "minecraft:sandstone", "minecraft:red_sandstone", "minecraft:bedrock", "chisel:limestone", "chisel:marble", "chisel:diorite", "chisel:granite", "chisel:andesite", "harvestcraft:salt"}
for i=1, 16 do
details = turtle.getItemDetail(i)
if details then
for j=1, #thrash do
if details.name == thrash[j] then
turtle.select(i)
turtle.drop()
end
end
end
end
end