diff --git a/src/lib/turtle/InvManager.hx b/src/lib/turtle/InvManager.hx index 26d7a77..be10abd 100644 --- a/src/lib/turtle/InvManager.hx +++ b/src/lib/turtle/InvManager.hx @@ -1,5 +1,8 @@ package lib.turtle; +import kernel.turtle.Types.ToolSide; +import lua.Result; +import kernel.peripherals.Side; import kernel.log.Log; import kernel.turtle.Types.TurtleSlot; import kernel.turtle.Types.InteractDirections; @@ -103,6 +106,21 @@ class InvManager { return rtn; } + /** + Returns the first slot that contains this item. + **/ + public static function findItemSlot(item:Item):Null { + var invState = getInvState(); + + for (k => slot in invState) { + if (slot.name == item) { + return k; + } + } + + return null; + } + /** Cleans up turtle inventory. Moves items together. This should be run in a turtle thread. @@ -180,4 +198,22 @@ class InvManager { } } } + + public static function equipTool(item:Item, side:ToolSide):Outcome { + var toolSlot = findItemSlot(item); + + if (toolSlot == null) { + return Failure("Item not found"); + } + + Turtle.selectSlot(toolSlot); + var result = Turtle.equip(side); + + switch result { + case Success(_): + return Success(toolSlot); + case Failure(failure): + return Failure(failure); + } + } }