Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local whiteList = {
- "minecraft:skull", 3,
- "minecraft:soul_sand", 4,
- }
- while true do
- local bool,data = turtle.inspect()
- if bool then
- print("Redstone level is "..data.metadata)
- end
- if data.metadata > 9 then
- print("Redstone acceptable. Doing the thing")
- turtle.turnLeft()
- for i = 1, 16 do --Dump inventory
- local data = turtle.getItemDetail(i)
- if data then
- turtle.select(i)
- turtle.drop()
- end
- end
- --Grab everything in 16 slot chest and make a list of each item, slot, and count
- local itemList = {}
- turtle.select(1)
- for i = 1, 16 do
- turtle.select(i)
- turtle.suck()
- local data = turtle.getItemDetail(i)
- if not itemList[data.name] then --If new item then make a table for it
- itemList[data.name] = {}
- itemList[data.name][1] = { count = data.count, slot = i }
- else --Item has already been seen. Insert an entry
- itemList[data.name][ #itemList[data.name]+1 ] = {count = data.count, slot = i}
- end
- end
- --Clear inventory of everything and all amounts not specified in whiteList
- for i,name in pairs(itemList) do --Iterate through every name in the item list
- for k = 1, #whiteList, 2 do --Iterate through whitelist and check name against it
- if name ~= whiteList[k] and k == #whiteList-1 do --Name is not on whitelist. Dump it
- for j = 1, #itemList[name] do
- turtle.select(itemList[name][j].slot)
- turtle.drop()
- end
- break
- elseif name == whiteList[k] then --Name is on the whitelist. Dump extra items
- --Get target amount for whitelisted item
- local tA
- for j = 1, #whiteList, 2 do
- if whiteList[j] == name then
- tA = whitelist[j+1]
- break
- end
- end
- --Dump extra
- for l = 1, #itemList[name] do
- local keepAmount = 0
- if itemList[name][l].count + keepAmount < tA then --We don't have enough saved yet
- if itemList[l].count > tA + keepAmount then --Too much in this slot
- turtle.drop(itemList[name][l].count-tA)
- keepAmount = tA
- else
- keepAmount = keepAmount + itemList[name][l].count --Not enough in just this slot
- end
- else --We've saved enough. Dump the extra
- turtle.select(itemList[name][l].slot)
- turtle.drop()
- end
- end
- end
- end
- end
- else
- print("Not doing the thing")
- end
- turtle.turnRight()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement