turtle equip round 2

This commit is contained in:
kepler155c@gmail.com
2019-03-07 18:14:19 -05:00
parent 7d83e66e4a
commit 9392fe47f8

View File

@@ -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