Search in sources :

Example 56 with IAIState

use of com.minecolonies.api.entity.ai.statemachine.states.IAIState in project minecolonies by ldtteam.

the class EntityAIWorkNether method decide.

@Override
protected IAIState decide() {
    if (job.isInNether()) {
        if (!worker.isInvisible()) {
            goToVault();
        }
        return NETHER_AWAY;
    }
    if (worker.isInvisible()) {
        returnFromVault();
    }
    IAIState crafterState = super.decide();
    if (crafterState != IDLE && crafterState != START_WORKING) {
        return crafterState;
    }
    // Get Armor if available.
    // This is async, so we could go to the nether without it.
    checkAndRequestArmor();
    // Check for materials needed to go to the Nether:
    IRecipeStorage rs = getOwnBuilding().getFirstModuleOccurance(BuildingNetherWorker.CraftingModule.class).getFirstRecipe(ItemStack::isEmpty);
    if (rs != null) {
        for (ItemStorage item : rs.getInput()) {
            checkAndRequestMaterials(item.getItemStack(), item.getAmount());
        }
    }
    // Make sure we have a stash of some food
    checkAndRequestFood(16);
    // Get other adventuring supplies. These are required.
    // Done this way to get all the requests in parallel
    boolean haveAxe = checkForToolOrWeapon(ToolType.AXE);
    boolean havePick = checkForToolOrWeapon(ToolType.PICKAXE);
    boolean haveShovel = checkForToolOrWeapon(ToolType.SHOVEL);
    boolean haveSword = checkForToolOrWeapon(ToolType.SWORD);
    boolean haveLighter = checkForToolOrWeapon(ToolType.FLINT_N_STEEL);
    if (haveAxe || havePick || haveShovel || haveSword || haveLighter) {
        worker.getCitizenData().setIdleAtJob(true);
        return IDLE;
    }
    if (currentRecipeStorage == null) {
        final ICraftingBuildingModule module = getOwnBuilding().getFirstModuleOccurance(BuildingNetherWorker.CraftingModule.class);
        currentRecipeStorage = module.getFirstFulfillableRecipe(ItemStackUtils::isEmpty, 1, false);
        if (getOwnBuilding().isReadyForTrip()) {
            worker.getCitizenData().setIdleAtJob(true);
        }
        final BlockPos portal = getOwnBuilding().getPortalLocation();
        if (portal != null && currentRecipeStorage == null && getOwnBuilding().shallClosePortalOnReturn()) {
            final BlockState block = world.getBlockState(portal);
            if (block.is(Blocks.NETHER_PORTAL)) {
                return NETHER_CLOSEPORTAL;
            }
        }
        return getState();
    } else {
        if (!getOwnBuilding().isReadyForTrip()) {
            worker.getCitizenData().setIdleAtJob(false);
            return IDLE;
        }
        if (walkTo != null || walkToBuilding()) {
            return getState();
        }
        if (InventoryUtils.isItemHandlerFull(worker.getInventoryCitizen())) {
            return INVENTORY_FULL;
        }
        IAIState checkResult = checkForItems(currentRecipeStorage);
        if (checkResult == GET_RECIPE) {
            currentRecipeStorage = null;
            worker.getCitizenData().setIdleAtJob(true);
            return IDLE;
        }
        if (checkResult != CRAFT) {
            return checkResult;
        }
    }
    return NETHER_LEAVE;
}
Also used : BuildingNetherWorker(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingNetherWorker) BlockState(net.minecraft.block.BlockState) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) BlockPos(net.minecraft.util.math.BlockPos) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 57 with IAIState

use of com.minecolonies.api.entity.ai.statemachine.states.IAIState in project minecolonies by ldtteam.

the class EntityAIWorkShepherd method decideWhatToDo.

@Override
public IAIState decideWhatToDo() {
    final IAIState result = super.decideWhatToDo();
    final List<SheepEntity> animals = new ArrayList<>(searchForAnimals());
    final SheepEntity shearingSheep = animals.stream().filter(sheepie -> !sheepie.isSheared() && !sheepie.isBaby()).findFirst().orElse(null);
    if (getOwnBuilding().getSetting(BuildingShepherd.SHEARING).getValue() && result.equals(START_WORKING) && shearingSheep != null) {
        return SHEPHERD_SHEAR;
    }
    return result;
}
Also used : SheepEntity(net.minecraft.entity.passive.SheepEntity) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) ArrayList(java.util.ArrayList)

Example 58 with IAIState

use of com.minecolonies.api.entity.ai.statemachine.states.IAIState in project minecolonies by ldtteam.

the class EntityAIWorkPlanter method decide.

@Override
protected IAIState decide() {
    final IAIState nextState = super.decide();
    if (nextState != START_WORKING && nextState != IDLE) {
        return nextState;
    }
    final BuildingPlantation plantation = getOwnBuilding();
    final List<BlockPos> list = plantation.getPosForPhase();
    for (final BlockPos pos : list) {
        if (isAtLeastThreeHigh(pos)) {
            this.workPos = pos;
            return PLANTATION_FARM;
        }
    }
    final Item current = plantation.nextPlantPhase();
    final int plantInBuilding = InventoryUtils.getCountFromBuilding(getOwnBuilding(), itemStack -> itemStack.sameItem(new ItemStack(current)));
    final int plantInInv = InventoryUtils.getItemCountInItemHandler((worker.getInventoryCitizen()), itemStack -> itemStack.sameItem(new ItemStack(current)));
    if (plantInBuilding + plantInInv <= 0) {
        requestPlantable(current);
        return START_WORKING;
    }
    if (plantInInv == 0 && plantInBuilding > 0) {
        needsCurrently = new Tuple<>(itemStack -> itemStack.sameItem(new ItemStack(current)), Math.min(plantInBuilding, PLANT_TO_REQUEST));
        return GATHERING_REQUIRED_MATERIALS;
    }
    for (final BlockPos pos : list) {
        if (world.getBlockState(pos.above()).getBlock() instanceof AirBlock) {
            this.workPos = pos;
            return PLANTATION_PLANT;
        }
    }
    return START_WORKING;
}
Also used : BuildingPlantation(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingPlantation) JobPlanter(com.minecolonies.coremod.colony.jobs.JobPlanter) TICKS_20(com.minecolonies.api.util.constant.CitizenConstants.TICKS_20) BuildingPlantation(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingPlantation) Item(net.minecraft.item.Item) AirBlock(net.minecraft.block.AirBlock) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) BlockPos(net.minecraft.util.math.BlockPos) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) Tuple(com.minecolonies.api.util.Tuple) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) BlockUtils(com.ldtteam.structurize.util.BlockUtils) InventoryUtils(com.minecolonies.api.util.InventoryUtils) AbstractEntityAICrafting(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAICrafting) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) ItemEntity(net.minecraft.entity.item.ItemEntity) NotNull(org.jetbrains.annotations.NotNull) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack) Item(net.minecraft.item.Item) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) AirBlock(net.minecraft.block.AirBlock) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 59 with IAIState

use of com.minecolonies.api.entity.ai.statemachine.states.IAIState in project minecolonies by ldtteam.

the class AbstractEntityAIRequestSmelter method checkForItems.

@Override
protected IAIState checkForItems(@NotNull final IRecipeStorage storage) {
    if (storage.getIntermediate() != Blocks.FURNACE) {
        return super.checkForItems(storage);
    }
    final List<ItemStorage> input = storage.getCleanedInput();
    final int countInFurnaces = getExtendedCount(storage.getPrimaryOutput());
    int outputInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, storage.getPrimaryOutput()));
    for (final ItemStorage inputStorage : input) {
        final Predicate<ItemStack> predicate = stack -> !ItemStackUtils.isEmpty(stack) && ItemStackUtils.compareItemStacksIgnoreStackSize(stack, inputStorage.getItemStack());
        int inputInFurnace = getExtendedCount(inputStorage.getItemStack());
        int inputInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), predicate);
        if (countInFurnaces + inputInFurnace + inputInInv + outputInInv < inputStorage.getAmount() * job.getMaxCraftingCount()) {
            if (InventoryUtils.hasItemInProvider(getOwnBuilding(), predicate)) {
                needsCurrently = new Tuple<>(predicate, inputStorage.getAmount() * (job.getMaxCraftingCount() - countInFurnaces - inputInFurnace));
                return GATHERING_REQUIRED_MATERIALS;
            }
        }
        // if we don't have enough at all, cancel
        int countOfInput = inputInInv + InventoryUtils.getCountFromBuilding(getOwnBuilding(), predicate) + countInFurnaces + inputInFurnace + outputInInv;
        if (countOfInput < inputStorage.getAmount() * job.getMaxCraftingCount()) {
            job.finishRequest(false);
            resetValues();
        }
    }
    return CRAFT;
}
Also used : TICKS_20(com.minecolonies.api.util.constant.CitizenConstants.TICKS_20) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) TypeToken(com.google.common.reflect.TypeToken) FurnaceUserModule(com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule) AbstractJobCrafter(com.minecolonies.coremod.colony.jobs.AbstractJobCrafter) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) Tuple(com.minecolonies.api.util.Tuple) ImmutableList(com.google.common.collect.ImmutableList) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) Hand(net.minecraft.util.Hand) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) FUEL_LIST(com.minecolonies.api.util.constant.BuildingConstants.FUEL_LIST) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) Constants(com.minecolonies.api.util.constant.Constants) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) AIEventTarget(com.minecolonies.api.entity.ai.statemachine.AIEventTarget) World(net.minecraft.world.World) Predicate(java.util.function.Predicate) RequestState(com.minecolonies.api.colony.requestsystem.request.RequestState) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) AIBlockingEventType(com.minecolonies.api.entity.ai.statemachine.states.AIBlockingEventType) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BlockPos(net.minecraft.util.math.BlockPos) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) Blocks(net.minecraft.block.Blocks) List(java.util.List) PublicCrafting(com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting) InventoryUtils(com.minecolonies.api.util.InventoryUtils) TileEntity(net.minecraft.tileentity.TileEntity) ItemStorage(com.minecolonies.api.crafting.ItemStorage) WorldUtil(com.minecolonies.api.util.WorldUtil) FurnaceBlock(net.minecraft.block.FurnaceBlock) NotNull(org.jetbrains.annotations.NotNull) ItemStack(net.minecraft.item.ItemStack) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 60 with IAIState

use of com.minecolonies.api.entity.ai.statemachine.states.IAIState in project minecolonies by ldtteam.

the class AbstractEntityAIRequestSmelter method getRecipe.

@Override
protected IAIState getRecipe() {
    final IRequest<? extends PublicCrafting> currentTask = job.getCurrentTask();
    if (currentTask == null) {
        worker.setItemInHand(Hand.MAIN_HAND, ItemStackUtils.EMPTY);
        return START_WORKING;
    }
    job.setMaxCraftingCount(currentTask.getRequest().getCount());
    final BlockPos furnacePosWithUsedFuel = getPositionOfOvenToRetrieveFuelFrom();
    if (furnacePosWithUsedFuel != null) {
        currentRequest = currentTask;
        walkTo = furnacePosWithUsedFuel;
        return RETRIEVING_USED_FUEL_FROM_FURNACE;
    }
    final BlockPos furnacePos = getPositionOfOvenToRetrieveFrom();
    if (furnacePos != null) {
        currentRequest = currentTask;
        walkTo = furnacePos;
        return RETRIEVING_END_PRODUCT_FROM_FURNACE;
    }
    if (currentRecipeStorage != null && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
        for (final BlockPos pos : getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class).getFurnaces()) {
            final TileEntity entity = world.getBlockEntity(pos);
            if (entity instanceof FurnaceTileEntity) {
                final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
                if (furnace.isLit() || !isEmpty(furnace.getItem(RESULT_SLOT)) || !isEmpty(furnace.getItem(SMELTABLE_SLOT))) {
                    if (furnace.isLit()) {
                        setDelay(TICKS_20);
                    }
                    return CRAFT;
                }
            }
        }
    }
    final IAIState newState = super.getRecipe();
    final ItemListModule module = getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(FUEL_LIST));
    // This should only happen in the stonesmelter, but it could potentially happen with multiple fuels.
    if (newState == QUERY_ITEMS && currentRecipeStorage != null && module.isItemInList(new ItemStorage(currentRecipeStorage.getPrimaryOutput()))) {
        job.setCraftCounter(0);
    }
    return newState;
}
Also used : FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) BlockPos(net.minecraft.util.math.BlockPos) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) ItemStorage(com.minecolonies.api.crafting.ItemStorage) FurnaceUserModule(com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule)

Aggregations

IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)74 ItemStack (net.minecraft.item.ItemStack)58 BlockPos (net.minecraft.util.math.BlockPos)52 AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)50 NotNull (org.jetbrains.annotations.NotNull)50 AITarget (com.minecolonies.api.entity.ai.statemachine.AITarget)48 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)48 ItemStorage (com.minecolonies.api.crafting.ItemStorage)42 StandardInteraction (com.minecolonies.coremod.colony.interactionhandling.StandardInteraction)38 Hand (net.minecraft.util.Hand)37 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)34 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)34 InventoryUtils (com.minecolonies.api.util.InventoryUtils)31 TranslationConstants (com.minecolonies.api.util.constant.TranslationConstants)30 TileEntity (net.minecraft.tileentity.TileEntity)28 List (java.util.List)27 TypeToken (com.google.common.reflect.TypeToken)26 StackList (com.minecolonies.api.colony.requestsystem.requestable.StackList)26 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)25 VisibleCitizenStatus (com.minecolonies.api.entity.citizen.VisibleCitizenStatus)25