refined storage bug, obsidian script

This commit is contained in:
kepler155c@gmail.com
2017-04-20 07:33:36 -04:00
parent 17f4f8d9c1
commit c57ff1541b
4 changed files with 99 additions and 34 deletions

View File

@@ -1,5 +1,4 @@
require = requireInjector(getfenv(1))
local Event = require('event')
local UI = require('ui')
local Socket = require('socket')
local Terminal = require('terminal')
@@ -20,7 +19,6 @@ local options = {
local SCRIPTS_PATH = '/apps/scripts'
local ct = term.current()
local nullTerm = Terminal.getNullTerm(term.current())
local turtles = { }
local policies = {
@@ -84,8 +82,9 @@ local page = UI.Page {
x = 1, y = 8, rey = -2,
scripts = UI.Grid {
tabTitle = 'Run',
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
columns = {
{ heading = '', key = 'label' },
{ heading = '', key = 'label' },
},
disableHeader = true,
sortColumn = 'label',
@@ -93,6 +92,7 @@ local page = UI.Page {
},
turtles = UI.Grid {
tabTitle = 'Sel',
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
columns = {
{ heading = 'label', key = 'label' },
{ heading = 'Dist', key = 'distance' },
@@ -104,18 +104,20 @@ local page = UI.Page {
autospace = true,
},
inventory = UI.Grid {
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
tabTitle = 'Inv',
columns = {
{ heading = '', key = 'qty', width = 2 },
{ heading = 'Inventory', key = 'id', width = 13 },
{ heading = '', key = 'qty', width = 2 },
{ heading = 'Inventory', key = 'id', width = UI.term.width - 5 },
},
disableHeader = true,
sortColumn = 'index',
},
policy = UI.Grid {
tabTitle = 'Mod',
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
columns = {
{ heading = 'label', key = 'label' },
{ heading = 'label', key = 'label' },
},
values = policies,
disableHeader = true,
@@ -187,7 +189,6 @@ function page.tabs.inventory:draw()
end
if v.id then
local item = itemInfoDB:get({ v.id, v.dmg })
debug(v)
if item then
v.id = item.displayName
else
@@ -273,7 +274,7 @@ end
function page:eventHandler(event)
if event.type == 'quit' then
UI:setPreviousPage()
UI:exitPullEvents()
elseif event.type == 'button_press' then
if event.button.fn then
self:runFunction(event.button.fn, event.button.nowrap)
@@ -323,5 +324,5 @@ UI:setPage(page)
page.tabs:activateTab(page.tabs[options.tab.value])
Event.pullEvents(updateThread)
UI:pullEvents(updateThread)
UI.term:reset()

58
apps/scripts/obsidian Normal file
View File

@@ -0,0 +1,58 @@
require = requireInjector(getfenv(1))
local Point = require('point')
local checkedNodes = { }
local nodes = { }
local function addNode(node)
local key = table.concat({ node.x, node.z }, ':')
for i = 0, 3 do
local hi = turtle.getHeadingInfo(i)
local testNode = { x = node.x + hi.xd, z = node.z + hi.zd }
key = table.concat({ testNode.x, testNode.z }, ':')
if not checkedNodes[key] then
nodes[key] = testNode
end
end
end
local function findObsidian()
while true do
local _,b = turtle.inspectDown()
local node = { x = turtle.point.x, z = turtle.point.z }
local key = table.concat({ node.x, node.z }, ':')
checkedNodes[key] = true
nodes[key] = nil
if b and b.name == 'minecraft:obsidian' then
turtle.digDown()
addNode(node)
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
end
end
turtle.reset()
turtle.setPolicy(turtle.policies.digOnly)
local s, m = turtle.run(function() findObsidian() end)
if not s and m then
error(m)
end
turtle.goto(0, 0, 0, 0)
turtle.reset()