1
0
mirror of https://github.com/kepler155c/opus synced 2024-12-28 17:40:26 +00:00
opus/sys/etc/scripts/obsidian

101 lines
2.1 KiB
Plaintext
Raw Normal View History

2017-04-20 11:33:36 +00:00
require = requireInjector(getfenv(1))
local Point = require('point')
2017-04-22 04:51:27 +00:00
local checkedNodes, nodes
2017-04-20 11:33:36 +00:00
local function addNode(node)
for i = 0, 3 do
local hi = turtle.getHeadingInfo(i)
local testNode = { x = node.x + hi.xd, z = node.z + hi.zd }
2017-04-22 04:51:27 +00:00
local key = table.concat({ testNode.x, testNode.z }, ':')
2017-04-20 11:33:36 +00:00
if not checkedNodes[key] then
nodes[key] = testNode
end
end
end
local function findObsidian()
2017-04-22 04:51:27 +00:00
repeat
2017-04-20 11:33:36 +00:00
local node = { x = turtle.point.x, z = turtle.point.z }
local key = table.concat({ node.x, node.z }, ':')
checkedNodes[key] = true
nodes[key] = nil
2017-04-22 04:51:27 +00:00
local _,b = turtle.inspectDown()
if b and (b.name == 'minecraft:lava' or b.name == 'minecraft:flowing_lava') then
if turtle.selectSlot('minecraft:water_bucket') then
2017-05-14 05:03:55 +00:00
while true do
if turtle.up() then
break
end
2017-05-14 04:53:59 +00:00
print('stuck')
end
2017-04-22 04:51:27 +00:00
turtle.placeDown()
os.sleep(2)
turtle.placeDown()
turtle.down()
2017-05-14 04:53:59 +00:00
turtle.select(1)
2017-04-22 04:51:27 +00:00
_, b = turtle.inspectDown()
end
end
2017-05-14 04:53:59 +00:00
if turtle.getCount(16) > 0 then
print('Inventory full')
print('Enter to continue...')
read()
end
2017-04-20 11:33:36 +00:00
if b and b.name == 'minecraft:obsidian' then
turtle.digDown()
addNode(node)
2017-04-22 04:51:27 +00:00
else
turtle.digDown()
2017-04-20 11:33:36 +00:00
end
print(string.format('%d nodes remaining', Util.size(nodes)))
if Util.size(nodes) == 0 then
break
end
local node = Point.closest(turtle.point, nodes)
if not turtle.gotoPoint(node) then
break
end
2017-04-22 04:51:27 +00:00
until turtle.abort
2017-04-20 11:33:36 +00:00
end
turtle.reset()
turtle.setPolicy(turtle.policies.digOnly)
2017-04-22 04:51:27 +00:00
local s, m = turtle.run(function()
repeat
checkedNodes = { }
nodes = { }
local _,b = turtle.inspectDown()
if not b or b.name ~= 'minecraft:obsidian' then
break
end
findObsidian()
if not turtle.selectSlot('minecraft:water_bucket') then
break
end
turtle.goto(0, 0)
turtle.placeDown()
os.sleep(2)
turtle.placeDown()
turtle.down()
2017-05-14 04:53:59 +00:00
turtle.select(1)
2017-04-22 04:51:27 +00:00
until turtle.abort
end)
turtle.goto(0, 0, 0, 0)
turtle.reset()
2017-04-20 11:33:36 +00:00
if not s and m then
error(m)
end