use of com.minecolonies.api.util.InventoryUtils in project minecolonies by Minecolonies.
the class AbstractEntityAIGuard method goToBuilding.
/**
* Goes back to the building and tries to take armour from it when he hasn't in his inventory.
*
* @return the next state to go to.
*/
protected AIState goToBuilding() {
if (walkToBuilding()) {
return AIState.GUARD_RESTOCK;
}
final AbstractBuildingWorker workBuilding = getOwnBuilding();
if (workBuilding != null) {
final TileEntityColonyBuilding chest = workBuilding.getTileEntity();
for (int i = 0; i < workBuilding.getTileEntity().getSizeInventory(); i++) {
final ItemStack stack = chest.getStackInSlot(i);
if (InventoryUtils.isItemStackEmpty(stack)) {
continue;
}
if (stack.getItem() instanceof ItemArmor && worker.getItemStackFromSlot(((ItemArmor) stack.getItem()).armorType) == null) {
final int emptySlot = InventoryUtils.findFirstSlotInItemHandlerWith(new InvWrapper(worker.getInventoryCitizen()), InventoryUtils::isItemStackEmpty);
if (emptySlot != -1) {
new InvWrapper(worker.getInventoryCitizen()).insertItem(emptySlot, stack, false);
chest.setInventorySlotContents(i, ItemStack.EMPTY);
}
}
dumpAfterActions = DUMP_BASE * workBuilding.getBuildingLevel();
}
}
attacksExecuted = 0;
return AIState.GUARD_SEARCH_TARGET;
}
Aggregations