Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --imgur : https://imgur.com/a/dVXnwfh
- monitor = peripheral.wrap("monitor_0")
- inputName="minecraft:chest_15"
- outputName="minecraft:chest_14"
- preCountPull=true
- inputChest=peripheral.wrap(inputName)
- outputChest=peripheral.wrap(outputName)
- storageChests={}
- storage={}
- function main()
- setupStorageChests()
- wrong=checkError()
- compileData()
- if(wrong~=nil) then
- return wrong
- end
- monitorMain()
- while true do
- local event, button, x, y = os.pullEvent( "monitor_touch" )
- if(x<11 and y<3) then
- push()
- end
- if(x>19 and y<3) then
- pull()
- end
- end
- end
- function compileData()
- storage={}
- for i, v in ipairs(storageChests) do
- table.insert(storage,i,v.list())
- end
- --save(storage,"data")
- print("Reset compiled data")
- end
- function setupStorageChests()
- storageChestsNames=peripheral.getNames()
- for i, v in ipairs(storageChestsNames) do
- if(v=="bottom") then
- table.remove(storageChestsNames,i)
- end
- end
- for i, v in ipairs(storageChestsNames) do
- if(v=="top") then
- table.remove(storageChestsNames,i)
- end
- end
- for i, v in ipairs(storageChestsNames) do
- if(v=="monitor_0") then
- table.remove(storageChestsNames,i)
- end
- end
- for i, v in ipairs(storageChestsNames) do
- if(v==inputName) then
- table.remove(storageChestsNames,i)
- end
- end
- for i, v in ipairs(storageChestsNames) do
- if(v==outputName) then
- table.remove(storageChestsNames,i)
- end
- end
- for i, v in ipairs(storageChestsNames) do
- table.insert(storageChests,peripheral.wrap(v))
- end
- end
- function push()
- print("Starting to push")
- for i, v in pairs(inputChest.list()) do
- --print(i, v.name)
- index=findSlot()
- print("Storing ",v.count,v.name," in chest",index)
- storageChests[index].pullItems(peripheral.getName(inputChest),i)
- table.insert(storage[index],v)
- --inputChest.pushItems(peripheral.getName( storageChests[index]),i,64,slot)
- end
- print("Pushed everything")
- compileData()
- end
- function pull()
- print("Type name of item, for example: iron_ingot. don't use any prefixes like minecraft:iron_ingot")
- name=read()
- if preCountPull then
- counter=0
- for i, v in ipairs(storage) do --for every chest
- checkChest=storage[i]
- for index=1,54 do --for every slot
- item=storage[i][index]
- if(item~=nil) then --if this passes, we have a slot containing a item
- if name == remove_prefix(item.name) then --if this passes, we have the slot with the correct item!
- counter=counter+item.count
- end
- end
- end
- end
- print("Type amount of item you need, (example: 78), maximum =",counter)
- else
- print("Type amount of item you need, (example: 78)")
- end
- maxCount=tonumber(read())
- ogCount=maxCount
- print("Trying to pull",maxCount,"of",name)
- for i, v in ipairs(storage) do --for every chest
- checkChest=storage[i]
- for index=1,54 do --for every slot
- item=storage[i][index]
- if(item~=nil) then --if this passes, we have a slot containing a item
- if name == remove_prefix(item.name) then --if this passes, we have the slot with the correct item!
- maxCount=maxCount-storageChests[i].pushItems(peripheral.getName(outputChest),index,maxCount)
- end
- end
- end
- end
- print("Finished trying to pull")
- print("Managed to pull",ogCount-maxCount,"items. This is",math.floor((ogCount-maxCount)/ogCount*100),"% of the actual amount")
- compileData()
- end
- function remove_prefix(input) --From ChatGPT
- local result = input:match(":(.+)")
- return result
- end
- function findSlot()
- for i, v in ipairs(storage) do
- checkChest=storage[i]
- for index=1,54 do
- hasItem=storage[i][index]
- if(hasItem==nil) then
- return i
- end
- end
- end
- return nil,nil
- end
- function findSlot1()
- for i, v in ipairs(storageChests) do
- checkChest=storageChests[i]
- for index=1,checkChest.size() do
- hasItem=checkChest.list()[index]
- if(hasItem==nil) then
- return i
- end
- end
- end
- return nil,nil
- end
- function checkError()
- if(monitor==nil) then
- return "NO MONITOR FOUND, Setup a 3x1 monitor setup above the input and output chests, and possibly change line 1 of the program"
- end
- return nil
- end
- function monitorMain()
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.write( "Click here" )
- monitor.setCursorPos(1,2)
- monitor.write( "To input" )
- monitor.setCursorPos(20,1)
- monitor.write( "Click here" )
- monitor.setCursorPos(21,2)
- monitor.write( "To output" )
- monitor.setCursorPos(13,3)
- end
- function save(table,name)
- local file = fs.open(name,"w")
- file.write(textutils.serialize(table))
- file.close()
- end
- print(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement