1.7.10 compatibility
This commit is contained in:
@@ -52,10 +52,10 @@ function ChestAdapter:init(args)
|
||||
|
||||
local chest
|
||||
if not self.side then
|
||||
chest = Peripheral.getByMethod('getAllStacks') or Peripheral.getByMethod('getAvailableItems')
|
||||
chest = Peripheral.getByMethod('getAllStacks')
|
||||
else
|
||||
chest = Peripheral.getBySide(self.side)
|
||||
if chest and not chest.getAllStacks and not chest.getAvailableItems then
|
||||
if chest and not chest.getAllStacks then
|
||||
chest = nil
|
||||
end
|
||||
end
|
||||
@@ -66,26 +66,11 @@ 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()
|
||||
local t = { }
|
||||
for _,v in pairs(self.getAvailableItems('all')) do
|
||||
v.item.is_craftable = v.is_craftable
|
||||
table.insert(t, v.item)
|
||||
end
|
||||
return t
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ChestAdapter:isValid()
|
||||
return not not self._getAllStacks
|
||||
return not not self.getAllStacks
|
||||
end
|
||||
|
||||
function ChestAdapter:refresh(throttle)
|
||||
@@ -100,7 +85,7 @@ function ChestAdapter:listItems(throttle)
|
||||
|
||||
-- getAllStacks sometimes fails
|
||||
pcall(function()
|
||||
for _,v in pairs(self._getAllStacks()) do
|
||||
for _,v in pairs(self.getAllStacks(false)) do
|
||||
if v.qty > 0 then
|
||||
convertItem(v)
|
||||
local key = table.concat({ v.name, v.damage, v.nbtHash }, ':')
|
||||
@@ -141,7 +126,7 @@ end
|
||||
|
||||
function ChestAdapter:provide(item, qty, slot, direction)
|
||||
pcall(function()
|
||||
for key,stack in Util.rpairs(self._getAllStacks()) do
|
||||
for key,stack in Util.rpairs(self.getAllStacks(false)) 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
|
||||
|
||||
@@ -6,7 +6,7 @@ function Adapter.wrap(args)
|
||||
'chestAdapter18',
|
||||
|
||||
-- adapters for version 1.7
|
||||
--'meAdapter',
|
||||
'meAdapter',
|
||||
'chestAdapter',
|
||||
}
|
||||
|
||||
|
||||
@@ -206,20 +206,21 @@ function MEAdapter:craftItems(items)
|
||||
end
|
||||
end
|
||||
|
||||
function MEAdapter:provide(item, count, slot, direction)
|
||||
function MEAdapter:provide(item, qty, slot, direction)
|
||||
return pcall(function()
|
||||
while count > 0 do
|
||||
local qty = math.min(count, 64)
|
||||
local s = self.exportItem({
|
||||
id = item.name,
|
||||
dmg = item.damage,
|
||||
nbt_hash = item.nbtHash,
|
||||
}, direction or self.direction, qty, slot)
|
||||
|
||||
if not s or s.size ~= qty then
|
||||
break
|
||||
for _,stack in Util.rpairs(self.getAllStacks(false)) 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
|
||||
local amount = math.min(qty, stack.qty)
|
||||
if amount > 0 then
|
||||
self.exportItem(stack, direction or self.direction, amount, slot)
|
||||
end
|
||||
qty = qty - amount
|
||||
if qty <= 0 then
|
||||
break
|
||||
end
|
||||
end
|
||||
count = count - 64
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user