This commit is contained in:
kepler155c
2017-10-08 17:45:37 -04:00
parent bba7841c43
commit ed2d6eeef1
23 changed files with 222 additions and 207 deletions

View File

@@ -64,7 +64,7 @@ function blockDB:lookup(id, dmg)
if not id then if not id then
return return
end end
return self.data[id .. ':' .. dmg] return self.data[id .. ':' .. dmg]
end end
@@ -136,12 +136,12 @@ function placementDB:addSubsForBlockType(id, dmg, bt)
sub.extra) sub.extra)
end end
end end
function placementDB:add(id, dmg, sid, sdmg, direction, extra) function placementDB:add(id, dmg, sid, sdmg, direction, extra)
if direction and #direction == 0 then if direction and #direction == 0 then
direction = nil direction = nil
end end
local entry = { local entry = {
oid = id, -- numeric ID oid = id, -- numeric ID
odmg = dmg, -- dmg with placement info odmg = dmg, -- dmg with placement info
@@ -176,9 +176,9 @@ function blockTypeDB:addTemp(blockType, subs)
end end
self.dirty = true self.dirty = true
end end
function blockTypeDB:load() function blockTypeDB:load()
blockTypeDB:addTemp('stairs', { blockTypeDB:addTemp('stairs', {
{ 0, nil, 0, 'east-up' }, { 0, nil, 0, 'east-up' },
{ 1, nil, 0, 'west-up' }, { 1, nil, 0, 'west-up' },
@@ -575,7 +575,8 @@ function Blocks:init(args)
placementDB:load2(blockDB, blockTypeDB) placementDB:load2(blockDB, blockTypeDB)
end end
-- for an ID / dmg (with placement info) - return the correct block (without the placment info embedded in the dmg) -- for an ID / dmg (with placement info)
-- return the correct block (without the placment info embedded in the dmg)
function Blocks:getPlaceableBlock(id, dmg) function Blocks:getPlaceableBlock(id, dmg)
local p = placementDB:get({id, dmg}) local p = placementDB:get({id, dmg})

View File

@@ -13,7 +13,7 @@ local convertNames = {
displayName = 'display_name', displayName = 'display_name',
maxDamage = 'max_dmg', maxDamage = 'max_dmg',
} }
local keys = { local keys = {
'damage', 'damage',
'displayName', 'displayName',
'maxCount', 'maxCount',
@@ -31,7 +31,7 @@ local function safeString(text)
local newText = {} local newText = {}
for i = 4, #text do for i = 4, #text do
local val = text:byte(i) val = text:byte(i)
newText[i - 3] = (val > 31 and val < 127) and val or 63 newText[i - 3] = (val > 31 and val < 127) and val or 63
end end
return string.char(unpack(newText)) return string.char(unpack(newText))
@@ -65,11 +65,11 @@ function ChestAdapter:init(args)
Util.merge(self, chest) Util.merge(self, chest)
end end
end end
function ChestAdapter:isValid() function ChestAdapter:isValid()
return not not self.getAllStacks return not not self.getAllStacks
end end
function ChestAdapter:refresh(throttle) function ChestAdapter:refresh(throttle)
return self:listItems(throttle) return self:listItems(throttle)
end end
@@ -109,12 +109,11 @@ function ChestAdapter:getItemInfo(item)
local key = table.concat({ item.name, item.damage, item.nbtHash }, ':') local key = table.concat({ item.name, item.damage, item.nbtHash }, ':')
return self.cache[key] return self.cache[key]
end end
function ChestAdapter:craft(id, dmg, qty) function ChestAdapter:craft()
return false
end end
function ChestAdapter:craftItems(items) function ChestAdapter:craftItems()
end end
function ChestAdapter:provide(item, qty, slot, direction) function ChestAdapter:provide(item, qty, slot, direction)
@@ -144,7 +143,7 @@ end
function ChestAdapter:insert(slot, qty) function ChestAdapter:insert(slot, qty)
local s, m = pcall(function() self.pullItem(self.direction, slot, qty) end) local s, m = pcall(function() self.pullItem(self.direction, slot, qty) end)
if not s and m then if not s and m then
sleep(1) os.sleep(1)
pcall(function() self.pullItem(self.direction, slot, qty) end) pcall(function() self.pullItem(self.direction, slot, qty) end)
end end
end end

View File

@@ -5,7 +5,7 @@ local Peripheral = require('peripheral')
local ChestAdapter = class() local ChestAdapter = class()
local keys = Util.transpose({ local keys = Util.transpose({
'damage', 'damage',
'displayName', 'displayName',
'maxCount', 'maxCount',
@@ -22,7 +22,7 @@ function ChestAdapter:init(args)
} }
Util.merge(self, defaults) Util.merge(self, defaults)
Util.merge(self, args) Util.merge(self, args)
local chest = Peripheral.getBySide(self.wrapSide) local chest = Peripheral.getBySide(self.wrapSide)
if not chest then if not chest then
chest = Peripheral.getByMethod('list') chest = Peripheral.getByMethod('list')
@@ -106,10 +106,10 @@ function ChestAdapter:getItemInfo(item)
return self.cache[key] return self.cache[key]
end end
function ChestAdapter:craft(name, damage, qty) function ChestAdapter:craft()
end end
function ChestAdapter:craftItems(items) function ChestAdapter:craftItems()
end end
function ChestAdapter:provide(item, qty, slot, direction) function ChestAdapter:provide(item, qty, slot, direction)

View File

@@ -3,7 +3,8 @@ local itemDB = require('itemDB')
local Peripheral = require('peripheral') local Peripheral = require('peripheral')
local Util = require('util') local Util = require('util')
local MEAdapter = class() local os = _G.os
local peripheral = _G.peripheral
local convertNames = { local convertNames = {
name = 'id', name = 'id',
@@ -13,7 +14,7 @@ local convertNames = {
displayName = 'display_name', displayName = 'display_name',
maxDamage = 'max_dmg', maxDamage = 'max_dmg',
} }
local keys = { local keys = {
'damage', 'damage',
'displayName', 'displayName',
'maxCount', 'maxCount',
@@ -31,7 +32,7 @@ local function safeString(text)
local newText = {} local newText = {}
for i = 4, #text do for i = 4, #text do
local val = text:byte(i) val = text:byte(i)
newText[i - 3] = (val > 31 and val < 127) and val or 63 newText[i - 3] = (val > 31 and val < 127) and val or 63
end end
return string.char(unpack(newText)) return string.char(unpack(newText))
@@ -48,6 +49,8 @@ local function convertItem(item)
item.displayName = safeString(item.displayName) item.displayName = safeString(item.displayName)
end end
local MEAdapter = class()
function MEAdapter:init(args) function MEAdapter:init(args)
local defaults = { local defaults = {
items = { }, items = { },
@@ -72,7 +75,7 @@ function MEAdapter:init(args)
end end
end end
end end
function MEAdapter:isValid() function MEAdapter:isValid()
return self.getAvailableItems and self.getAvailableItems() return self.getAvailableItems and self.getAvailableItems()
end end
@@ -102,9 +105,9 @@ function MEAdapter:listItems()
self:refresh() self:refresh()
return self.items return self.items
end end
function MEAdapter:getItemInfo(item) function MEAdapter:getItemInfo(item)
for key,i in pairs(self.items) do for _,i in pairs(self.items) do
if item.name == i.name and item.damage == i.damage and item.nbtHash == i.nbtHash then if item.name == i.name and item.damage == i.damage and item.nbtHash == i.nbtHash then
return i return i
end end
@@ -123,7 +126,7 @@ function MEAdapter:isCPUAvailable()
end end
end end
return available return available
end end
function MEAdapter:craft(item, count) function MEAdapter:craft(item, count)
@@ -133,7 +136,7 @@ function MEAdapter:craft(item, count)
self:refresh() self:refresh()
local item = self:getItemInfo(item) item = self:getItemInfo(item)
if item and item.is_craftable then if item and item.is_craftable then
local cpus = self.getCraftingCPUs() or { } local cpus = self.getCraftingCPUs() or { }
@@ -186,8 +189,8 @@ end
function MEAdapter:isCrafting(item) function MEAdapter:isCrafting(item)
for _,v in pairs(self:getJobList()) do for _,v in pairs(self:getJobList()) do
if v.name == item.name and if v.name == item.name and
v.damage == item.damage and v.damage == item.damage and
v.nbtHash == item.nbtHash then v.nbtHash == item.nbtHash then
return true return true
end end
@@ -220,7 +223,7 @@ function MEAdapter:provide(item, count, slot, direction)
return pcall(function() return pcall(function()
while count > 0 do while count > 0 do
local qty = math.min(count, 64) local qty = math.min(count, 64)
local s, m = self.exportItem({ local s = self.exportItem({
id = item.name, id = item.name,
dmg = item.damage dmg = item.damage
}, direction or self.direction, qty, slot) }, direction or self.direction, qty, slot)
@@ -232,18 +235,14 @@ function MEAdapter:provide(item, count, slot, direction)
end end
end) end)
end end
function MEAdapter:insert(slot, count) function MEAdapter:insert(slot, count)
local s, m = pcall(function() self.pullItem(self.direction, slot, count) end) local s, m = pcall(function() self.pullItem(self.direction, slot, count) end)
if not s and m then if not s and m then
print('MEAdapter:pullItem') os.sleep(1)
print(m)
sleep(1)
s, m = pcall(function() self.pullItem(self.direction, slot, count) end) s, m = pcall(function() self.pullItem(self.direction, slot, count) end)
if not s and m then if not s and m then
print('MEAdapter:pullItem') error(m)
print(m)
read()
end end
end end
end end

View File

@@ -12,7 +12,7 @@ function nameDB:load()
end end
for strId, block in pairs(blocks) do for strId, block in pairs(blocks) do
local strId = 'minecraft:' .. strId strId = 'minecraft:' .. strId
if type(block.name) == 'string' then if type(block.name) == 'string' then
self.data[strId .. ':0'] = block.name self.data[strId .. ':0'] = block.name
else else

View File

@@ -5,7 +5,7 @@ local itemDB = require('itemDB')
local RefinedAdapter = class() local RefinedAdapter = class()
local keys = { local keys = {
'damage', 'damage',
'displayName', 'displayName',
'maxCount', 'maxCount',
@@ -109,8 +109,8 @@ end
function RefinedAdapter:isCrafting(item) function RefinedAdapter:isCrafting(item)
for _,task in pairs(self.getCraftingTasks()) do for _,task in pairs(self.getCraftingTasks()) do
local output = task.getPattern().outputs[1] local output = task.getPattern().outputs[1]
if output.name == item.name and if output.name == item.name and
output.damage == item.damage and output.damage == item.damage and
output.nbtHash == item.nbtHash then output.nbtHash == item.nbtHash then
return true return true
end end
@@ -125,18 +125,18 @@ function RefinedAdapter:craft(item, qty)
end end
end end
function RefinedAdapter:craftItems(items) function RefinedAdapter:craftItems()
return false return false
end end
function RefinedAdapter:provide(item, qty, slot) function RefinedAdapter:provide()
end end
function RefinedAdapter:extract(slot, qty) function RefinedAdapter:extract()
-- self.pushItems(self.direction, slot, qty) -- self.pushItems(self.direction, slot, qty)
end end
function RefinedAdapter:insert(slot, qty) function RefinedAdapter:insert()
-- self.pullItems(self.direction, slot, qty) -- self.pullItems(self.direction, slot, qty)
end end

View File

@@ -4,6 +4,11 @@ local DEFLATE = require('deflatelua')
local UI = require('ui') local UI = require('ui')
local Point = require('point') local Point = require('point')
local bit = _G.bit
local fs = _G.fs
local term = _G.term
local turtle = _G.turtle
--[[ --[[
Loading and manipulating a schematic Loading and manipulating a schematic
--]] --]]
@@ -24,7 +29,7 @@ end
--[[ --[[
Credit to Orwell for the schematic file reader code Credit to Orwell for the schematic file reader code
http://www.computercraft.info/forums2/index.php?/topic/1949-turtle-schematic-file-builder/ http://www.computercraft.info/forums2/index.php?/topic/1949-turtle-schematic-file-builder/
Some parts of the file reader code was modified from the original Some parts of the file reader code was modified from the original
--]] --]]
@@ -52,7 +57,7 @@ function Schematic:readname(h)
local c = h:readbyte(h) local c = h:readbyte(h)
if c == nil then if c == nil then
return return
end end
str = str .. string.char(c) str = str .. string.char(c)
end end
return str return str
@@ -218,11 +223,11 @@ function DiskFile:close()
end end
local MemoryFile = class() local MemoryFile = class()
function MemoryFile:init(args) function MemoryFile:init()
self.s = { } self.s = { }
self.i = 1 self.i = 1
end end
function MemoryFile:open(filename) function MemoryFile:open()
self.i = 1 self.i = 1
end end
function MemoryFile:close() end function MemoryFile:close() end
@@ -247,7 +252,7 @@ function Schematic:decompress(ifname, spinner)
local mh = MemoryFile() local mh = MemoryFile()
DEFLATE.gunzip({ DEFLATE.gunzip({
input=function(...) spinner:spin() return ifh.read() end, input=function() spinner:spin() return ifh.read() end,
output=function(b) mh:write(b) end, output=function(b) mh:write(b) end,
disable_crc=true disable_crc=true
}) })
@@ -310,7 +315,7 @@ end
function Schematic:load(filename) function Schematic:load(filename)
local cursorX, cursorY = term.getCursorPos() local _, cursorY = term.getCursorPos()
local spinner = UI.Spinner({ local spinner = UI.Spinner({
x = UI.term.width, x = UI.term.width,
y = cursorY - 1 y = cursorY - 1
@@ -757,7 +762,7 @@ function Schematic:determineBlockPlacement(y)
-- otherwise, the turtle must place the block from the same plane -- otherwise, the turtle must place the block from the same plane
-- against another block -- against another block
-- if no block to place against (from side) then the turtle must place from -- if no block to place against (from side) then the turtle must place from
-- the other side -- the other side
-- --
-- Stair bug in 1.7 - placing a stair southward doesn't respect the turtle's direction -- Stair bug in 1.7 - placing a stair southward doesn't respect the turtle's direction
-- all other directions are fine -- all other directions are fine
@@ -843,8 +848,6 @@ end
-- set the order for block dependencies -- set the order for block dependencies
function Schematic:setPlacementOrder(spinner, placementChains) function Schematic:setPlacementOrder(spinner, placementChains)
local cursorX, cursorY = term.getCursorPos()
-- optimize for overlapping check -- optimize for overlapping check
for _,chain in pairs(placementChains) do for _,chain in pairs(placementChains) do
for index,_ in pairs(chain.keys) do for index,_ in pairs(chain.keys) do
@@ -917,9 +920,9 @@ function Schematic:setPlacementOrder(spinner, placementChains)
]]-- ]]--
local masterChain = table.remove(chains) local masterChain = table.remove(chains)
--[[ it's something like this: --[[ it's something like this:
A chain B chain result A chain B chain result
1 1 1 1
2 -------- 2 2 2 -------- 2 2
@@ -1040,12 +1043,10 @@ v.info = 'Unplaceable'
end end
term.clearLine() term.clearLine()
return t
end end
function Schematic:optimizeRoute(spinner, y) function Schematic:optimizeRoute(spinner, y)
local function getNearestNeighbor(p, pt, maxDistance) local function getNearestNeighbor(p, pt, maxDistance)
local key, block, heading local key, block, heading
local moves = maxDistance local moves = maxDistance
@@ -1146,7 +1147,6 @@ function Schematic:optimizeRoute(spinner, y)
local maxDistance = self.width*self.length local maxDistance = self.width*self.length
local plane, doors = extractPlane(y) local plane, doors = extractPlane(y)
spinner:spin(percent)
pt.index = 0 pt.index = 0
for i = 1, #plane do for i = 1, #plane do
local b = getNearestNeighbor(plane, pt, maxDistance) local b = getNearestNeighbor(plane, pt, maxDistance)

View File

@@ -11,14 +11,14 @@ function TableDB:init(args)
Util.merge(defaults, args) Util.merge(defaults, args)
Util.merge(self, defaults) Util.merge(self, defaults)
end end
function TableDB:load() function TableDB:load()
local t = Util.readTable(self.fileName) local t = Util.readTable(self.fileName)
if t then if t then
self.data = t.data or t self.data = t.data or t
end end
end end
function TableDB:add(key, entry) function TableDB:add(key, entry)
if type(key) == 'table' then if type(key) == 'table' then
key = table.concat(key, ':') key = table.concat(key, ':')
@@ -26,19 +26,19 @@ function TableDB:add(key, entry)
self.data[key] = entry self.data[key] = entry
self.dirty = true self.dirty = true
end end
function TableDB:get(key) function TableDB:get(key)
if type(key) == 'table' then if type(key) == 'table' then
key = table.concat(key, ':') key = table.concat(key, ':')
end end
return self.data[key] return self.data[key]
end end
function TableDB:remove(key) function TableDB:remove(key)
self.data[key] = nil self.data[key] = nil
self.dirty = true self.dirty = true
end end
function TableDB:flush() function TableDB:flush()
if self.dirty then if self.dirty then
Util.writeTable(self.fileName, self.data) Util.writeTable(self.fileName, self.data)

View File

@@ -1,25 +1,28 @@
requireInjector(getfenv(1)) _G.requireInjector()
local Ansi = require('ansi') local Ansi = require('ansi')
local Config = require('config')
local SHA1 = require('sha1') local SHA1 = require('sha1')
local UI = require('ui') local UI = require('ui')
local Util = require('util') local Util = require('util')
-- scrap this entire file. don't muck with standard apis local fs = _G.fs
local http = _G.http
local multishell = _ENV.multishell
local os = _G.os
local shell = _ENV.shell
local REGISTRY_DIR = 'usr/.registry' local REGISTRY_DIR = 'usr/.registry'
-- FIX SOMEDAY -- FIX SOMEDAY
function os.registerApp(app, key) local function registerApp(app, key)
app.key = SHA1.sha1(key) app.key = SHA1.sha1(key)
Util.writeTable(fs.combine(REGISTRY_DIR, app.key), app) Util.writeTable(fs.combine(REGISTRY_DIR, app.key), app)
os.queueEvent('os_register_app') os.queueEvent('os_register_app')
end end
function os.unregisterApp(key) local function unregisterApp(key)
local filename = fs.combine(REGISTRY_DIR, SHA1.sha1(key)) local filename = fs.combine(REGISTRY_DIR, SHA1.sha1(key))
if fs.exists(filename) then if fs.exists(filename) then
@@ -29,7 +32,7 @@ function os.unregisterApp(key)
end end
local sandboxEnv = Util.shallowCopy(getfenv(1)) local sandboxEnv = Util.shallowCopy(_ENV)
setmetatable(sandboxEnv, { __index = _G }) setmetatable(sandboxEnv, { __index = _G })
multishell.setTitle(multishell.getCurrent(), 'App Store') multishell.setTitle(multishell.getCurrent(), 'App Store')
@@ -243,7 +246,7 @@ function appPage:eventHandler(event)
elseif event.type == 'uninstall' then elseif event.type == 'uninstall' then
if self.app.runOnly then if self.app.runOnly then
s,m = runApp(self.app, false, 'uninstall') runApp(self.app, false, 'uninstall')
else else
fs.delete(fs.combine(APP_DIR, self.app.name)) fs.delete(fs.combine(APP_DIR, self.app.name))
self.notification:success("Uninstalled " .. self.app.name, 3) self.notification:success("Uninstalled " .. self.app.name, 3)
@@ -251,7 +254,7 @@ function appPage:eventHandler(event)
self.menuBar.removeButton:disable('Remove') self.menuBar.removeButton:disable('Remove')
self.menuBar:draw() self.menuBar:draw()
os.unregisterApp(self.app.creator .. '.' .. self.app.name) unregisterApp(self.app.creator .. '.' .. self.app.name)
end end
elseif event.type == 'install' then elseif event.type == 'install' then
@@ -275,7 +278,7 @@ function appPage:eventHandler(event)
category = 'Games' category = 'Games'
end end
os.registerApp({ registerApp({
run = fs.combine(APP_DIR, self.app.name), run = fs.combine(APP_DIR, self.app.name),
title = self.app.title, title = self.app.title,
category = category, category = category,
@@ -314,7 +317,7 @@ local categoryPage = UI.Page {
function categoryPage:setCategory(source, name, index) function categoryPage:setCategory(source, name, index)
self.grid.values = { } self.grid.values = { }
for k,v in pairs(source.storeURLs) do for _,v in pairs(source.storeURLs) do
if index == 0 or index == v.catagory then if index == 0 or index == v.catagory then
table.insert(self.grid.values, v) table.insert(self.grid.values, v)
end end
@@ -339,7 +342,7 @@ function categoryPage:setSource(source)
end end
local buttons = { } local buttons = { }
for k,v in Util.spairs(source.storeCatagoryNames, for k,v in Util.spairs(source.storeCatagoryNames,
function(a, b) return a:lower() < b:lower() end) do function(a, b) return a:lower() < b:lower() end) do
if v ~= 'Operating System' then if v ~= 'Operating System' then

View File

@@ -1,9 +1,12 @@
requireInjector(getfenv(1)) _G.requireInjector()
local Event = require('event') local Event = require('event')
local UI = require('ui') local UI = require('ui')
local Util = require('util') local Util = require('util')
local multishell = _ENV.multishell
local os = _G.os
multishell.setTitle(multishell.getCurrent(), 'Events') multishell.setTitle(multishell.getCurrent(), 'Events')
UI:configure('Events', ...) UI:configure('Events', ...)

View File

@@ -1,4 +1,4 @@
requireInjector(getfenv(1)) _G.requireInjector()
local Ansi = require('ansi') local Ansi = require('ansi')
local Event = require('event') local Event = require('event')
@@ -6,6 +6,7 @@ local UI = require('ui')
local Util = require('util') local Util = require('util')
local colors = _G.colors local colors = _G.colors
local multishell = _ENV.multishell
local peripheral = _G.peripheral local peripheral = _G.peripheral
multishell.setTitle(multishell.getCurrent(), 'Devices') multishell.setTitle(multishell.getCurrent(), 'Devices')

View File

@@ -1,4 +1,4 @@
requireInjector(getfenv(1)) _G.requireInjector()
local Config = require('config') local Config = require('config')
local Event = require('event') local Event = require('event')
@@ -6,6 +6,12 @@ local Socket = require('socket')
local UI = require('ui') local UI = require('ui')
local Util = require('util') local Util = require('util')
local colors = _G.colors
local fs = _G.fs
local multishell = _ENV.multishell
local os = _G.os
local shell = _ENV.shell
local GROUPS_PATH = 'usr/groups' local GROUPS_PATH = 'usr/groups'
local SCRIPTS_PATH = 'usr/etc/scripts' local SCRIPTS_PATH = 'usr/etc/scripts'
@@ -26,7 +32,7 @@ if UI.term.width % 2 ~= 0 then
width = width + 1 width = width + 1
end end
function processVariables(script) local function processVariables(script)
local fn = loadstring('return ' .. config.variables) local fn = loadstring('return ' .. config.variables)
if fn then if fn then
@@ -40,7 +46,7 @@ function processVariables(script)
return script return script
end end
function invokeScript(computer, scriptName) local function invokeScript(computer, scriptName)
local script = Util.readFile(scriptName) local script = Util.readFile(scriptName)
if not script then if not script then
@@ -74,7 +80,7 @@ function invokeScript(computer, scriptName)
socket:close() socket:close()
end end
function runScript(computerOrGroup, scriptName) local function runScript(computerOrGroup, scriptName)
if computerOrGroup.id then if computerOrGroup.id then
invokeScript(computerOrGroup, scriptName) invokeScript(computerOrGroup, scriptName)
else else
@@ -208,14 +214,14 @@ local editorPage = UI.Page({
y = 3, y = 3,
}), }),
right = UI.Button({ right = UI.Button({
text = '>', text = '>',
event = 'right', event = 'right',
x = width - 2, x = width - 2,
y = 2, y = 2,
width = 3, width = 3,
}), }),
left = UI.Button({ left = UI.Button({
text = '<', text = '<',
event = 'left', event = 'left',
x = UI.term.width - width + 1, x = UI.term.width - width + 1,
y = 2, y = 2,
@@ -459,11 +465,6 @@ function mainPage:eventHandler(event)
elseif event.type == 'toggle' then elseif event.type == 'toggle' then
config.showGroups = not config.showGroups config.showGroups = not config.showGroups
local text = 'Computers'
if config.showGroups then
text = 'Groups'
end
-- self.statusBar.toggleButton.text = text
self:draw() self:draw()
Config.update('script', config) Config.update('script', config)

View File

@@ -1,4 +1,4 @@
requireInjector(getfenv(1)) _G.requireInjector()
local Config = require('config') local Config = require('config')
local Event = require('event') local Event = require('event')
@@ -8,6 +8,14 @@ local Terminal = require('terminal')
local UI = require('ui') local UI = require('ui')
local Util = require('util') local Util = require('util')
local colors = _G.colors
local fs = _G.fs
local multishell = _ENV.multishell
local network = _G.network
local os = _G.os
local shell = _ENV.shell
local term = _G.term
multishell.setTitle(multishell.getCurrent(), 'Turtles') multishell.setTitle(multishell.getCurrent(), 'Turtles')
UI.Button.defaults.focusIndicator = ' ' UI.Button.defaults.focusIndicator = ' '
UI:configure('Turtles', ...) UI:configure('Turtles', ...)
@@ -27,15 +35,7 @@ local options = {
local SCRIPTS_PATH = 'usr/etc/scripts' local SCRIPTS_PATH = 'usr/etc/scripts'
local nullTerm = Terminal.getNullTerm(term.current()) local nullTerm = Terminal.getNullTerm(term.current())
local turtles = { }
local socket local socket
local policies = {
{ label = 'none' },
{ label = 'digOnly' },
{ label = 'attackOnly' },
{ label = 'digAttack' },
{ label = 'turtleSafe' },
}
local page = UI.Page { local page = UI.Page {
coords = UI.Window { coords = UI.Window {
@@ -142,7 +142,7 @@ function page:enable(turtle)
end end
function page:runFunction(script, nowrap) function page:runFunction(script, nowrap)
for i = 1, 2 do for _ = 1, 2 do
if not socket then if not socket then
socket = Socket.connect(self.turtle.id, 161) socket = Socket.connect(self.turtle.id, 161)
end end
@@ -186,7 +186,7 @@ function page.coords:draw()
if not t.point.gps then if not t.point.gps then
ind = 'REL' ind = 'REL'
end end
self:print(string.format('%s : %d,%d,%d\n Fuel: %s\n', self:print(string.format('%s : %d,%d,%d\n Fuel: %s\n',
ind, t.point.x, t.point.y, t.point.z, Util.toBytes(t.fuel))) ind, t.point.x, t.point.y, t.point.z, Util.toBytes(t.fuel)))
end end
end end
@@ -210,12 +210,6 @@ function page.tabs.inventory:draw()
v.selected = true v.selected = true
end end
if v.id then if v.id then
-- local item = itemDB:get({ v.id, v.dmg })
-- if item then
-- v.id = item.displayName
-- else
-- v.id = v.id:gsub('.*:(.*)', '%1')
-- end
v.id = itemDB:getName(v) v.id = itemDB:getName(v)
end end
end end
@@ -356,7 +350,7 @@ if not Util.getOptions(options, { ... }, true) then
end end
if options.turtle.value >= 0 then if options.turtle.value >= 0 then
for i = 1, 10 do for _ = 1, 10 do
page.turtle = _G.network[options.turtle.value] page.turtle = _G.network[options.turtle.value]
if page.turtle then if page.turtle then
break break

View File

@@ -1,6 +1,10 @@
requireInjector(getfenv(1)) _G.requireInjector()
Base64 = require('base64') local Base64 = require('base64')
local http = _G.http
local os = _G.os
local shell = _ENV.shell
local args = { ... } local args = { ... }

View File

@@ -1,4 +1,4 @@
requireInjector(getfenv(1)) _G.requireInjector()
local ChestAdapter = require('chestAdapter18') local ChestAdapter = require('chestAdapter18')
local Config = require('config') local Config = require('config')
@@ -12,6 +12,11 @@ local Terminal = require('terminal')
local UI = require('ui') local UI = require('ui')
local Util = require('util') local Util = require('util')
local device = _G.device
local multishell = _ENV.multishell
local peripheral = _G.peripheral
local term = _G.term
multishell.setTitle(multishell.getCurrent(), 'Resource Manager') multishell.setTitle(multishell.getCurrent(), 'Resource Manager')
-- 3 wide monitor (any side of turtle) -- 3 wide monitor (any side of turtle)
@@ -58,6 +63,9 @@ end
local RESOURCE_FILE = 'usr/config/resources.db' local RESOURCE_FILE = 'usr/config/resources.db'
local RECIPES_FILE = 'usr/etc/recipes.db' local RECIPES_FILE = 'usr/etc/recipes.db'
local colors = _G.colors
local turtle = _G.turtle
local craftingPaused = false local craftingPaused = false
local canCraft = not not duckAntenna or turtleChestAdapter:isValid() local canCraft = not not duckAntenna or turtleChestAdapter:isValid()
local recipes = Util.readTable(RECIPES_FILE) or { } local recipes = Util.readTable(RECIPES_FILE) or { }
@@ -97,18 +105,6 @@ local function getItemQuantity(items, item)
return 0 return 0
end end
local function getItemDetails(items, item)
local cItem = getItem(items, item)
if cItem then
return cItem
end
cItem = itemDB:get(itemDB:makeKey(item))
if cItem then
return { count = 0, maxCount = cItem.maxCount }
end
return { count = 0, maxCount = 64 }
end
local function uniqueKey(item) local function uniqueKey(item)
return table.concat({ item.name, item.damage, item.nbtHash }, ':') return table.concat({ item.name, item.damage, item.nbtHash }, ':')
end end
@@ -143,12 +139,12 @@ local function mergeResources(t)
v.lname = v.displayName:lower() v.lname = v.displayName:lower()
end end
end end
local function filterItems(t, filter) local function filterItems(t, filter)
if filter then if filter then
local r = {} local r = {}
filter = filter:lower() filter = filter:lower()
for k,v in pairs(t) do for _,v in pairs(t) do
if string.find(v.lname, filter) then if string.find(v.lname, filter) then
table.insert(r, v) table.insert(r, v)
end end
@@ -160,7 +156,6 @@ end
local function sumItems3(ingredients, items, summedItems, count) local function sumItems3(ingredients, items, summedItems, count)
local canCraft = 0
for _,key in pairs(ingredients) do for _,key in pairs(ingredients) do
local item = splitKey(key) local item = splitKey(key)
local summedItem = summedItems[key] local summedItem = summedItems[key]
@@ -205,7 +200,7 @@ local function addCraftingRequest(item, craftList, count)
local key = uniqueKey(item) local key = uniqueKey(item)
local request = craftList[key] local request = craftList[key]
if not craftList[key] then if not craftList[key] then
request = { name = item.name, damage = item.damage, nbtHash = nbtHash, count = 0 } request = { name = item.name, damage = item.damage, nbtHash = item.nbtHash, count = 0 }
request.displayName = itemDB:getName(request) request.displayName = itemDB:getName(request)
craftList[key] = request craftList[key] = request
end end
@@ -238,7 +233,7 @@ local function craftItem(recipe, items, originalItem, craftList, count)
local summedItems = { } local summedItems = { }
sumItems3(recipe.ingredients, items, summedItems, math.ceil(count / recipe.count)) sumItems3(recipe.ingredients, items, summedItems, math.ceil(count / recipe.count))
for key,ingredient in pairs(summedItems) do for _,ingredient in pairs(summedItems) do
if not ingredient.recipe and ingredient.count < 0 then if not ingredient.recipe and ingredient.count < 0 then
addCraftingRequest(ingredient, craftList, -ingredient.count) addCraftingRequest(ingredient, craftList, -ingredient.count)
end end
@@ -270,7 +265,7 @@ local function craftItems(craftList, allItems)
else else
local count = item.count local count = item.count
while count >= 1 do -- try to request smaller quantities until successful while count >= 1 do -- try to request smaller quantities until successful
local s, m = pcall(function() local s = pcall(function()
item.status = '(no recipe)' item.status = '(no recipe)'
if not controller:craft(item, count) then if not controller:craft(item, count) then
item.status = '(missing ingredients)' item.status = '(missing ingredients)'
@@ -289,7 +284,7 @@ local function craftItems(craftList, allItems)
end end
end end
local function jobMonitor(jobList) local function jobMonitor()
local mon = Peripheral.getByType('monitor') local mon = Peripheral.getByType('monitor')
@@ -368,7 +363,7 @@ local function watchResources(items)
local craftList = { } local craftList = { }
local outputs = { } local outputs = { }
for k, res in pairs(resources) do for _,res in pairs(resources) do
local item = getItemWithQty(items, res, res.ignoreDamage) local item = getItemWithQty(items, res, res.ignoreDamage)
if not item then if not item then
item = { item = {
@@ -381,8 +376,8 @@ local function watchResources(items)
end end
if res.limit and item.count > res.limit then if res.limit and item.count > res.limit then
local s, m = inventoryAdapter:provide( inventoryAdapter:provide(
{ name = item.name, damage = item.damage }, { name = item.name, damage = item.damage },
item.count - res.limit, item.count - res.limit,
nil, nil,
config.trashDirection) config.trashDirection)
@@ -522,9 +517,9 @@ function itemPage:enable(item)
local devices = self.form[6].choices local devices = self.form[6].choices
Util.clear(devices) Util.clear(devices)
for _,device in pairs(device) do for _,dev in pairs(device) do
if device.setOutput then if dev.setOutput then
table.insert(devices, { name = device.name, value = device.name }) table.insert(devices, { name = dev.name, value = dev.name })
end end
end end
@@ -564,7 +559,7 @@ function itemPage:eventHandler(event)
if filtered.auto ~= true then if filtered.auto ~= true then
filtered.auto = nil filtered.auto = nil
end end
if filtered.rsControl ~= true then if filtered.rsControl ~= true then
filtered.rsControl = nil filtered.rsControl = nil
filtered.rsSide = nil filtered.rsSide = nil
@@ -629,9 +624,6 @@ function listingPage.grid:getRowTextColor(row, selected)
return colors.yellow return colors.yellow
end end
if row.has_recipe then if row.has_recipe then
if selected then
return colors.cyan
end
return colors.cyan return colors.cyan
end end
return UI.Grid:getRowTextColor(row, selected) return UI.Grid:getRowTextColor(row, selected)
@@ -705,7 +697,7 @@ function listingPage:eventHandler(event)
self.grid:draw() self.grid:draw()
end end
elseif event.type == 'text_change' then elseif event.type == 'text_change' then
self.filter = event.text self.filter = event.text
if #self.filter == 0 then if #self.filter == 0 then
self.filter = nil self.filter = nil
@@ -741,7 +733,7 @@ local function getTurtleInventory()
if duckAntenna then if duckAntenna then
local list = duckAntenna.getAllStacks(false) local list = duckAntenna.getAllStacks(false)
for k,v in pairs(list) do for _,v in pairs(list) do
v.name = v.id v.name = v.id
v.damage = v.dmg v.damage = v.dmg
v.displayName = v.display_name v.displayName = v.display_name
@@ -765,22 +757,12 @@ local function getTurtleInventory()
return inventory return inventory
end end
local function filter(t, filter)
local keys = Util.keys(t)
for _,key in pairs(keys) do
if not Util.key(filter, key) then
t[key] = nil
end
end
end
local function learnRecipe(page) local function learnRecipe(page)
local recipe = { }
local ingredients = getTurtleInventory() local ingredients = getTurtleInventory()
if ingredients then if ingredients then
turtle.select(1) turtle.select(1)
if canCraft and turtle.craft() then if canCraft and turtle.craft() then
recipe = getTurtleInventory() local recipe = getTurtleInventory()
if recipe and recipe[1] then if recipe and recipe[1] then
clearGrid() clearGrid()
@@ -851,7 +833,7 @@ function learnPage:disable()
craftingPaused = false craftingPaused = false
UI.Dialog.disable(self) UI.Dialog.disable(self)
end end
function learnPage:eventHandler(event) function learnPage:eventHandler(event)
if event.type == 'cancel' then if event.type == 'cancel' then
UI:setPreviousPage() UI:setPreviousPage()
@@ -902,12 +884,11 @@ function craftPage:disable()
craftingPaused = false craftingPaused = false
UI.Dialog.disable(self) UI.Dialog.disable(self)
end end
function craftPage:eventHandler(event) function craftPage:eventHandler(event)
if event.type == 'cancel' then if event.type == 'cancel' then
UI:setPreviousPage() UI:setPreviousPage()
elseif event.type == 'accept' then --elseif event.type == 'accept' then
else else
return UI.Dialog.eventHandler(self, event) return UI.Dialog.eventHandler(self, event)
end end

View File

@@ -1,9 +1,12 @@
requireInjector(getfenv(1)) _G.requireInjector()
local Terminal = require('terminal') local Terminal = require('terminal')
local shell = _ENV.shell
local term = _G.term
local args = { ... } local args = { ... }
local mon = device[table.remove(args, 1) or 'monitor'] local mon = _G.device[table.remove(args, 1) or 'monitor']
if not mon then if not mon then
error('mirror: Invalid device') error('mirror: Invalid device')
end end

View File

@@ -1,11 +1,13 @@
requireInjector(getfenv(1)) _G.requireInjector()
local Event = require('event') local Event = require('event')
local Logger = require('logger') local Logger = require('logger')
local Socket = require('socket') local Socket = require('socket')
local Terminal = require('terminal')
local Util = require('util') local Util = require('util')
local multishell = _ENV.multishell
local os = _G.os
Logger.setScreenLogging() Logger.setScreenLogging()
local remoteId local remoteId
@@ -14,7 +16,7 @@ if #args == 1 then
remoteId = tonumber(args[1]) remoteId = tonumber(args[1])
else else
print('Enter host ID') print('Enter host ID')
remoteId = tonumber(read()) remoteId = tonumber(_G.read())
end end
if not remoteId then if not remoteId then
@@ -70,7 +72,7 @@ while true do
while true do while true do
local e = Event.pullEvent() local e = Event.pullEvent()
if e[1] == 'terminate' then if e[1] == 'terminate' then
break break
end end
if not socket.connected then if not socket.connected then
break break

View File

@@ -1,15 +1,18 @@
requireInjector(getfenv(1)) _G.requireInjector()
local Event = require('event') local Event = require('event')
local Logger = require('logger') local Logger = require('logger')
local Socket = require('socket') local Socket = require('socket')
local colors = _G.colors
local term = _G.term
Logger.setScreenLogging() Logger.setScreenLogging()
local mon = term.current() local mon = term.current()
local args = { ... } local args = { ... }
if args[1] then if args[1] then
mon = device[args[1]] mon = _G.device[args[1]]
end end
if not mon then if not mon then

View File

@@ -1,8 +1,14 @@
require = requireInjector(getfenv(1)) _G.requireInjector()
local Event = require('event') local Event = require('event')
local UI = require('ui') local UI = require('ui')
local colors = _G.colors
local device = _G.device
local turtle = _G.turtle
local multishell = _ENV.multishell
multishell.setTitle(multishell.getCurrent(), 'Music') multishell.setTitle(multishell.getCurrent(), 'Music')
local radio = device.drive or error('No drive attached') local radio = device.drive or error('No drive attached')
@@ -16,8 +22,6 @@ end
UI:configure('Music', ...) UI:configure('Music', ...)
local monitor = UI.term
UI.Button.defaults.backgroundFocusColor = colors.gray UI.Button.defaults.backgroundFocusColor = colors.gray
local page = UI.Page({ local page = UI.Page({
@@ -146,12 +150,12 @@ function page:eventHandler(event)
end end
end end
function page:setVolume(volume, displayOnly) function page:setVolume(volume)
volume = math.min(volume, 15) volume = math.min(volume, 15)
volume = math.max(volume, 1) volume = math.max(volume, 1)
self.volume = volume self.volume = volume
volume = math.ceil(volume / 2) volume = math.ceil(volume / 2)
for i = 1, volume do for i = 1, volume do
self.volumeControls[i].backgroundColor = self.volumeControls[i].backgroundColor =
self.volumeControls[i].color self.volumeControls[i].color
@@ -224,7 +228,7 @@ end
function page:updateStationName() function page:updateStationName()
local title = radio.getAudioTitle() local title = radio.getAudioTitle()
if title then if title then
self.stationName.value = title self.stationName.value = title
self.stationName:draw() self.stationName:draw()

View File

@@ -1,9 +1,16 @@
local injector = requireInjector or load(http.get('https://raw.githubusercontent.com/kepler155c/opus/master/sys/apis/injector.lua').readAll())() local injector = requireInjector or load(http.get('https://raw.githubusercontent.com/kepler155c/opus/master/sys/apis/injector.lua').readAll())()
injector(getfenv(1)) injector()
local Canvas = require('ui.canvas') local Canvas = require('ui.canvas')
local Util = require('util') local Util = require('util')
local colors = _G.colors
local os = _G.os
local peripheral = _G.peripheral
local shell = _ENV.shell
local term = _G.term
local window = _G.window
local function syntax() local function syntax()
printError('Syntax:') printError('Syntax:')
error('mwm sessionName [monitor]') error('mwm sessionName [monitor]')
@@ -18,7 +25,7 @@ local sessionFile = args[1] or syntax()
local running local running
local monitor local monitor
local defaultEnv = Util.shallowCopy(getfenv(1)) local defaultEnv = Util.shallowCopy(_ENV)
defaultEnv.multishell = multishell defaultEnv.multishell = multishell
if args[2] then if args[2] then
@@ -55,7 +62,7 @@ end
local function getProcessAt(x, y) local function getProcessAt(x, y)
for k = #processes, 1, -1 do for k = #processes, 1, -1 do
local process = processes[k] local process = processes[k]
if x >= process.x and if x >= process.x and
y >= process.y and y >= process.y and
x <= process.x + process.width - 1 and x <= process.x + process.width - 1 and
y <= process.y + process.height - 1 then y <= process.y + process.height - 1 then
@@ -356,7 +363,7 @@ function multishell.removeProcess(process)
redraw() redraw()
end end
function multishell.saveSession(sessionFile) function multishell.saveSession(filename)
local t = { } local t = { }
for _,process in pairs(processes) do for _,process in pairs(processes) do
if process.path and not process.isShell then if process.path and not process.isShell then
@@ -370,11 +377,11 @@ function multishell.saveSession(sessionFile)
}) })
end end
end end
Util.writeTable(sessionFile, t) Util.writeTable(filename, t)
end end
function multishell.loadSession(sessionFile) function multishell.loadSession(filename)
local config = Util.readTable(sessionFile) local config = Util.readTable(filename)
if config then if config then
for _,v in pairs(config) do for _,v in pairs(config) do
multishell.openTab(v) multishell.openTab(v)

View File

@@ -1,4 +1,4 @@
requireInjector(getfenv(1)) _G.requireInjector()
local ChestAdapter = require('chestAdapter18') local ChestAdapter = require('chestAdapter18')
local Event = require('event') local Event = require('event')
@@ -7,6 +7,9 @@ local RefinedAdapter = require('refinedAdapter')
local UI = require('ui') local UI = require('ui')
local Util = require('util') local Util = require('util')
local colors = _G.colors
local multishell = _ENV.multishell
local storage = RefinedAdapter() local storage = RefinedAdapter()
if not storage:isValid() then if not storage:isValid() then
storage = MEAdapter({ auto = true }) storage = MEAdapter({ auto = true })
@@ -73,7 +76,7 @@ function changedPage.grid:getDisplayValues(row)
end end
function changedPage:eventHandler(event) function changedPage:eventHandler(event)
if event.type == 'reset' then if event.type == 'reset' then
self.lastItems = nil self.lastItems = nil
self.grid:setValues({ }) self.grid:setValues({ })
@@ -102,22 +105,23 @@ end
function changedPage:refresh() function changedPage:refresh()
local t = storage:listItems() local t = storage:listItems()
if not t or Util.empty(t) then if not t or Util.empty(t) then
self:clear() self:clear()
self:centeredWrite(math.ceil(self.height/2), 'Communication failure') self:centeredWrite(math.ceil(self.height/2), 'Communication failure')
return return
end end
for k,v in pairs(t) do for k,v in pairs(t) do
t[k] = Util.shallowCopy(v) t[k] = Util.shallowCopy(v)
end end
if not self.lastItems then if not self.lastItems then
self.lastItems = t self.lastItems = t
self.grid:setValues({ }) self.grid:setValues({ })
else else
local changedItems = {} local changedItems = { }
local found
for _,v in pairs(self.lastItems) do for _,v in pairs(self.lastItems) do
found = false found = false
for k2,v2 in pairs(t) do for k2,v2 in pairs(t) do
@@ -141,12 +145,12 @@ function changedPage:refresh()
end end
end end
-- No items left -- No items left
for k,v in pairs(t) do for _,v in pairs(t) do
v.lastCount = 0 v.lastCount = 0
table.insert(changedItems, v) table.insert(changedItems, v)
end end
for k,v in pairs(changedItems) do for _,v in pairs(changedItems) do
v.change = v.count - v.lastCount v.change = v.count - v.lastCount
end end
@@ -154,11 +158,11 @@ function changedPage:refresh()
end end
self.grid:draw() self.grid:draw()
end end
Event.onInterval(5, function() Event.onInterval(5, function()
changedPage:refresh() changedPage:refresh()
changedPage:sync() changedPage:sync()
end) end)
UI:setPage(changedPage) UI:setPage(changedPage)
UI:pullEvents() UI:pullEvents()

View File

@@ -1,4 +1,4 @@
requireInjector(getfenv(1)) _G.requireInjector()
--[[ --[[
Requirements: Requirements:
@@ -27,6 +27,10 @@ local Pathing = require('turtle.pathfind')
local Point = require('point') local Point = require('point')
local Util = require('util') local Util = require('util')
local os = _G.os
local read = _G.read
local turtle = _G.turtle
local FUEL_BASE = 0 local FUEL_BASE = 0
local FUEL_DIRE = FUEL_BASE + 10 local FUEL_DIRE = FUEL_BASE + 10
local FUEL_GOOD = FUEL_BASE + 2000 local FUEL_GOOD = FUEL_BASE + 2000
@@ -175,7 +179,7 @@ local function makeSingleCharcoal()
local slots = turtle.getSummedInventory() local slots = turtle.getSummedInventory()
if not state.furnace or if not state.furnace or
slots[CHARCOAL] or slots[CHARCOAL] or
not slots[OAK_LOG] or not slots[OAK_LOG] or
slots[OAK_LOG].count < 2 then slots[OAK_LOG].count < 2 then
@@ -195,13 +199,13 @@ local function makeCharcoal()
local slots = turtle.getSummedInventory() local slots = turtle.getSummedInventory()
if not state.furnace or if not state.furnace or
not slots[CHARCOAL] or not slots[CHARCOAL] or
slots[CHARCOAL].count >= MIN_CHARCOAL then slots[CHARCOAL].count >= MIN_CHARCOAL then
return true return true
end end
local function getLogSlot(slots) local function getLogSlot()
local maxslot = { count = 0 } local maxslot = { count = 0 }
for k,slot in pairs(slots) do for k,slot in pairs(slots) do
if string.match(k, 'minecraft:log') then if string.match(k, 'minecraft:log') then
@@ -214,7 +218,8 @@ local function makeCharcoal()
end end
repeat repeat
local slots = turtle.getSummedInventory() slots = turtle.getSummedInventory()
local charcoal = slots[CHARCOAL].count local charcoal = slots[CHARCOAL].count
local slot = getLogSlot(slots) local slot = getLogSlot(slots)
@@ -266,7 +271,7 @@ local function getCobblestone(count)
turtle.select(1) turtle.select(1)
turtle.digDown() turtle.digDown()
turtle.down() turtle.down()
for i = 1, 4 do for _ = 1, 4 do
if inspect(turtle.inspect) == STONE then if inspect(turtle.inspect) == STONE then
turtle.dig() turtle.dig()
end end
@@ -391,9 +396,9 @@ local function dropOffItems()
if state.chest_1 then if state.chest_1 then
local slots = turtle.getSummedInventory() local slots = turtle.getSummedInventory()
if state.chest_1 and if state.chest_1 and
slots[CHARCOAL] and slots[CHARCOAL] and
slots[CHARCOAL].count >= MIN_CHARCOAL and slots[CHARCOAL].count >= MIN_CHARCOAL and
(turtle.getItemCount('minecraft:log') > 0 or (turtle.getItemCount('minecraft:log') > 0 or
turtle.getItemCount('minecraft:log2') > 0) then turtle.getItemCount('minecraft:log2') > 0) then
@@ -510,10 +515,10 @@ local function fell()
local pts = Util.shallowCopy(state.trees) local pts = Util.shallowCopy(state.trees)
local pt = table.remove(pts, math.random(1, #pts)) local rpt = table.remove(pts, math.random(1, #pts))
-- give the pathfinder hints about what to avoid (state.trees) -- give the pathfinder hints about what to avoid (state.trees)
if not turtle.faceAgainst(pt, { blocks = Util.shallowCopy(state.trees) }) or if not turtle.faceAgainst(rpt, { blocks = Util.shallowCopy(state.trees) }) or
not string.match(inspect(turtle.inspect), 'minecraft:log') then not string.match(inspect(turtle.inspect), 'minecraft:log') then
return true return true
end end
@@ -523,7 +528,7 @@ local function fell()
local fuel = turtle.getFuelLevel() local fuel = turtle.getFuelLevel()
-- push this point to the start of this list -- push this point to the start of this list
table.insert(pts, 1, pt) table.insert(pts, 1, rpt)
Point.eachClosest(turtle.point, pts, function(pt) Point.eachClosest(turtle.point, pts, function(pt)
if turtle.faceAgainst(pt, { blocks = Util.shallowCopy(state.trees) }) and if turtle.faceAgainst(pt, { blocks = Util.shallowCopy(state.trees) }) and
@@ -570,7 +575,7 @@ local function moreTrees()
end) end)
end end
function getTurtleFacing(block) local function getTurtleFacing(block)
local directions = { local directions = {
[5] = 2, [5] = 2,
[3] = 3, [3] = 3,
@@ -586,7 +591,7 @@ function getTurtleFacing(block)
return directions[bi.metadata] return directions[bi.metadata]
end end
function saveTurtleFacing() local function saveTurtleFacing()
if not state.facing then if not state.facing then
setState('facing', getTurtleFacing(CHEST)) setState('facing', getTurtleFacing(CHEST))
end end
@@ -600,9 +605,9 @@ local function findGround()
local s, block = turtle.inspectDown() local s, block = turtle.inspectDown()
if not s then block = { name = 'minecraft:air', metadata = 0 } end if not s then block = { name = 'minecraft:air', metadata = 0 } end
b = block.name .. ':' .. block.metadata local b = block.name .. ':' .. block.metadata
if b == 'minecraft:dirt:0' or if b == 'minecraft:dirt:0' or
b == 'minecraft:grass:0' or b == 'minecraft:grass:0' or
block.name == 'minecraft:chest' then block.name == 'minecraft:chest' then
break break
@@ -719,7 +724,7 @@ local tasks = {
{ desc = 'Placing torches', fn = placeTorches }, { desc = 'Placing torches', fn = placeTorches },
{ desc = 'Refueling', fn = refuel }, { desc = 'Refueling', fn = refuel },
{ desc = 'Dropping off items', fn = dropOffItems }, { desc = 'Dropping off items', fn = dropOffItems },
{ desc = 'Condensing', fn = turtle.condense }, { desc = 'Condensing', fn = turtle.condense },
{ desc = 'Sleeping', fn = updateClock }, { desc = 'Sleeping', fn = updateClock },
} }
@@ -734,12 +739,12 @@ local s, m = turtle.run(function()
turtle.status = task.desc turtle.status = task.desc
turtle.select(1) turtle.select(1)
if not task.fn() then if not task.fn() then
Util.filterInplace(tasks, function(v) return v.fn ~= task.fn end) Util.filterInplace(tasks, function(v) return v.fn ~= task.fn end)
end end
end end
end end
end) end)
if not s then if not s then
error('Failed') error(m or 'Failed')
end end

1
etc/fstab.ignore Normal file
View File

@@ -0,0 +1 @@
forced fstab overwrite