From 9392fe47f8e27a16d0196e3128bfd276f6956e48 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Thu, 7 Mar 2019 18:14:19 -0500 Subject: [PATCH] turtle equip round 2 --- turtle/apis/equipper.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/turtle/apis/equipper.lua b/turtle/apis/equipper.lua index 5396635..d8c13c6 100644 --- a/turtle/apis/equipper.lua +++ b/turtle/apis/equipper.lua @@ -55,6 +55,13 @@ local function getEquipped() end end +local function matches(left, right) + -- return a match for 'minecraft:diamond_sword:0' with 'minecraft:diamond_sword' + if left and right then + return left:match(right) + end +end + function Equipper.unequip(side) local slot = turtle.selectOpenSlot() if not slot then @@ -80,11 +87,12 @@ function Equipper.equip(side, invName, equippedName) end -- is it already equipped ? - if Equipper.equipped[side] == (equippedName or invName) then + if matches(Equipper.equipped[side], equippedName or invName) then return peripheral.getType(side) and peripheral.wrap(side) end + -- is it equipped on other side ? - if Equipper.equipped[reversed[side]] == (equippedName or invName) then + if matches(Equipper.equipped[reversed[side]], equippedName or invName) then Equipper.unequip(reversed[side]) end