-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert.lua
More file actions
51 lines (45 loc) · 1.79 KB
/
insert.lua
File metadata and controls
51 lines (45 loc) · 1.79 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
-- insert.lua
-- This script is used to index items to individual chests
-- The index is based on the hash of the item name
local helpers = require("helpers")
local initChests = helpers.initChests
local getChestIndex = helpers.getChestIndex
local mainChestName = "minecraft:chest_0"
local startIdx = 1
local endIdx = 20
-- Initialize the chests
-- So here chest 0 is the main chest, and chests 1 and 2 are the storage chests
local dropChest, storageChests = initChests(mainChestName, startIdx, endIdx)
local function main()
local numChests = #storageChests
local dropItems = dropChest.list()
for slot, item in pairs(dropItems) do
local itemName = item.name
local chestIndex = getChestIndex(itemName, numChests)
local targetChest = storageChests[chestIndex]
local moved = dropChest.pushItems(peripheral.getName(targetChest), slot)
return {status = "Moved " .. moved .. " of " .. itemName .. " to chest " .. chestIndex,
count = moved,
name = itemName,
chestIndex = chestIndex,
shortName = string.sub(itemName, string.find(itemName, ":")+1, #itemName)
}
end
end
local function dump(slot, itemName)
local numChests = #storageChests
local chestIndex = getChestIndex(itemName, numChests)
local targetChest = storageChests[chestIndex]
local moved = dropChest.pushItems(peripheral.getName(targetChest), slot)
return {status = "Moved " .. moved .. " of " .. itemName .. " to chest " .. chestIndex,
count = moved,
name = itemName,
chestIndex = chestIndex,
shortName = string.sub(itemName, string.find(itemName, ":")+1, #itemName)
}
end
-- Run main loop
return {
init = main,
store = dump
}