diff --git a/farms/attack.lua b/farms/attack.lua index dcc97f7..e283f2e 100644 --- a/farms/attack.lua +++ b/farms/attack.lua @@ -1,11 +1,9 @@ -_G.requireInjector(_ENV) - +local Peripheral = require('peripheral') local Point = require('point') local Util = require('util') local device = _G.device local os = _G.os -local peripheral = _G.peripheral local turtle = _G.turtle local args = { ... } @@ -21,12 +19,23 @@ local Runners = { } local function equip(side, item, rawName) - if peripheral.getType(side) ~= item then - if not turtle.equip(side, rawName or item) then + local equipped = Peripheral.lookup('side/' .. side) + + if equipped and equipped.type == item then + return true + end + + if not turtle.equip(side, rawName or item) then + if not turtle.selectSlotWithQuantity(0) then + error('No slots available') + end + turtle.equip(side) + if not turtle.equip(side, item) then error('Unable to equip ' .. item) end - turtle.select(1) end + + turtle.select(1) end equip('left', 'minecraft:diamond_sword') diff --git a/farms/rancher.lua b/farms/rancher.lua index fd70291..dfe5603 100644 --- a/farms/rancher.lua +++ b/farms/rancher.lua @@ -1,13 +1,13 @@ _G.requireInjector(_ENV) -local Config = require('config') -local Util = require('util') local Adapter = require('chestAdapter18') +local Config = require('config') +local Peripheral = require('peripheral') +local Util = require('util') local device = _G.device local fs = _G.fs local os = _G.os -local peripheral = _G.peripheral local turtle = _G.turtle local STARTUP_FILE = 'usr/autorun/rancher.lua' @@ -33,12 +33,23 @@ local ANIMALS = { local animal = ANIMALS[config.animal] local function equip(side, item, rawName) - if peripheral.getType(side) ~= item then - if not turtle.equip(side, rawName or item) then + local equipped = Peripheral.lookup('side/' .. side) + + if equipped and equipped.type == item then + return true + end + + if not turtle.equip(side, rawName or item) then + if not turtle.selectSlotWithQuantity(0) then + error('No slots available') + end + turtle.equip(side) + if not turtle.equip(side, item) then error('Unable to equip ' .. item) end - turtle.select(1) end + + turtle.select(1) end local function getLocalName() diff --git a/milo/apps/furni.lua b/milo/apps/furni.lua index 56fe9e9..6969d3b 100644 --- a/milo/apps/furni.lua +++ b/milo/apps/furni.lua @@ -18,23 +18,34 @@ Use this turtle for machine crafting. _G.requireInjector(_ENV) local Event = require('event') +local Peripheral = require('peripheral') local Util = require('util') local device = _G.device local fs = _G.fs local os = _G.os -local peripheral = _G.peripheral local turtle = _G.turtle local STARTUP_FILE = 'usr/autorun/miloFurni.lua' local function equip(side, item, rawName) - if peripheral.getType(side) ~= item then - if not turtle.equip(side, rawName or item) then + local equipped = Peripheral.lookup('side/' .. side) + + if equipped and equipped.type == item then + return true + end + + if not turtle.equip(side, rawName or item) then + if not turtle.selectSlotWithQuantity(0) then + error('No slots available') + end + turtle.equip(side) + if not turtle.equip(side, item) then error('Unable to equip ' .. item) end - turtle.select(1) end + + turtle.select(1) end equip('left', 'plethora:introspection', 'plethora:module:0')