refuel with lava program

This commit is contained in:
kepler155c
2018-11-08 12:43:00 -05:00
parent a0dd3a7b6d
commit 0893164868

56
farms/lavaRefuel.lua Normal file
View File

@@ -0,0 +1,56 @@
_G.requireInjector(_ENV)
local Point = require('point')
local device = _G.device
local turtle = _G.turtle
local MAX_FUEL = turtle.getFuelLimit()
local scanner = device['plethora:scanner'] or
turtle.equip('right', 'plethora:module:2') and device['plethora:scanner'] or
error('Plethora scanner required')
if not turtle.select('minecraft:bucket') then
error('bucket required')
end
local s, m = turtle.run(function()
local facing = scanner.getBlockMeta(0, 0, 0).state.facing
turtle.setPoint({ x = 0, y = 0, z = 0, heading = Point.facings[facing].heading })
local blocks = scanner.scan()
local first, last = blocks[#blocks].y, blocks[1].y
for y = first, last, -1 do
if turtle.getFuelLevel() >= (MAX_FUEL - 1000) then
print('I am full')
break
end
local t = { }
for _,v in pairs(blocks) do
if v.y == y then
if (v.name == 'minecraft:lava' and v.metadata == 0) or
(v.name == 'minecraft:flowing_lava' and v.metadata == 0) then
table.insert(t, v)
end
end
end
print(y .. ': ' .. #t)
Point.eachClosest(turtle.point, t, function(b)
if turtle.getFuelLevel() >= (MAX_FUEL - 1000) then
return true
end
turtle.placeDownAt(b)
turtle.refuel()
print(turtle.getFuelLevel())
end)
end
end)
turtle.gotoY(0)
turtle._goto({ x = 0, y = 0, z = 0 })
if not s and m then
error(m)
end