From 08bc0d578e2910f67fd8b4bf16bb0d13298f2954 Mon Sep 17 00:00:00 2001 From: kepler155c Date: Thu, 29 Mar 2018 05:04:34 -0400 Subject: [PATCH] plethora import/export support + introspection module --- apis/chestAdapter18.lua | 5 +++-- apis/refinedAdapter.lua | 11 ++++++++--- apps/chestManager.lua | 30 ++++++++++++++++++++++-------- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/apis/chestAdapter18.lua b/apis/chestAdapter18.lua index 99e010f..8d5cc01 100644 --- a/apis/chestAdapter18.lua +++ b/apis/chestAdapter18.lua @@ -14,10 +14,11 @@ function ChestAdapter:init(args) local chest if not self.side then - chest = Peripheral.getByMethod('list') or Peripheral.getByMethod('listAvailableItems') + chest = Peripheral.getByMethod('list') + -- or Peripheral.getByMethod('listAvailableItems') else chest = Peripheral.getBySide(self.side) - if chest and not chest.list and not chest.listAvailableItems then + if chest and not chest.list then -- and not chest.listAvailableItems then chest = nil end end diff --git a/apis/refinedAdapter.lua b/apis/refinedAdapter.lua index da38a41..b80249d 100644 --- a/apis/refinedAdapter.lua +++ b/apis/refinedAdapter.lua @@ -14,10 +14,10 @@ function RefinedAdapter:init(args) local controller if not self.side then - controller = Peripheral.getByType('refinedstorage:controller') + controller = Peripheral.getByMethod('listAvailableItems') else controller = Peripheral.getBySide(self.side) - if controller and not controller.getCraftingTasks then + if controller and not controller.listAvailableItems then controller = nil end end @@ -131,7 +131,12 @@ function RefinedAdapter:provide(item, qty, slot, direction) end) end -function RefinedAdapter:insert() +function RefinedAdapter:extract(slot, qty, toSlot) + self.pushItems(self.direction, slot, qty, toSlot) +end + +function RefinedAdapter:insert(slot, qty, toSlot) + self.pullItems(self.direction, slot, qty, toSlot) end return RefinedAdapter diff --git a/apps/chestManager.lua b/apps/chestManager.lua index 4647f61..d233609 100644 --- a/apps/chestManager.lua +++ b/apps/chestManager.lua @@ -24,7 +24,11 @@ 2. Requires a vanilla chest beside the turtle with the "craftingChest" configuration variable defined. -- or -- - If using MC 1.7x, you can equip the turtle with a duck antenna. + If using MC 1.7x, you can equip the turtle with a duck antenna and + set the duckAntenna configuration value to true. + -- or -- + If plethora mod is available, equip the turtle with an introspection + module. Controller (optional): Provides the ability to request crafting from AE / RS @@ -38,7 +42,7 @@ Refined Storage In versions 1.8x, inventory access works depending upon version. - Turtle/computer must be touching controller for inventory access. If only + Turtle/computer must be touching an interface for inventory access. If only requesting crafting, the controller must be either be touching or connected via CC cables. @@ -66,6 +70,7 @@ craftingChest : side for the chest used for crafting controller : side for AE cable/interface or RS controller stock : side for restocking inventory + duckAntenna : true/false if the 1.7 openperipherals duck antenna is equipped trashDirection : direction of trash block (trashcan/inventory/etc) in relationship to the main inventory. This block does not need to touch the turtle, only the main inventory block. @@ -116,11 +121,12 @@ local config = { Config.loadWithCheck('inventoryManager', config) -local controllerAdapter = ControllerAdapter.wrap({ side = config.controller, facing = config.computerFacing }) -local inventoryAdapter = InventoryAdapter.wrap({ side = config.inventory, facing = config.computerFacing }) -local stockAdapter = InventoryAdapter.wrap({ side = config.stock, facing = config.computerFacing }) -local turtleChestAdapter = InventoryAdapter.wrap({ side = config.craftingChest, facing = config.computerFacing }) -local modem = device.modem +local controllerAdapter = ControllerAdapter.wrap({ side = config.controller, facing = config.computerFacing }) +local inventoryAdapter = InventoryAdapter.wrap({ side = config.inventory, facing = config.computerFacing }) +local stockAdapter = InventoryAdapter.wrap({ side = config.stock, facing = config.computerFacing }) +local turtleChestAdapter = InventoryAdapter.wrap({ side = config.craftingChest, facing = config.computerFacing }) +local modem = device.modem +local introspectionModule = device['plethora:introspection'] local duckAntenna if not inventoryAdapter then @@ -148,7 +154,7 @@ local RECIPES_FILE = 'usr/config/recipes.db' local craftingPaused = false local canCraft = not not (turtle and turtle.craft) -local canLearn = not not (canCraft and (duckAntenna or turtleChestAdapter)) +local canLearn = not not (canCraft and (duckAntenna or turtleChestAdapter or introspectionModule)) local userRecipes = Util.readTable(RECIPES_FILE) or { } local jobList local resources @@ -1115,6 +1121,14 @@ local function getTurtleInventory() return list end + if introspectionModule then + local list = { } + for i = 1,16 do + list[i] = introspectionModule.getInventory().getItemMeta(i) + end + return list + end + local inventory = { } for i = 1,16 do local qty = turtle.getItemCount(i)