1.7.10 compatibility

This commit is contained in:
kepler155c
2018-03-08 10:04:08 -05:00
parent 37d3264999
commit 71dfb8af4b
2 changed files with 16 additions and 6 deletions

View File

@@ -52,10 +52,10 @@ function ChestAdapter:init(args)
local chest local chest
if not self.side then if not self.side then
chest = Peripheral.getByMethod('getAllStacks') chest = Peripheral.getByMethod('getAllStacks') or Peripheral.getByMethod('getAvailableItems')
else else
chest = Peripheral.getBySide(self.side) chest = Peripheral.getBySide(self.side)
if chest and not chest.getAllStacks then if chest and not chest.getAllStacks and not chest.getAvailableItems then
chest = nil chest = nil
end end
end end
@@ -66,11 +66,21 @@ function ChestAdapter:init(args)
if chest.listAvailableItems then if chest.listAvailableItems then
self.list = chest.listAvailableItems self.list = chest.listAvailableItems
end end
if chest.getAllStacks then
self._getAllStacks = function()
return self.getAllStacks(false)
end
else
self._getAllStacks = function()
return self.getAvailableItems()
end
end
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)
@@ -85,7 +95,7 @@ function ChestAdapter:listItems(throttle)
-- getAllStacks sometimes fails -- getAllStacks sometimes fails
pcall(function() pcall(function()
for _,v in pairs(self.getAllStacks(false)) do for _,v in pairs(self._getAllStacks()) do
if v.qty > 0 then if v.qty > 0 then
convertItem(v) convertItem(v)
local key = table.concat({ v.name, v.damage, v.nbtHash }, ':') local key = table.concat({ v.name, v.damage, v.nbtHash }, ':')
@@ -126,7 +136,7 @@ end
function ChestAdapter:provide(item, qty, slot, direction) function ChestAdapter:provide(item, qty, slot, direction)
pcall(function() pcall(function()
for key,stack in Util.rpairs(self.getAllStacks(false)) do for key,stack in Util.rpairs(self._getAllStacks()) do
if stack.id == item.name and if stack.id == item.name and
(not item.damage or stack.dmg == item.damage) and (not item.damage or stack.dmg == item.damage) and
(not item.nbtHash or stack.nbt_hash == item.nbtHash) then (not item.nbtHash or stack.nbt_hash == item.nbtHash) then

View File

@@ -6,7 +6,7 @@ function Adapter.wrap(args)
'chestAdapter18', 'chestAdapter18',
-- adapters for version 1.7 -- adapters for version 1.7
'meAdapter', --'meAdapter',
'chestAdapter', 'chestAdapter',
} }