Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- apis/ChestManagement
- -- Print what is inside the chest in front of the turtle
- function whatIsInChest()
- if turtle.detectDown() then
- turtle.digDown()
- end
- turtle.select(16)
- turtle.placeDown()
- turtle.select(1)
- -- Move everything from the chest in front to the swap chest below
- while turtle.suck() do
- if not turtle.dropDown() then
- -- The swap chest is smaller than the source chest :(
- print("Bottom chest is full?? Reverting")
- while turtle.suckDown() do
- turtle.drop()
- end
- return false
- end
- end
- local contents = {}
- -- Move everything from the swap chest back into the chest in front
- while turtle.suckDown() do
- local info = turtle.getItemDetail(1)
- -- Look through existing content to see if it matches
- for k, tItem1 in pairs(contents) do
- if itemsAreTheSame(tItem1, info) then
- contents[k].count = contents[k].count + info.count
- info = nil
- break
- end
- end
- if info ~= nil then
- table.insert(contents, info)
- end
- turtle.drop()
- end
- -- Put the swap chest back into the inventory
- turtle.select(16)
- turtle.digDown()
- turtle.select(1)
- for k, v in pairs(contents) do
- for k2, v2 in pairs(v) do
- print(k2 .. ": " .. v2)
- end
- print(" ")
- end
- return contents
- end
- function itemsAreTheSame(tItem1, tItem2)
- if tItem1 == nil then
- return false
- end
- if tItem2 == nil then
- return false
- end
- for k, v in pairs(tItem1) do
- if k ~= "count" and tItem1[k] ~= tItem2[k] then
- return false
- end
- end
- -- Check it based on the keys for tItem2 just in case it has some extra important key
- for k, v in pairs(tItem2) do
- if k ~= "count" and tItem1[k] ~= tItem2[k] then
- return false
- end
- end
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement