Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FARM_ITEMS ={}
- FARM_ITEMS["minecraft:wheat_seeds"] = 128
- FARM_ITEMS["minecraft:oak_sapling"] = 128
- STORAGE_ITEMS = {}
- STORAGE_ITEMS["minecraft:sugar_cane"] = 5120
- STORAGE_ITEMS["minecraft:wheat"] = 5120
- STORAGE_ITEMS["minecraft:wheat_seeds"] = 1280
- STORAGE_ITEMS["minecraft:kelp"] = 5120
- STORAGE_ITEMS["minecraft:oak_sapling"] = 1280
- STORAGE_ITEMS["minecraft:oak_log"] = 5120
- STORAGE_ITEMS["minecraft:apple"] = 640
- STORAGE_ITEMS["minecraft:stick"] = 640
- local farm_side = "left"
- local storage_side = "right"
- local void_side = "bottom"
- farm = peripheral.wrap(farm_side)
- storage = peripheral.wrap(storage_side)
- function itemList(inventory)
- accumulator = {}
- if inventory then
- for i,slot in pairs(inventory) do
- if accumulator[slot.name] then
- accumulator[slot.name] = slot.count+accumulator[slot.name]
- else
- accumulator[slot.name] = slot.count
- end
- end
- end
- return accumulator
- end
- function printT(T)
- print(textutils.serializeJSON(T))
- end
- function getKey0(T,K)
- if T[K] then
- return T[K]
- end
- return 0
- end
- function moveItems(source,dest,item_id,count)
- c = count
- i = source.list()
- if not i then
- return
- end
- for slot,item in pairs(i) do
- if item.name == item_id then
- if slot < 1 then
- return
- end
- if c < 1 then
- return
- end
- r = source.pushItems(dest,slot,c)
- n = 0
- if r then
- n = r
- end
- c = c - n
- end
- end
- end
- function min(a,b)
- if a<b then
- return a
- end
- return b
- end
- function max(a,b)
- if a>b then
- return a
- end
- return b
- end
- while 1==1 do
- inv_farm = itemList(farm.list())
- inv_storage = itemList(storage.list())
- for item_id,item_count in pairs(inv_farm) do
- overCount = item_count-getKey0(FARM_ITEMS,item_id)
- if overCount > 0 then
- usingCount = max(0,min(getKey0(STORAGE_ITEMS,item_id)-getKey0(inv_storage,item_id),overCount))
- voidingCount = max(0,overCount - usingCount)
- if usingCount > 0 then
- --store
- print("using",usingCount,item_id)
- moveItems(farm,storage_side,item_id,usingCount)
- end
- if voidingCount > 0 then
- --void
- print("voiding",voidingCount,item_id)
- moveItems(farm,void_side,item_id,voidingCount)
- end
- end
- end
- sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment