1.7.10 compatibility

This commit is contained in:
kepler155c
2018-03-08 10:27:14 -05:00
parent 715fc1c2c6
commit 8096a208e1
3 changed files with 19 additions and 33 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') or Peripheral.getByMethod('getAvailableItems') chest = Peripheral.getByMethod('getAllStacks')
else else
chest = Peripheral.getBySide(self.side) 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 chest = nil
end end
end end
@@ -66,26 +66,11 @@ 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()
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
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)
@@ -100,7 +85,7 @@ function ChestAdapter:listItems(throttle)
-- getAllStacks sometimes fails -- getAllStacks sometimes fails
pcall(function() pcall(function()
for _,v in pairs(self._getAllStacks()) do for _,v in pairs(self.getAllStacks(false)) 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 }, ':')
@@ -141,7 +126,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()) do for key,stack in Util.rpairs(self.getAllStacks(false)) 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',
} }

View File

@@ -206,20 +206,21 @@ function MEAdapter:craftItems(items)
end end
end end
function MEAdapter:provide(item, count, slot, direction) function MEAdapter:provide(item, qty, slot, direction)
return pcall(function() return pcall(function()
while count > 0 do for _,stack in Util.rpairs(self.getAllStacks(false)) do
local qty = math.min(count, 64) if stack.id == item.name and
local s = self.exportItem({ (not item.damage or stack.dmg == item.damage) and
id = item.name, (not item.nbtHash or stack.nbt_hash == item.nbtHash) then
dmg = item.damage, local amount = math.min(qty, stack.qty)
nbt_hash = item.nbtHash, if amount > 0 then
}, direction or self.direction, qty, slot) self.exportItem(stack, direction or self.direction, amount, slot)
end
if not s or s.size ~= qty then qty = qty - amount
if qty <= 0 then
break break
end end
count = count - 64 end
end end
end) end)
end end