From 71dfb8af4b704a163f8bf9317eb6cd78a6cf9a28 Mon Sep 17 00:00:00 2001 From: kepler155c Date: Thu, 8 Mar 2018 10:04:08 -0500 Subject: [PATCH] 1.7.10 compatibility --- apis/chestAdapter.lua | 20 +++++++++++++++----- apis/inventoryAdapter.lua | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/apis/chestAdapter.lua b/apis/chestAdapter.lua index 73292fd..1bf8592 100644 --- a/apis/chestAdapter.lua +++ b/apis/chestAdapter.lua @@ -52,10 +52,10 @@ function ChestAdapter:init(args) local chest if not self.side then - chest = Peripheral.getByMethod('getAllStacks') + chest = Peripheral.getByMethod('getAllStacks') or Peripheral.getByMethod('getAvailableItems') else 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 end end @@ -66,11 +66,21 @@ function ChestAdapter:init(args) if chest.listAvailableItems then self.list = chest.listAvailableItems end + + if chest.getAllStacks then + self._getAllStacks = function() + return self.getAllStacks(false) + end + else + self._getAllStacks = function() + return self.getAvailableItems() + end + end end end function ChestAdapter:isValid() - return not not self.getAllStacks + return not not self._getAllStacks end function ChestAdapter:refresh(throttle) @@ -85,7 +95,7 @@ function ChestAdapter:listItems(throttle) -- getAllStacks sometimes fails pcall(function() - for _,v in pairs(self.getAllStacks(false)) do + for _,v in pairs(self._getAllStacks()) do if v.qty > 0 then convertItem(v) local key = table.concat({ v.name, v.damage, v.nbtHash }, ':') @@ -126,7 +136,7 @@ end function ChestAdapter:provide(item, qty, slot, direction) 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 (not item.damage or stack.dmg == item.damage) and (not item.nbtHash or stack.nbt_hash == item.nbtHash) then diff --git a/apis/inventoryAdapter.lua b/apis/inventoryAdapter.lua index c5d65ae..745f23d 100644 --- a/apis/inventoryAdapter.lua +++ b/apis/inventoryAdapter.lua @@ -6,7 +6,7 @@ function Adapter.wrap(args) 'chestAdapter18', -- adapters for version 1.7 - 'meAdapter', + --'meAdapter', 'chestAdapter', }