1.7.10 compatibility
This commit is contained in:
@@ -3,6 +3,8 @@ local itemDB = require('itemDB')
|
|||||||
local Peripheral = require('peripheral')
|
local Peripheral = require('peripheral')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
|
local os = _G.os
|
||||||
|
|
||||||
local ChestAdapter = class()
|
local ChestAdapter = class()
|
||||||
|
|
||||||
local convertNames = {
|
local convertNames = {
|
||||||
@@ -13,14 +15,6 @@ local convertNames = {
|
|||||||
displayName = 'display_name',
|
displayName = 'display_name',
|
||||||
maxDamage = 'max_dmg',
|
maxDamage = 'max_dmg',
|
||||||
}
|
}
|
||||||
local keys = {
|
|
||||||
'damage',
|
|
||||||
'displayName',
|
|
||||||
'maxCount',
|
|
||||||
'maxDamage',
|
|
||||||
'name',
|
|
||||||
'nbtHash',
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Strip off color prefix
|
-- Strip off color prefix
|
||||||
local function safeString(text)
|
local function safeString(text)
|
||||||
@@ -50,19 +44,27 @@ end
|
|||||||
|
|
||||||
function ChestAdapter:init(args)
|
function ChestAdapter:init(args)
|
||||||
local defaults = {
|
local defaults = {
|
||||||
name = 'chest',
|
name = 'chest',
|
||||||
direction = 'up',
|
|
||||||
wrapSide = 'bottom',
|
|
||||||
}
|
}
|
||||||
Util.merge(self, defaults)
|
Util.merge(self, defaults)
|
||||||
Util.merge(self, args)
|
Util.merge(self, args)
|
||||||
|
|
||||||
local chest = Peripheral.getBySide(self.wrapSide)
|
local chest
|
||||||
if not chest then
|
if not self.side then
|
||||||
chest = Peripheral.getByMethod('getAllStacks')
|
chest = Peripheral.getByMethod('getAllStacks')
|
||||||
|
else
|
||||||
|
chest = Peripheral.getBySide(self.side)
|
||||||
|
if chest and not chest.getAllStacks then
|
||||||
|
chest = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if chest then
|
if chest then
|
||||||
Util.merge(self, chest)
|
Util.merge(self, chest)
|
||||||
|
|
||||||
|
if chest.listAvailableItems then
|
||||||
|
self.list = chest.listAvailableItems
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -75,30 +77,31 @@ function ChestAdapter:refresh(throttle)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- provide a consolidated list of items
|
-- provide a consolidated list of items
|
||||||
function ChestAdapter:listItems(throttle)
|
function ChestAdapter:listItems()
|
||||||
self.cache = { }
|
local cache = { }
|
||||||
|
local items = { }
|
||||||
|
|
||||||
for _,v in pairs(self.getAllStacks(false)) do
|
for _,v in pairs(self.getAllStacks(false)) do
|
||||||
convertItem(v)
|
convertItem(v)
|
||||||
local key = table.concat({ v.name, v.damage, v.nbtHash }, ':')
|
local key = table.concat({ v.name, v.damage, v.nbtHash }, ':')
|
||||||
|
|
||||||
local entry = self.cache[key]
|
local entry = cache[key]
|
||||||
if not entry then
|
if not entry then
|
||||||
self.cache[key] = v
|
cache[key] = v
|
||||||
|
|
||||||
if not itemDB:get(v) then
|
if not itemDB:get(v) then
|
||||||
local t = { }
|
itemDB:add(v)
|
||||||
for _,k in pairs(keys) do
|
|
||||||
t[k] = v[k]
|
|
||||||
end
|
|
||||||
itemDB:add(t)
|
|
||||||
end
|
end
|
||||||
|
table.insert(items, v)
|
||||||
else
|
else
|
||||||
entry.count = entry.count + v.count
|
entry.count = entry.count + v.count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
itemDB:flush()
|
itemDB:flush()
|
||||||
return self.cache
|
if not Util.empty(items) then
|
||||||
|
self.cache = cache
|
||||||
|
return items
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ChestAdapter:getItemInfo(item)
|
function ChestAdapter:getItemInfo(item)
|
||||||
@@ -139,11 +142,12 @@ function ChestAdapter:extract(slot, qty, toSlot)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ChestAdapter:insert(slot, qty)
|
function ChestAdapter:insert(slot, qty, toSlot)
|
||||||
local s, m = pcall(function() self.pullItem(self.direction, slot, qty) end)
|
-- toSlot not tested ...
|
||||||
|
local s, m = pcall(self.pullItem, self.direction, slot, qty, toSlot)
|
||||||
if not s and m then
|
if not s and m then
|
||||||
os.sleep(1)
|
os.sleep(1)
|
||||||
pcall(function() self.pullItem(self.direction, slot, qty) end)
|
pcall(self.pullItem, self.direction, slot, qty, toSlot)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ local RECIPES_FILE = 'usr/config/recipes.db'
|
|||||||
|
|
||||||
local craftingPaused = false
|
local craftingPaused = false
|
||||||
local canCraft = not not (turtle and turtle.craft)
|
local canCraft = not not (turtle and turtle.craft)
|
||||||
local canLearn = not not duckAntenna or not not turtleChestAdapter
|
local canLearn = not not (canCraft and (duckAntenna or turtleChestAdapter))
|
||||||
local userRecipes = Util.readTable(RECIPES_FILE) or { }
|
local userRecipes = Util.readTable(RECIPES_FILE) or { }
|
||||||
local jobList
|
local jobList
|
||||||
local resources
|
local resources
|
||||||
|
|||||||
@@ -4,12 +4,19 @@ _G.requireInjector(_ENV)
|
|||||||
|
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
|
local fs = _G.fs
|
||||||
local shell = _ENV.shell
|
local shell = _ENV.shell
|
||||||
|
|
||||||
local args = { ... }
|
local args = { ... }
|
||||||
local fileName = args[1] or error('Syntax: persist <file name>')
|
local fileName = args[1] and
|
||||||
|
shell.resolve(args[1]) or
|
||||||
|
error('Syntax: persist <file name>')
|
||||||
|
|
||||||
local c = Util.readFile(shell.resolve(fileName)) or error('Unable to open file')
|
local c = Util.readFile() or error('Unable to read file')
|
||||||
Util.writeFile(shell.resolve(fileName), c)
|
|
||||||
|
-- ensure it is writable - if not an error is thrown
|
||||||
|
Util.writeFile(fileName, '')
|
||||||
|
fs.delete(fileName)
|
||||||
|
Util.writeFile(fileName, c)
|
||||||
|
|
||||||
print('Saved')
|
print('Saved')
|
||||||
|
|||||||
Reference in New Issue
Block a user