Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Turn it off, just in case
- redstone.setOutput("right", false)
- -- Assumption: the slots are fixed
- cobble = {name = "minecraft:cobblestone", slot = 9, target = 3, out = 10}
- netherrack = {name = "minecraft:netherrack" , slot = 7, target = 2, out = 8}
- endstone = {name = "minecraft:end_stone" , slot = 3, target = 4, out = 4}
- -- gravel = {name = "minecraft:gravel" , slot = 10, target = 8, out = 11}
- -- sand = {name = "minecraft:sand" , slot = 11, target = 2, out = 6}
- -- Bind peripherals
- local drawers = peripheral.wrap("storagedrawers:controllerslave_0")
- local builder = peripheral.wrap("minecraft:builder_te_0")
- -- Add names for easy reference
- drawers.name = "storagedrawers:controllerslave_0"
- builder.name = "minecraft:builder_te_0"
- -- Calculate total number of items
- local target_total = 0
- for k, item in pairs({cobble, gravel, netherrack, sand, endstone}) do
- target_total = target_total + item.target
- end
- -- Various variables for mainloop
- local items_short = 0
- local items_moved = 0
- local place_phase = false
- local item_limit = 31 * 64
- function builderItemCount(name)
- -- Totals up number of items in builder
- local builder_items = 0
- for k, item in pairs(builder.list()) do
- builder_items = builder_items + item.count
- end
- return builder_items
- end
- function errorIfSlotLessThan(slot, value)
- if drawers.getItem(slot).getMetadata().count < value then
- error()
- end
- end
- -- Main loop
- while true do
- -- Sleep to yield
- sleep(1)
- -- If placing, then do not top up
- -- Placing phase remains on until the builder is empty
- if place_phase then
- -- Check if the builder is empty
- if builderItemCount(builder.name) == 0 then
- place_phase = false
- end
- else
- -- Build list of items to move
- for k, item in pairs({netherrack, endstone}) do
- -- Only move if there's more than the required value
- local has_item = pcall(errorIfSlotLessThan, item.slot, item.target + 10)
- -- Only move if there's room
- local has_room = not pcall(errorIfSlotLessThan, item.out, item_limit)
- -- Reset counter
- items_moved = 0
- -- Do the actual move
- if has_item and has_room then
- -- Move items to the builder, record how many were moved
- items_moved = drawers.pushItems(builder.name, item.slot, item.target)
- end
- -- Find out how many items were short
- items_short = items_short + item.target - items_moved
- end
- -- Top up with cobblestone
- drawers.pushItems(builder.name, cobble.slot, cobble.target + items_short)
- -- Reset
- items_short = 0
- items_moved = 0
- -- Total up items in builder
- builder_items = 0
- for k, item in pairs(builder.list()) do
- builder_items = builder_items + item.count
- end
- -- Switch to placement phase if target reached
- if builderItemCount(builder.name) >= target_total then
- place_phase = true
- end
- end
- -- Set redstone controlling builder
- redstone.setOutput("right", place_phase)
- end
Add Comment
Please, Sign In to add comment