Search in sources :

Example 11 with IAIState

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

the class EntityAIConcreteMixer method mixConcrete.

/**
 * Mix the concrete and mine it.
 *
 * @return next state.
 */
private IAIState mixConcrete() {
    int slot = -1;
    if (currentRequest != null && currentRecipeStorage != null) {
        ItemStack inputStack = currentRecipeStorage.getCleanedInput().get(0).getItemStack();
        if (CONCRETE.test(inputStack)) {
            slot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), s -> ItemStackUtils.compareItemStacksIgnoreStackSize(s, inputStack));
        } else {
            return START_WORKING;
        }
    } else {
        slot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), CONCRETE);
    }
    if (slot != -1) {
        final ItemStack stack = worker.getInventoryCitizen().getStackInSlot(slot);
        final Block block = ((BlockItem) stack.getItem()).getBlock();
        final BlockPos posToPlace = getOwnBuilding().getBlockToPlace();
        if (posToPlace != null) {
            if (walkToBlock(posToPlace)) {
                walkTo = posToPlace;
                return START_WORKING;
            }
            walkTo = null;
            if (InventoryUtils.attemptReduceStackInItemHandler(worker.getInventoryCitizen(), stack, 1)) {
                world.setBlock(posToPlace, block.defaultBlockState().updateShape(Direction.DOWN, block.defaultBlockState(), world, posToPlace, posToPlace), 0x03);
            }
            return START_WORKING;
        }
    }
    final BlockPos pos = getOwnBuilding().getBlockToMine();
    if (pos != null) {
        if (walkToBlock(pos)) {
            walkTo = pos;
            return START_WORKING;
        }
        walkTo = null;
        if (mineBlock(pos)) {
            this.resetActionsDone();
            return CRAFT;
        }
        return START_WORKING;
    }
    if (InventoryUtils.hasItemInItemHandler(getOwnBuilding().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElseGet(null), CONCRETE)) {
        needsCurrently = new Tuple<>(CONCRETE, STACKSIZE);
        return GATHERING_REQUIRED_MATERIALS;
    } else {
        incrementActionsDone();
    }
    return START_WORKING;
}
Also used : ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) STACKSIZE(com.minecolonies.api.util.constant.Constants.STACKSIZE) Predicate(java.util.function.Predicate) RequestState(com.minecolonies.api.colony.requestsystem.request.RequestState) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) ItemStack(net.minecraft.item.ItemStack) Tuple(com.minecolonies.api.util.Tuple) JobConcreteMixer(com.minecolonies.coremod.colony.jobs.JobConcreteMixer) Block(net.minecraft.block.Block) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) BlockItem(net.minecraft.item.BlockItem) InventoryUtils(com.minecolonies.api.util.InventoryUtils) ConcretePowderBlock(net.minecraft.block.ConcretePowderBlock) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) AbstractEntityAICrafting(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAICrafting) BuildingConcreteMixer(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingConcreteMixer) NotNull(org.jetbrains.annotations.NotNull) Block(net.minecraft.block.Block) ConcretePowderBlock(net.minecraft.block.ConcretePowderBlock) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) BlockItem(net.minecraft.item.BlockItem)

Example 12 with IAIState

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

the class AbstractEntityAIUsesFurnace method startWorking.

/**
 * Central method of the furnace user, he decides about what to do next from here. First check if any of the workers has important tasks to handle first. If not check if there
 * is an oven with an item which has to be retrieved. If not check if fuel and smeltable are available and request if necessary and get into inventory. Then check if able to
 * smelt already.
 *
 * @return the next state to go to.
 */
public IAIState startWorking() {
    if (walkToBuilding()) {
        return getState();
    }
    final FurnaceUserModule furnaceModule = getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class);
    final ItemListModule itemListModule = getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(FUEL_LIST));
    worker.getCitizenData().setVisibleStatus(VisibleCitizenStatus.WORKING);
    if (itemListModule.getList().isEmpty()) {
        if (worker.getCitizenData() != null) {
            worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(FURNACE_USER_NO_FUEL), ChatPriority.BLOCKING));
        }
        return getState();
    }
    if (furnaceModule.getFurnaces().isEmpty()) {
        if (worker.getCitizenData() != null) {
            worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(BAKER_HAS_NO_FURNACES_MESSAGE), ChatPriority.BLOCKING));
        }
        return getState();
    }
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_DECIDING));
    final IAIState nextState = checkForImportantJobs();
    if (nextState != START_WORKING) {
        return nextState;
    }
    final BlockPos posOfUsedFuelOven = getPositionOfOvenToRetrieveFuelFrom();
    if (posOfUsedFuelOven != null) {
        walkTo = posOfUsedFuelOven;
        worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.retrieving"));
        return RETRIEVING_USED_FUEL_FROM_FURNACE;
    }
    final BlockPos posOfOven = getPositionOfOvenToRetrieveFrom();
    if (posOfOven != null) {
        walkTo = posOfOven;
        worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.retrieving"));
        return RETRIEVING_END_PRODUCT_FROM_FURNACE;
    }
    final int amountOfSmeltableInBuilding = InventoryUtils.getCountFromBuilding(getOwnBuilding(), this::isSmeltable);
    final int amountOfSmeltableInInv = InventoryUtils.getItemCountInItemHandler((worker.getInventoryCitizen()), this::isSmeltable);
    final int amountOfFuelInBuilding = InventoryUtils.getCountFromBuilding(getOwnBuilding(), itemListModule.getList());
    final int amountOfFuelInInv = InventoryUtils.getItemCountInItemHandler((worker.getInventoryCitizen()), stack -> itemListModule.isItemInList(new ItemStorage(stack)));
    if (amountOfSmeltableInBuilding + amountOfSmeltableInInv <= 0 && !reachedMaxToKeep()) {
        requestSmeltable();
    }
    if (amountOfFuelInBuilding + amountOfFuelInInv <= 0 && !getOwnBuilding().hasWorkerOpenRequestsFiltered(worker.getCitizenData().getId(), req -> req.getShortDisplayString().getSiblings().contains(new TranslationTextComponent(COM_MINECOLONIES_REQUESTS_BURNABLE)))) {
        worker.getCitizenData().createRequestAsync(new StackList(getAllowedFuel(), COM_MINECOLONIES_REQUESTS_BURNABLE, STACKSIZE * furnaceModule.getFurnaces().size(), 1));
    }
    if (amountOfSmeltableInBuilding > 0 && amountOfSmeltableInInv == 0) {
        needsCurrently = new Tuple<>(this::isSmeltable, STACKSIZE);
        return GATHERING_REQUIRED_MATERIALS;
    } else if (amountOfFuelInBuilding > 0 && amountOfFuelInInv == 0) {
        needsCurrently = new Tuple<>(stack -> itemListModule.isItemInList(new ItemStorage(stack)), STACKSIZE);
        return GATHERING_REQUIRED_MATERIALS;
    }
    return checkIfAbleToSmelt(amountOfFuelInBuilding + amountOfFuelInInv, amountOfSmeltableInBuilding + amountOfSmeltableInInv);
}
Also used : ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) ItemStorage(com.minecolonies.api.crafting.ItemStorage) Tuple(com.minecolonies.api.util.Tuple) FurnaceUserModule(com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule)

Example 13 with IAIState

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

the class EntityAIWorkBeekeeper method decideWhatToDo.

/**
 * Decides what job the beekeeper should switch to, breeding or harvesting.
 *
 * @return The next {@link IAIState} the beekeeper should switch to, after executing this method.
 */
private IAIState decideWhatToDo() {
    setDelay(DECIDING_DELAY + (99 / getSecondarySkillLevel() - 1));
    final Set<BlockPos> hives = getOwnBuilding().getHives();
    if (hives.isEmpty()) {
        worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_HIVES), ChatPriority.BLOCKING));
        setDelay(NO_HIVES_DELAY);
        return DECIDE;
    }
    ItemListModule flowersModule = getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(BUILDING_FLOWER_LIST));
    if (flowersModule.getList().isEmpty()) {
        worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_BEEKEEPER_NOFLOWERS), ChatPriority.BLOCKING));
        setDelay(NO_FLOWERS_DELAY);
        return DECIDE;
    }
    for (BlockPos pos : hives) {
        if (!(world.getBlockState(pos).getBlock() instanceof BeehiveBlock)) {
            getOwnBuilding().removeHive(pos);
        }
    }
    final Optional<BlockPos> hive = getOwnBuilding().getHives().stream().filter(pos -> BeehiveTileEntity.getHoneyLevel(world.getBlockState(pos)) >= 5).findFirst();
    if (hive.isPresent()) {
        return BEEKEEPER_HARVEST;
    }
    final List<BeeEntity> bees = new ArrayList<>(searchForAnimals(world, getOwnBuilding()));
    final JobBeekeeper job = worker.getCitizenJobHandler().getColonyJob(JobBeekeeper.class);
    if (bees.isEmpty()) {
        if (getBeesInHives() <= 0) {
            job.tickNoBees();
            if (job.checkForBeeInteraction()) {
                worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_BEES), ChatPriority.BLOCKING));
            }
        } else {
            job.resetCounter();
        }
        setDelay(NO_ANIMALS_DELAY);
        return DECIDE;
    } else {
        job.resetCounter();
    }
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(TranslationConstants.COM_MINECOLONIES_COREMOD_STATUS_DECIDING));
    final int breedableAnimals = (int) bees.stream().filter(animal -> animal.getAge() == 0).count();
    final boolean hasBreedingItem = InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), (stack) -> flowersModule.isItemInList(new ItemStorage(stack)));
    if (getOwnBuilding().getSetting(BuildingBeekeeper.BREEDING).getValue() && !hasMaxAnimals(bees) && breedableAnimals >= NUM_OF_ANIMALS_TO_BREED && hasBreedingItem) {
        return HERDER_BREED;
    }
    return START_WORKING;
}
Also used : ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) BeeEntity(net.minecraft.entity.passive.BeeEntity) BeehiveBlock(net.minecraft.block.BeehiveBlock) java.util(java.util) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) Item(net.minecraft.item.Item) BuildingBeekeeper(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBeekeeper) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Compatibility(com.minecolonies.api.compatibility.Compatibility) BUILDING_FLOWER_LIST(com.minecolonies.api.util.constant.BuildingConstants.BUILDING_FLOWER_LIST) TypeToken(com.google.common.reflect.TypeToken) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) BlockTags(net.minecraft.tags.BlockTags) BeehiveTileEntity(net.minecraft.tileentity.BeehiveTileEntity) JobBeekeeper(com.minecolonies.coremod.colony.jobs.JobBeekeeper) Hand(net.minecraft.util.Hand) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) AbstractEntityAIInteract(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIInteract) Entity(net.minecraft.entity.Entity) ItemTags(net.minecraft.tags.ItemTags) TOOL_LEVEL_WOOD_OR_GOLD(com.minecolonies.api.util.constant.ToolLevelConstants.TOOL_LEVEL_WOOD_OR_GOLD) World(net.minecraft.world.World) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) Collectors(java.util.stream.Collectors) InventoryUtils(com.minecolonies.api.util.InventoryUtils) ToolType(com.minecolonies.api.util.constant.ToolType) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) BlockStateProperties(net.minecraft.state.properties.BlockStateProperties) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BeehiveBlock(net.minecraft.block.BeehiveBlock) ItemStorage(com.minecolonies.api.crafting.ItemStorage) JobBeekeeper(com.minecolonies.coremod.colony.jobs.JobBeekeeper) BeeEntity(net.minecraft.entity.passive.BeeEntity) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos)

Example 14 with IAIState

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

the class EntityAIWorkBeekeeper method prepareForHerding.

/**
 * Prepares the beekeeper for herding
 *
 * @return The next {@link IAIState}.
 */
private IAIState prepareForHerding() {
    setDelay(DECIDING_DELAY);
    if (!getOwnBuilding().getHarvestTypes().equals(BuildingBeekeeper.HONEY)) {
        if (checkForToolOrWeapon(ToolType.SHEARS)) {
            return getState();
        }
    }
    if (!getOwnBuilding().getHarvestTypes().equals(BuildingBeekeeper.HONEYCOMB)) {
        checkIfRequestForItemExistOrCreateAsynch(new ItemStack(Items.GLASS_BOTTLE));
    }
    List<ItemStorage> allowedFlowers = getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(BUILDING_FLOWER_LIST)).getList();
    ;
    if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), (stack) -> allowedFlowers.contains(new ItemStorage(stack))) && InventoryUtils.getCountFromBuilding(getOwnBuilding(), allowedFlowers) == 0 && !getOwnBuilding().hasWorkerOpenRequestsOfType(worker.getCitizenData().getId(), TypeToken.of(StackList.class))) {
        worker.getCitizenData().createRequestAsync(new StackList(allowedFlowers.stream().map((item) -> item.getItemStack()).peek((stack) -> stack.setCount(16)).collect(Collectors.toList()), COM_MINECOLONIES_COREMOD_REQUEST_FLOWERS, 16, 1));
    }
    return DECIDE;
}
Also used : ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) BeeEntity(net.minecraft.entity.passive.BeeEntity) BeehiveBlock(net.minecraft.block.BeehiveBlock) java.util(java.util) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) Item(net.minecraft.item.Item) BuildingBeekeeper(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBeekeeper) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Compatibility(com.minecolonies.api.compatibility.Compatibility) BUILDING_FLOWER_LIST(com.minecolonies.api.util.constant.BuildingConstants.BUILDING_FLOWER_LIST) TypeToken(com.google.common.reflect.TypeToken) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) BlockTags(net.minecraft.tags.BlockTags) BeehiveTileEntity(net.minecraft.tileentity.BeehiveTileEntity) JobBeekeeper(com.minecolonies.coremod.colony.jobs.JobBeekeeper) Hand(net.minecraft.util.Hand) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) AbstractEntityAIInteract(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIInteract) Entity(net.minecraft.entity.Entity) ItemTags(net.minecraft.tags.ItemTags) TOOL_LEVEL_WOOD_OR_GOLD(com.minecolonies.api.util.constant.ToolLevelConstants.TOOL_LEVEL_WOOD_OR_GOLD) World(net.minecraft.world.World) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) Collectors(java.util.stream.Collectors) InventoryUtils(com.minecolonies.api.util.InventoryUtils) ToolType(com.minecolonies.api.util.constant.ToolType) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) BlockStateProperties(net.minecraft.state.properties.BlockStateProperties) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) ItemStack(net.minecraft.item.ItemStack) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 15 with IAIState

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

the class EntityAIWorkCowboy method decideWhatToDo.

@Override
public IAIState decideWhatToDo() {
    final IAIState result = super.decideWhatToDo();
    final BuildingCowboy building = getOwnBuilding();
    final boolean hasBucket = InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), Items.BUCKET);
    if (building != null && getOwnBuilding().getSetting(BuildingCowboy.MILKING).getValue() && result.equals(START_WORKING) && hasBucket) {
        return COWBOY_MILK;
    }
    return result;
}
Also used : BuildingCowboy(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingCowboy) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState)

Aggregations

IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)67 ItemStack (net.minecraft.item.ItemStack)52 BlockPos (net.minecraft.util.math.BlockPos)45 AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)44 NotNull (org.jetbrains.annotations.NotNull)44 AITarget (com.minecolonies.api.entity.ai.statemachine.AITarget)42 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)42 ItemStorage (com.minecolonies.api.crafting.ItemStorage)35 InventoryUtils (com.minecolonies.api.util.InventoryUtils)32 StandardInteraction (com.minecolonies.coremod.colony.interactionhandling.StandardInteraction)32 Hand (net.minecraft.util.Hand)32 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)30 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)28 TranslationConstants (com.minecolonies.api.util.constant.TranslationConstants)24 ItemListModule (com.minecolonies.coremod.colony.buildings.modules.ItemListModule)24 TileEntity (net.minecraft.tileentity.TileEntity)24 Tuple (com.minecolonies.api.util.Tuple)22 List (java.util.List)22 TypeToken (com.google.common.reflect.TypeToken)20 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)20