Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Initalise
- rs.setBundledOutput("left", 0)
- rs.setBundledOutput("left", colors.red)
- drawers = peripheral.wrap("front")
- screen = peripheral.wrap("bottom")
- -- Make distal name:slot_ID table
- function tableHelper()
- local drawer_slots = {}
- for ID, slot in pairs(drawers.getAllStacks()) do
- drawer_slots[slot.all().id] = ID
- print(ID, " ", slot.all().id)
- end
- return drawer_slots
- end
- -- Function to help pull to full
- function pullHelper(turtle_slot, drawer_slot, number)
- local to_pull = number - turtle.getItemCount(turtle_slot)
- while to_pull > 0 do
- drawers.pushItem("south", drawer_slot, to_pull, turtle_slot)
- to_pull = number - turtle.getItemCount(turtle_slot)
- sleep(0.1)
- end
- end
- drawer_slots = tableHelper()
- -- Function to get slots
- function getSlot(item)
- while true do
- slot = drawer_slots[item]
- if slot then
- return slot
- end
- drawer_slots = tableHelper()
- sleep(0.1)
- end
- end
- -- Main loop
- while true do
- if rs.getAnalogOutput("top") < 15 then
- local total = 0
- -- Switch off pull before counting
- rs.setBundledOutput("left", colors.red)
- -- Tabulate items in inventory
- screen.setText("screen", "Counting items!", 0xffffff)
- for i = 1, 16 do
- item = turtle.getItemDetail(i)
- if item then
- -- inventory[item.name] += item.count
- total = total + item.count
- end
- end
- -- If inventory is empty, refill
- if total == 0 then
- local drawer_slot = 0
- -- One nether star
- screen.setText("screen", "Refilling star!", 0xFF0000)
- drawer_slot = getSlot("minecraft:nether_star")
- drawers.pushItem("south", drawer_slot, 1, 1)
- -- Forty wheat
- screen.setText("screen", "Refilling wheat!", 0xFF0000)
- drawer_slot = getSlot("minecraft:wheat")
- pullHelper(2, drawer_slot, 40)
- -- Four hundred soul sand
- screen.setText("screen", "Refilling soul sand!", 0xFF0000)
- drawer_slot = getSlot("minecraft:soul_sand")
- for i = 3, 8 do
- pullHelper(i, drawer_slot, 60)
- end
- -- And a partridge in a pear tree
- pullHelper(9, drawer_slot, 40)
- end
- -- Reenable pull
- screen.setText("screen", "Active!", 0xffffff)
- rs.setBundledOutput("left", colors.red + colors.green)
- else
- rs.setBundledOutput("left", colors.red)
- screen.setText("screen", "Nether stars full!", 0xffffff)
- end
- -- Yield
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment