Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Cheststart = 12
- local InputChest = 11
- local ChestAmount = 6
- local Extra = 6
- local ChestType = "iron_chest_"
- local Side = "east"
- local SideO = "west"
- local List = {
- ["Raw Beef"] = 3;
- ["Computer"] = 2;
- ["Networking Cable"] = 2;
- ["Chest"] = 4;
- ["Apple"] = 3;
- [""] = 3;
- ["Dirt"] = 1;
- ["Cobblestone"] = 1;
- ["Iron Ingot"] = 5;
- }
- local Chests = {}
- local MoveItem
- local Input = peripheral.wrap("iron_chest_11")
- for i = 1, ChestAmount do
- Chests[i] = peripheral.wrap(ChestType .. i + Cheststart - 1)
- end
- -- Input.push("west", 0, 64)
- local function Distribute()
- for i = 0, (Input.getSizeInventory() - 1) do
- local t = Input.getStackInSlot(i)
- if t then
- local Match
- for i,v in pairs(List) do
- if i == t["name"] then
- Match = v
- break
- end
- if string.sub(i, 1, 1) == "-" then
- print("Yeah")
- if string.find(t["name"]:lower(), i:sub(2):lower()) then
- Match = v
- break
- end
- end
- end
- if Match then
- print("Moving " .. t["name"] .. " to " .. Match .. " from Input (Distributing)")
- if Match == 1 then
- Input.push(Side, i, 64)
- else
- Input.pushIntoSlot(Side, i, 64, 53)
- MoveItem(1, 53, Match)
- end
- else
- print("Moving " .. t["name"] .. " to " .. Extra .. " from input (Misc.)")
- if Extra == 1 then
- Input.push(Side, i, 64)
- else
- Input.pushIntoSlot(Side, i, 64, 53)
- MoveItem(1, 53, Extra)
- end
- end
- end
- end
- end
- local function CheckOther()
- for i,v in pairs(Chests) do
- for t = 0, v.getSizeInventory() - 1 do
- -- print("Item " .. t)
- local Item = v.getStackInSlot(t)
- if Item then
- local Match
- for r,c in pairs(List) do
- if r == Item["name"] then
- Match = c
- break
- end
- if string.sub(r, 1, 1) == "-" then
- if string.find(Item["name"]:lower(), r:sub(2, #r):lower()) then
- Match = c
- break
- end
- end
- end
- if Match then
- if Match ~= i then
- print("Moving " .. Item["name"] .. " to " .. Match .. " from " .. i .. " (Wrong chest)")
- MoveItem(i, t, Match)
- end
- else
- if i ~= Extra then
- print("Moving " .. Item["name"] .. " to " .. Extra .. " from " .. i .. " (Wrong chest)")
- MoveItem(i, t, Extra)
- end
- end
- end
- end
- end
- end
- MoveItem = function(Chest, Slot, NewChest)
- local MSide = Side
- if NewChest < Chest then
- MSide = SideO
- end
- if Chest - NewChest == 1 or Chest - NewChest == -1 then
- Chests[Chest].push(MSide, Slot, 64)
- return
- end
- local ToGo = NewChest - Chest
- local Der = 1
- local Ha = 0
- if ToGo < 0 then
- Ha = 2
- Der = -1
- end
- Chests[Chest].pushIntoSlot(MSide, Slot, 64, 53)
- for i = Chest + Der, Chest + ToGo - 1 + Ha, Der do
- if i == Chest + ToGo - 1 + Ha then
- Chests[i].push(MSide, 53, 64)
- else
- Chests[i].pushIntoSlot(MSide, 53, 64, 53)
- end
- end
- end
- while true do
- sleep(5)
- Distribute()
- CheckOther()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement