Search in sources :

Example 1 with InventoryUtils

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;
}
Also used : AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) InventoryUtils(com.minecolonies.api.util.InventoryUtils) TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) ItemArmor(net.minecraft.item.ItemArmor) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) ItemStack(net.minecraft.item.ItemStack)

Aggregations

InventoryUtils (com.minecolonies.api.util.InventoryUtils)1 AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)1 TileEntityColonyBuilding (com.minecolonies.coremod.tileentities.TileEntityColonyBuilding)1 ItemArmor (net.minecraft.item.ItemArmor)1 ItemStack (net.minecraft.item.ItemStack)1 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)1