added equipTool to InvManager
This commit is contained in:
parent
c0741c48aa
commit
815ccdaab9
@ -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<TurtleSlot> {
|
||||
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<TurtleSlot, String> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user