From 1643151bb3db24575549c66d6759a93a3bcc1578 Mon Sep 17 00:00:00 2001 From: osmarks Date: Sun, 29 Jul 2018 10:35:10 +0100 Subject: [PATCH] Make chest backend only consider internal chests --- backend-chests.lua | 4 +++- lib.lua | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/backend-chests.lua b/backend-chests.lua index b6962bc..9b6283b 100644 --- a/backend-chests.lua +++ b/backend-chests.lua @@ -7,6 +7,8 @@ local d = require "luadash" local conf = w.load_config({ "buffer_internal", "buffer_external" +}, { + "modem_internal" = nil }) local BUFFER_OUT_SLOT = 1 @@ -15,7 +17,7 @@ local BUFFER_IN_SLOT = 2 -- Find all chests or shulker boxes local inventories = d.map_with_key(w.find_peripherals(function(type, name, wrapped) return string.find(name, "chest") or string.find(name, "shulker") -end), function(_, p) return p.name, p.wrapped end) +end, conf.modem_internal), function(_, p) return p.name, p.wrapped end) local display_name_cache = {} diff --git a/lib.lua b/lib.lua index 68f22e4..08b2d62 100644 --- a/lib.lua +++ b/lib.lua @@ -225,9 +225,15 @@ local function load_config(required_data, defaults, filename) end -- Returns a list of peripheral objects whose type, name and object satisfy the given predicate -local function find_peripherals(predicate) +local function find_peripherals(predicate, from) local matching = {} - for k, name in pairs(peripheral.getNames()) do + local list + if from then + list = peripheral.call(from, "getNamesRemote") + else + list = peripheral.getNames() + end + for k, name in pairs(list) do local wrapped = peripheral.wrap(name) local type = peripheral.getType(name) if predicate(type, name, wrapped) then table.insert(matching, { wrapped = wrapped, name = name} ) end