This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| reactorFuels = { | |
| {id=6, name='Oak Sapling'}, | |
| {id=6, dmg=2, name='Birch Sapling'}, | |
| {id=6, dmg=3, name='Junglewood Sapling'}, | |
| {id=295, name='Seeds'}, | |
| {id=351, name='Ink Sac'}, | |
| {id=351, dmg=3, name='Cocoa Beans'}, | |
| {id=361, name='Pumpkin Seeds'}, | |
| {id=362, name='Melon Seeds'}, | |
| {id=372, name='Nether Wart'}, | |
| {id=391, name='Carrot'}, | |
| {id=392, name='Potato'}, | |
| {id=3124, name='Rubber Sapling'}, | |
| {id=3256, dmg=3, name='Sakura Sapling'}, | |
| {id=12659, name='Barley Seeds'}, | |
| } | |
| function bestFuels(ae) | |
| local fuels = {} | |
| for i, fuel in pairs(reactorFuels) do | |
| if fuel.dmg == nil then fuel.dmg = 0 end | |
| fuel.count = ae.countOfItemType(fuel.id, fuel.dmg) | |
| table.insert(fuels, fuel) | |
| end | |
| table.sort(fuels, function(a,b) return a.count > b.count end) | |
| return fuels | |
| end | |
| function clear() | |
| for i = 1,16 do | |
| if turtle.getItemCount(i) > 0 then | |
| ae.insertItem(i, 64, 'up') | |
| end | |
| end | |
| end | |
| function refuel() | |
| if turtle.getFuelLevel() < 1000 then | |
| ae.extractItem({id=263, qty=64}, 'up') | |
| turtle.refuel() | |
| end | |
| end | |
| function needRestock() | |
| for i = 1,9 do | |
| if turtle.getItemCount(i) == 0 then | |
| return true | |
| end | |
| end | |
| return false | |
| end | |
| function restock(fuels) | |
| local pos = at | |
| home() | |
| for i = 1,9 do | |
| local fuel = fuels[i] | |
| fuel.qty = turtle.getItemSpace(i) | |
| if fuel.qty > 0 then | |
| ae.extractItem(fuel, 'up') | |
| end | |
| end | |
| goto(pos) | |
| end | |
| function fill(r, fuels) | |
| local stacks = r.br.getAllStacks() | |
| for i = 1,9 do | |
| local fuel = fuels[i] | |
| fuel.qty = 64 | |
| if stacks[i] ~= nil then | |
| fuel.qty = fuel.qty - stacks[i].qty | |
| end | |
| if fuel.qty > 0 then | |
| r.br.pullItem('up', i, fuel.qty, i) | |
| end | |
| end | |
| end | |
| function goto(pos) | |
| function go(n) | |
| if n > 0 then | |
| for i=1,n do turtle.forward() end | |
| else | |
| for i=1,-n do turtle.back() end | |
| end | |
| end | |
| if at.r then | |
| go(pos.y-at.y) | |
| at.y = pos.y | |
| if pos.x ~= at.x then | |
| turtle.turnLeft() | |
| at.r = false | |
| go(pos.x-at.x) | |
| at.x = pos.x | |
| end | |
| else | |
| go(pos.x-at.x) | |
| at.x = pos.x | |
| if pos.y ~= at.y then | |
| turtle.turnRight() | |
| at.r = true | |
| go(pos.y-at.y) | |
| at.y = pos.y | |
| end | |
| end | |
| os.sleep(0.1) -- workaround | |
| end | |
| function home() | |
| goto({x=0, y=0}) | |
| if at.r then | |
| turtle.turnLeft() | |
| at.r = false | |
| end | |
| end | |
| function reset(reactors) | |
| for i, r in pairs(reactors) do | |
| goto(r) | |
| for i=1,9 do | |
| r.br.pushItem('up', i, 64, i) | |
| end | |
| home() | |
| clear() | |
| goto(r) | |
| for i=10,18 do | |
| r.br.pushItem('up', i, 64, i-9) | |
| end | |
| home() | |
| clear() | |
| end | |
| end | |
| function main() | |
| if peripheral.getType('bottom') ~= 'me_interface' then | |
| print('ME Interface not found (bottom).') | |
| return | |
| end | |
| ae = peripheral.wrap('bottom') | |
| at = {x=0, y=0, r=false} | |
| clear() | |
| local reactors = {} | |
| for y=0,4 do | |
| if y == 0 or y == 2 or y == 4 then | |
| for x=1,5 do table.insert(reactors, {x=x, y=y*2}) | |
| end | |
| else | |
| for x=5,1,-1 do table.insert(reactors, {x=x, y=y*2}) end | |
| end | |
| end | |
| for i, r in pairs(reactors) do | |
| goto(r) | |
| r.br = peripheral.wrap('bottom') | |
| end | |
| home() | |
| while true do | |
| print(os.time()) | |
| local fuels = bestFuels(ae) | |
| for i = 1,9 do | |
| print(i, ' ', fuels[i].name, ' ', fuels[i].count) | |
| end | |
| refuel() | |
| for i, r in pairs(reactors) do | |
| if needRestock() then | |
| restock(fuels) | |
| end | |
| goto(r) | |
| fill(r, fuels) | |
| end | |
| home() | |
| clear() | |
| os.sleep(60) | |
| end | |
| end | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment