Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getItems()
- items={}
- slots={}
- turtle.turnRight()
- turtle.turnRight()
- chestOne=peripheral.wrap("right")
- allItems={}
- for i=1,27 do
- slotItems=chestOne.getStackInSlot(i)
- if slotItems~=nil then
- slotItems['slot']=i
- allItems[#allItems+1]=slotItems
- end
- end
- for nothing,itemData in pairs(allItems) do
- if items[itemData['id']]~=nil then
- items[itemData['id']]={['name']=itemData['name'],['count']=itemData['qty']+items[itemData['id']]['count']}
- else
- items[itemData['id']]={['name']=itemData['name'],['count']=itemData['qty']}
- end
- end
- for nothing,itemData in pairs(allItems) do
- if slots[itemData['slot']]~=nil then
- slots[itemData['slot']]={['name']=itemData['name'],['count']=itemData['qty']+slots[itemData['id']]['count'],['id']=itemData['id']}
- else
- slots[itemData['slot']]={['name']=itemData['name'],['count']=itemData['qty'],['id']=itemData['id']}
- end
- end
- turtle.turnRight()
- turtle.turnRight()
- chestOne=peripheral.wrap("right")
- allItems={}
- for i=1,27 do
- slotItems=chestOne.getStackInSlot(i)
- if slotItems~=nil then
- slotItems['slot']=i
- allItems[#allItems+1]=slotItems
- end
- end
- for nothing,itemData in pairs(allItems) do
- if items[itemData['id']]~=nil then
- items[itemData['id']]={['name']=itemData['name'],['count']=itemData['qty']+items[itemData['id']]['count']}
- else
- items[itemData['id']]={['name']=itemData['name'],['count']=itemData['qty']}
- end
- end
- for nothing,itemData in pairs(allItems) do
- if slots[itemData['slot']]~=nil then
- slots[itemData['slot']]={['name']=itemData['name'],['count']=itemData['qty']+slots[itemData['id']]['count'],['id']=itemData['id']}
- else
- slots[itemData['slot']]={['name']=itemData['name'],['count']=itemData['qty'],['id']=itemData['id']}
- end
- end
- for id,data in pairs(items) do
- print(id.." ("..data['name']..") : "..data['count'])
- end
- for id,data in pairs(slots) do
- print(id.." ("..data['name']..") : "..data['count'])
- end
- return items,slots
- end
- function getsideItemsInSide(side)
- sidesideItems={}
- if side=="north" then
- chestOne=peripheral.wrap("right")
- allsideItems={}
- slots={}
- for i=1,27 do
- slotsideItems=chestOne.getStackInSlot(i)
- if slotsideItems~=nil then
- slotsideItems['slot']=i
- allsideItems[#allsideItems+1]=slotsideItems
- end
- end
- for nothing,itemData in pairs(allsideItems) do
- if sideItems[itemData['id']]~=nil then
- sideItems[itemData['id']]={['name']=itemData['name'],['count']=itemData['qty']+sideItems[itemData['id']]['count']}
- else
- sideItems[itemData['id']]={['name']=itemData['name'],['count']=itemData['qty']}
- end
- end
- for nothing,itemData in pairs(allsideItems) do
- if slots[itemData['slot']]~=nil then
- slots[itemData['slot']]={['name']=itemData['name'],['count']=itemData['qty']+slots[itemData['id']]['count'],['id']=itemData['id']}
- else
- slots[itemData['slot']]={['name']=itemData['name'],['count']=itemData['qty'],['id']=itemData['id']}
- end
- end
- elseif side=="south" then
- turtle.turnRight()
- turtle.turnRight()
- chestOne=peripheral.wrap("right")
- allsideItems={}
- slots={}
- for i=1,27 do
- slotsideItems=chestOne.getStackInSlot(i)
- if slotsideItems~=nil then
- slotsideItems['slot']=i
- allsideItems[#allsideItems+1]=slotsideItems
- end
- end
- for nothing,itemData in pairs(allsideItems) do
- if sideItems[itemData['id']]~=nil then
- sideItems[itemData['id']]={['name']=itemData['name'],['count']=itemData['qty']+sideItems[itemData['id']]['count']}
- else
- sideItems[itemData['id']]={['name']=itemData['name'],['count']=itemData['qty']}
- end
- end
- for nothing,itemData in pairs(allsideItems) do
- if slots[itemData['slot']]~=nil then
- slots[itemData['slot']]={['name']=itemData['name'],['count']=itemData['qty']+slots[itemData['id']]['count'],['id']=itemData['id']}
- else
- slots[itemData['slot']]={['name']=itemData['name'],['count']=itemData['qty'],['id']=itemData['id']}
- end
- end
- turtle.turnRight()
- turtle.turnRight()
- end
- return sidesideItems,slots
- end
- function getSlotsWithItem(slots,id)
- slotsWithItem={}
- if slots~=nil then
- for slot,data in pairs(slots) do
- if data['id']==id then
- slotsWithItem[slot]=data['count']
- end
- end
- return slotsWithItem
- end
- end
- function getSpecificItemCount(id)
- allItems,allSlots=getItems()
- count=items[id]['count']
- return count
- end
- function pullItem(id,count,side)
- sideItems,sideSlots=getItemsInSide(side)
- if sideItems[id]~=nil then
- available=sideItems[id]['count']
- slotsWithitem=getSlotsWithItem(sideSlots,id)
- if side=="north" then
- for slot,availableCount in pairs(slotsWithItem) do
- if availableCount>count then
- temp=peripheral.wrap("right")
- temp.pullItem("south",slot,count,1)
- turtle.dropDown(1)
- else
- temp=peripheral.wrap("right")
- temp.pullItem("south",slot,availableCount,1)
- turtle.dropDown(1)
- count=count-availableCount
- end
- end
- elseif side=="south" then
- turtle.turnRight()
- turtle.turnRight()
- temp=peripheral.wrap("right")
- temp.pullItem()
- turtle.dropDown(1)
- turtle.turnRight()
- turtle.turnRight()
- end
- end
- return count
- end
- getItems()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement