Search in sources :

Example 1 with AIState

use of com.minecolonies.coremod.entity.ai.util.AIState in project minecolonies by Minecolonies.

the class EntityAIWorkDeliveryman method tryToGatherItems.

/**
     * Gather item from chest.
     * Gathers only one stack of the item.
     *
     * @param buildingToDeliver building to deliver to.
     */
private AIState tryToGatherItems(@NotNull final AbstractBuilding buildingToDeliver) {
    final BlockPos position;
    if (buildingToDeliver instanceof BuildingHome) {
        position = wareHouse.getTileEntity().getPositionOfChestWithItemStack(itemStack -> !InventoryUtils.isItemStackEmpty(itemStack) && itemStack.getItem() instanceof ItemFood);
    } else if (itemsToDeliver.isEmpty()) {
        final String tool = buildingToDeliver.getRequiredTool();
        position = wareHouse.getTileEntity().getPositionOfChestWithTool(tool, Utils.PICKAXE.equals(tool) ? buildingToDeliver.getNeededPickaxeLevel() : buildingToDeliver.getBuildingLevel(), buildingToDeliver);
    } else {
        final ItemStack stack = itemsToDeliver.get(0);
        position = wareHouse.getTileEntity().getPositionOfChestWithItemStack(stack);
    }
    if (position == null) {
        ((BuildingDeliveryman) getOwnBuilding()).setBuildingToDeliver(null);
        itemsToDeliver.clear();
        return START_WORKING;
    }
    if (!worker.isWorkerAtSiteWithMove(position, MIN_DISTANCE_TO_CHEST)) {
        setDelay(DUMP_AND_GATHER_DELAY);
        return GATHER_IN_WAREHOUSE;
    }
    return gatherItems(buildingToDeliver, position);
}
Also used : Utils(com.minecolonies.api.util.Utils) TileEntityChest(net.minecraft.tileentity.TileEntityChest) ArrayList(java.util.ArrayList) JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) ItemStack(net.minecraft.item.ItemStack) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) AITarget(com.minecolonies.coremod.entity.ai.util.AITarget) Map(java.util.Map) AbstractEntityAIInteract(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIInteract) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) ItemStorage(com.minecolonies.coremod.entity.ai.item.handling.ItemStorage) Colony(com.minecolonies.coremod.colony.Colony) Collection(java.util.Collection) ItemFood(net.minecraft.item.ItemFood) BlockPos(net.minecraft.util.math.BlockPos) AIState(com.minecolonies.coremod.entity.ai.util.AIState) TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) com.minecolonies.coremod.colony.buildings(com.minecolonies.coremod.colony.buildings) TextComponentString(net.minecraft.util.text.TextComponentString) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) InventoryUtils(com.minecolonies.api.util.InventoryUtils) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) TileEntity(net.minecraft.tileentity.TileEntity) NotNull(org.jetbrains.annotations.NotNull) ItemFood(net.minecraft.item.ItemFood) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString) ItemStack(net.minecraft.item.ItemStack)

Example 2 with AIState

use of com.minecolonies.coremod.entity.ai.util.AIState in project minecolonies by Minecolonies.

the class EntityAIWorkFisherman method doFishing.

/**
     * Main fishing methods,
     * let's the fisherman gather xp orbs next to him,
     * check if all requirements to fish are given.
     * Actually fish, retrieve his rod if stuck or if a fish bites.
     *
     * @return the next AIState the fisherman should switch to, after executing this method.
     */
@Nullable
private AIState doFishing() {
    @Nullable final AIState notReadyState = isReadyToFish();
    if (notReadyState != null) {
        return notReadyState;
    }
    if (caughtFish()) {
        this.getOwnBuilding().getColony().incrementStatistic("fish");
        playCaughtFishSound();
        if (random.nextDouble() < CHANCE_NEW_POND) {
            job.setWater(null);
            return FISHERMAN_SEARCHING_WATER;
        }
        return FISHERMAN_WALKING_TO_WATER;
    }
    return throwOrRetrieveHook();
}
Also used : AIState(com.minecolonies.coremod.entity.ai.util.AIState) Nullable(org.jetbrains.annotations.Nullable) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AIState (com.minecolonies.coremod.entity.ai.util.AIState)2 Nullable (org.jetbrains.annotations.Nullable)2 InventoryUtils (com.minecolonies.api.util.InventoryUtils)1 Utils (com.minecolonies.api.util.Utils)1 TranslationConstants (com.minecolonies.api.util.constant.TranslationConstants)1 Colony (com.minecolonies.coremod.colony.Colony)1 com.minecolonies.coremod.colony.buildings (com.minecolonies.coremod.colony.buildings)1 JobDeliveryman (com.minecolonies.coremod.colony.jobs.JobDeliveryman)1 EntityCitizen (com.minecolonies.coremod.entity.EntityCitizen)1 AbstractEntityAIInteract (com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIInteract)1 ItemStorage (com.minecolonies.coremod.entity.ai.item.handling.ItemStorage)1 AITarget (com.minecolonies.coremod.entity.ai.util.AITarget)1 TileEntityColonyBuilding (com.minecolonies.coremod.tileentities.TileEntityColonyBuilding)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 ItemFood (net.minecraft.item.ItemFood)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1