Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Initalise
- rs.setOutput("left", false)
- drawers = peripheral.wrap("front")
- -- Function to help pull to full
- function pullHelper(turtle_slot, drawer_slot, number)
- while turtle.getItemCount(turtle_slot) < number do
- drawers.pushItem("south", drawer_slot, number, turtle_slot)
- end
- end
- -- Make distal name:slot_ID table
- drawer_slots = {}
- for ID, slot in pairs(drawers.getAllStacks()) do
- drawer_slots[slot.all().id] = ID
- print(ID, " ", slot.all().id)
- end
- while true do
- if rs.getAnalogOutput("top") < 15 then
- local total = 0
- -- local inventory = {
- -- "minecraft:wheat" = 0,
- -- "minecraft:soul_sand" = 0,
- -- "minecraft:nether_star" = 0
- -- }
- -- Switch off redstone before counting
- rs.setOutput("left", false)
- -- Tabulate items in inventory
- 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
- drawer_slot = drawer_slots["minecraft:nether_star"]
- drawers.pushItem("south", drawer_slot, 1, 1)
- -- Forty wheat
- drawer_slot = drawer_slots["minecraft:wheat"]
- pullHelper(2, drawer_slot, 40)
- -- Four hundred soul sand
- drawer_slot = drawer_slots["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
- end
- -- Reenable redstone
- rs.setOutput("left", true)
- -- Yield
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment