turtle equip round 2
This commit is contained in:
@@ -55,6 +55,13 @@ local function getEquipped()
|
|||||||
end
|
end
|
||||||
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)
|
function Equipper.unequip(side)
|
||||||
local slot = turtle.selectOpenSlot()
|
local slot = turtle.selectOpenSlot()
|
||||||
if not slot then
|
if not slot then
|
||||||
@@ -80,11 +87,12 @@ function Equipper.equip(side, invName, equippedName)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- is it already equipped ?
|
-- 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)
|
return peripheral.getType(side) and peripheral.wrap(side)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- is it equipped on other side ?
|
-- 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])
|
Equipper.unequip(reversed[side])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user