Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Uncomment to use given pipe side.
- --PipeSide="bottom"
- --Uncomment to use given monitor side(s). Put commas between for multiple sides, keep the curly braces.
- --MonitorSide={"top"}
- sleepTime=60 --In seconds. Default is 60.
- itemsPerTick=10 --How many items it should search per tick. Default is 10.
- checkCount=false --Should it check the amount of items?
- itemThreshold=64 --The max amount of items it can have and still be requested. Default is 64.
- writeToConsole=true --Should it write to the computer itself?
- writeToMonitor=true --Should it write to connected monitors?
- nameWhitelist=true --Should it filter based on a whitelist or a blacklist?
- nameList={} --Unlocalized name(s) of filtered items.
- idWhitelist=true --Should it filter based on a whitelist or a blacklist?
- idList={52} --IDs of filtered items. Supports ID:Meta.
- modWhitelist=true --Should it filter based on a whitelist or a blacklist?
- modList={}
- checkDurability=false --Should it look at durability?
- durabilityPercentThreshold=50 --Items this percentage or lower will be pulled out if checkDurability is true.
- local function getPeripherals(type)
- PerTbl={}
- local Peripherals=peripheral.getNames()
- wildcardBeginning=string.sub(type,1,1)=="*"
- wildcardEnd=string.sub(type,#type)=="*"
- for i=1,#Peripherals do
- index1,index2=string.find(peripheral.getType(Peripherals[i]),type:gsub("*",""))
- if wildcardBeginning and wildcardEnd and index1 then
- table.insert(PerTbl,Peripherals[i])
- elseif wildcardBeginning then
- if index2==#peripheral.getType(Peripherals[i]) then
- table.insert(PerTbl,Peripherals[i])
- end
- elseif wildcardEnd then
- if index1==1 then
- table.insert(PerTbl,Peripherals[i])
- end
- elseif peripheral.getType(Peripherals[i])==type then
- table.insert(PerTbl,Peripherals[i])
- end
- end
- return PerTbl
- end
- local function findPeripheral(type)
- local Peripherals=peripheral.getNames()
- wildcardBeginning=string.sub(type,1,1)=="*"
- wildcardEnd=string.sub(type,#type)=="*"
- for i=1,#Peripherals do
- currentType=peripheral.getType(Peripherals[i])
- index1,index2=string.find(currentType,type:gsub("*",""))
- if wildcardBeginning and wildcardEnd and index1 then
- return Peripherals[i]
- elseif wildcardBeginning then
- if index2==#currentType then
- return Peripherals[i]
- end
- elseif wildcardEnd then
- if index1==1 then
- return Peripherals[i]
- end
- elseif currentType==type then
- return Peripherals[i]
- end
- end
- end
- local function draw(str)
- if writeToMonitor then
- MonTbl=MonitorSide or getPeripherals("monitor")
- for i=1,#MonTbl do
- peripheral.call(MonTbl[i],"write",str)
- end
- end
- if writeToConsole then
- term.write(str)
- end
- end
- local function Clear()
- if writeToMonitor then
- MonTbl=MonitorSide or getPeripherals("monitor")
- for i=1,#MonTbl do
- peripheral.call(MonTbl[i],"clear")
- end
- end
- if writeToConsole then
- term.clear()
- end
- end
- local function CursorPos(x,y)
- if writeToMonitor then
- MonTbl=MonitorSide or getPeripherals("monitor")
- for i=1,#MonTbl do
- peripheral.call(MonTbl[i],"setCursorPos",x,y)
- end
- end
- if writeToConsole then
- term.setCursorPos(x,y)
- end
- end
- function countDown()
- for i=(sleepTime*10),0,-1 do
- CursorPos(1,1)
- draw(clr)
- CursorPos(1,1)
- draw(i/10)
- draw("s until next search.")
- sleep(0.1)
- end
- end
- local function request(id,amt,Count)
- Count=Count+1
- m.makeRequest(id,amt)
- return Count
- end
- --Setup for the main loop
- local clr=""
- local MonTbl=MonitorSide or getPeripherals("monitor")
- local searchTime=0
- x,y=term.getSize()
- for i=1,#MonTbl do
- local p=peripheral.wrap(MonTbl[i])
- local x2,y2=p.getSize()
- x=math.max(x,x2)
- y=math.max(y,y2)
- end
- for i=1,x do
- clr=clr.." " --String that will clear the whole line of a monitor.
- end
- m={}
- if PipeSide and peripheral.getType(PipeSide)=="LogisticsPipes:Request" then
- m=peripheral.wrap(PipeSide)
- else
- if peripheral.find then --Checks to see if peripheral.find exists at all
- m=peripheral.find("LogisticsPipes:Request")
- else
- m=findPeripheral("LogisticsPipes:Request") --This isn't as nice as peripheral.find(), but it'll work.
- end
- end
- if not m then
- error("No request pipe found.")
- end
- --Main loop
- function main()
- local Items=m.getAvailableItems()
- local Count=0
- searchTime=0
- if #Items>itemsPerTick then
- CursorPos(1,2)
- draw("Searching...")
- end
- for k,v in pairs(Items) do
- local id=v.getValue1()
- local amt=m.getItemAmount(id)
- if checkCount and amt<=itemThreshold then
- Count=request(id,amt,Count)
- end
- for i=1,#nameList do
- if nameWhitelist and id.getName()==nameList[i] then
- Count=request(id,amt,Count)
- elseif not nameWhitelist and id.getName()~=nameList[i] then
- Count=request(id,amt,Count)
- end
- end
- for i=1,#idList do
- findColon,findColonEnd=string.find(idList[i],":")
- if findColon then
- if idWhitelist and id.getId()==string.sub(idList[i],1,findColon-1) and id.getData()==string.sub(idList[i],findColon+1) then
- Count=request(id,amt,Count)
- elseif not idWhitelist and id.getId()~=idList[i] then
- Count=request(id,amt,Count)
- end
- else
- if idWhitelist and id.getId()==idList[i] then
- Count=request(id,amt,Count)
- elseif not idWhitelist and id.getId()~=idList[i] then
- Count=request(id,amt,Count)
- end
- end
- end
- for i=1,#modList do
- if modWhitelist and id.getModName()==modList[i] then
- Count=request(id,amt,Count)
- elseif not modWhitelist and id.getModName()~=modList[i] then
- Count=request(id,amt,Count)
- end
- end
- if checkDurability and id.isDamageable() and id.getData()/id.getUndamaged().getData()<=durabilityPercentThreshold/100 then
- Count=request(id,amt,Count)
- end
- if k%itemsPerTick==0 then
- searchTime=searchTime+.05
- sleep(0.05)
- end
- end
- CursorPos(1,2)
- draw(clr)
- CursorPos(1,2)
- if Count==1 then
- draw(Count.." item pulled.")
- else
- draw(Count.." items pulled.")
- end
- end
- --"Real" main loop
- while true do
- parallel.waitForAll(countDown,main)
- end
- --Program by moomoomoo3O9
- --LP ItemIdentifier functions (accessed with m.getAvailableItems()[x].getValue1()
- --getValue2() returns an integer for the LP documentation's functions
- --[[
- getID()
- getUndamaged()
- isFluidContainer()
- getName()
- hasTagCompound()
- getTagCompound()
- getModName()
- isDamageable()
- getType()
- getData()
- getFluidContainer()
- makeStack()
- getIgnoringNBT()
- ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement