Search in sources :

Example 1 with InventoryCitizen

use of com.minecolonies.coremod.inventory.InventoryCitizen in project minecolonies by Minecolonies.

the class BuildingBuilder method updateAvailableResources.

/**
     * Update the available resources.
     * <p>
     * which are needed for the build and in the builder's chest or inventory
     */
private void updateAvailableResources() {
    final EntityCitizen builder = getWorkerEntity();
    InventoryCitizen builderInventory = null;
    if (builder != null) {
        builderInventory = builder.getInventoryCitizen();
    }
    for (@NotNull final Map.Entry<String, BuildingBuilderResource> entry : neededResources.entrySet()) {
        final BuildingBuilderResource resource = entry.getValue();
        resource.setAvailable(0);
        if (builderInventory != null) {
            resource.addAvailable(InventoryUtils.getItemCountInItemHandler(new InvWrapper(builderInventory), resource.getItem(), resource.getDamageValue()));
        }
        final TileEntity chestInventory = this.getTileEntity();
        if (chestInventory != null) {
            resource.addAvailable(InventoryUtils.getItemCountInProvider(chestInventory, resource.getItem(), resource.getDamageValue()));
        }
        //Count in the additional chests as well
        if (builder != null) {
            for (final BlockPos pos : getAdditionalCountainers()) {
                final TileEntity entity = builder.world.getTileEntity(pos);
                if (entity instanceof TileEntityChest) {
                    resource.addAvailable(InventoryUtils.getItemCountInProvider(entity, resource.getItem(), resource.getDamageValue()));
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityChest(net.minecraft.tileentity.TileEntityChest) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) InventoryCitizen(com.minecolonies.coremod.inventory.InventoryCitizen) BlockPos(net.minecraft.util.math.BlockPos) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) NotNull(org.jetbrains.annotations.NotNull) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with InventoryCitizen

use of com.minecolonies.coremod.inventory.InventoryCitizen in project minecolonies by Minecolonies.

the class AbstractEntityAIBasic method getMostEfficientTool.

/**
     * Calculates the most efficient tool to use
     * on that block.
     *
     * @param target the Block type to mine
     * @return the slot with the best tool
     */
private int getMostEfficientTool(@NotNull final Block target) {
    final String tool = target.getHarvestTool(target.getDefaultState());
    final int required = target.getHarvestLevel(target.getDefaultState());
    int bestSlot = -1;
    int bestLevel = Integer.MAX_VALUE;
    @NotNull final InventoryCitizen inventory = worker.getInventoryCitizen();
    final int hutLevel = worker.getWorkBuilding().getBuildingLevel();
    for (int i = 0; i < new InvWrapper(worker.getInventoryCitizen()).getSlots(); i++) {
        final ItemStack item = inventory.getStackInSlot(i);
        final int level = Utils.getMiningLevel(item, tool);
        if (level >= required && level < bestLevel) {
            if (tool == null || InventoryUtils.verifyToolLevel(item, level, hutLevel)) {
                bestSlot = i;
                bestLevel = level;
            }
        }
    }
    return bestSlot;
}
Also used : InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) InventoryCitizen(com.minecolonies.coremod.inventory.InventoryCitizen) ItemStack(net.minecraft.item.ItemStack) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with InventoryCitizen

use of com.minecolonies.coremod.inventory.InventoryCitizen in project minecolonies by Minecolonies.

the class AbstractEntityAIBasic method checkForTool.

/**
     * Ensures that we have a tool available.
     *
     * @param tool tool required for block
     * @return true if we have a tool
     */
private boolean checkForTool(@NotNull final String tool) {
    final boolean needsTool = !InventoryFunctions.matchFirstInProvider(worker, stack -> Utils.isTool(stack, tool));
    final int hutLevel = worker.getWorkBuilding().getBuildingLevel();
    final InventoryCitizen inventory = worker.getInventoryCitizen();
    final boolean isUsable = InventoryUtils.isToolInItemHandler(new InvWrapper(inventory), tool, hutLevel);
    if (!needsTool && isUsable) {
        return false;
    }
    delay += DELAY_RECHECK;
    if (walkToBuilding()) {
        return true;
    }
    if (isToolInHut(tool)) {
        return false;
    }
    if (!getOwnBuilding().hasOnGoingDelivery()) {
        chatSpamFilter.talkWithoutSpam(COM_MINECOLONIES_COREMOD_ENTITY_WORKER_TOOLREQUEST, tool, InventoryUtils.swapToolGrade(hutLevel));
    }
    return true;
}
Also used : InventoryCitizen(com.minecolonies.coremod.inventory.InventoryCitizen) java.util(java.util) Blocks(net.minecraft.init.Blocks) ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) AbstractJob(com.minecolonies.coremod.colony.jobs.AbstractJob) TextComponentBase(net.minecraft.util.text.TextComponentBase) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) TileEntityChest(net.minecraft.tileentity.TileEntityChest) JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) ItemStack(net.minecraft.item.ItemStack) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) AITarget(com.minecolonies.coremod.entity.ai.util.AITarget) Block(net.minecraft.block.Block) com.minecolonies.api.util(com.minecolonies.api.util) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) ItemStorage(com.minecolonies.coremod.entity.ai.item.handling.ItemStorage) WalkToProxy(com.minecolonies.coremod.entity.pathfinding.WalkToProxy) Predicate(java.util.function.Predicate) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) AIState(com.minecolonies.coremod.entity.ai.util.AIState) Nullable(org.jetbrains.annotations.Nullable) AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) TileEntity(net.minecraft.tileentity.TileEntity) NotNull(org.jetbrains.annotations.NotNull) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) InventoryCitizen(com.minecolonies.coremod.inventory.InventoryCitizen)

Example 4 with InventoryCitizen

use of com.minecolonies.coremod.inventory.InventoryCitizen in project minecolonies by Minecolonies.

the class AbstractEntityAIBasic method checkForPickaxe.

/**
     * Ensures that we have a pickaxe available.
     * Will set {@code needsPickaxe} accordingly.
     *
     * @param minlevel the minimum pickaxe level needed.
     * @return true if we have a pickaxe
     */
private boolean checkForPickaxe(final int minlevel) {
    //Check for a pickaxe
    getOwnBuilding().setNeedsPickaxe(!InventoryFunctions.matchFirstInProvider(worker, stack -> Utils.checkIfPickaxeQualifies(minlevel, Utils.getMiningLevel(stack, Utils.PICKAXE))));
    delay += DELAY_RECHECK;
    final InventoryCitizen inventory = worker.getInventoryCitizen();
    final int hutLevel = worker.getWorkBuilding().getBuildingLevel();
    final boolean isUsable = InventoryUtils.isToolInItemHandler(new InvWrapper(inventory), Utils.PICKAXE, hutLevel);
    if (!isUsable) {
        getOwnBuilding().setNeedsPickaxe(true);
    }
    if (getOwnBuilding().needsPickaxe()) {
        getOwnBuilding().setNeedsPickaxeLevel(minlevel);
        if (walkToBuilding()) {
            return false;
        }
        if (isPickaxeInHut(minlevel)) {
            return true;
        }
        if (!getOwnBuilding().hasOnGoingDelivery()) {
            if (minlevel > hutLevel) {
                chatSpamFilter.talkWithoutSpam(COM_MINECOLONIES_COREMOD_ENTITY_WORKER_PICKAXEREQUESTBETTERHUT, InventoryUtils.swapToolGrade(hutLevel));
            } else {
                chatSpamFilter.talkWithoutSpam(COM_MINECOLONIES_COREMOD_ENTITY_WORKER_PICKAXEREQUEST, InventoryUtils.swapToolGrade(minlevel), InventoryUtils.swapToolGrade(hutLevel));
            }
        }
    }
    return getOwnBuilding().needsPickaxe();
}
Also used : InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) InventoryCitizen(com.minecolonies.coremod.inventory.InventoryCitizen)

Aggregations

InventoryCitizen (com.minecolonies.coremod.inventory.InventoryCitizen)4 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)4 NotNull (org.jetbrains.annotations.NotNull)3 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 TileEntityChest (net.minecraft.tileentity.TileEntityChest)2 BlockPos (net.minecraft.util.math.BlockPos)2 com.minecolonies.api.util (com.minecolonies.api.util)1 TranslationConstants (com.minecolonies.api.util.constant.TranslationConstants)1 AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)1 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)1 AbstractJob (com.minecolonies.coremod.colony.jobs.AbstractJob)1 JobDeliveryman (com.minecolonies.coremod.colony.jobs.JobDeliveryman)1 EntityCitizen (com.minecolonies.coremod.entity.EntityCitizen)1 ItemStorage (com.minecolonies.coremod.entity.ai.item.handling.ItemStorage)1 AIState (com.minecolonies.coremod.entity.ai.util.AIState)1 AITarget (com.minecolonies.coremod.entity.ai.util.AITarget)1 WalkToProxy (com.minecolonies.coremod.entity.pathfinding.WalkToProxy)1 java.util (java.util)1 HashMap (java.util.HashMap)1