Search in sources :

Example 31 with StandardInteraction

use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by Minecolonies.

the class EntityAIEatTask method hasFood.

/**
 * Checks if the citizen has food in the inventory and makes a decision based on that.
 *
 * @return the next state to go to.
 */
private boolean hasFood() {
    final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(citizen, stack -> CAN_EAT.test(stack) && canEat(citizen.getCitizenData(), stack));
    if (slot != -1) {
        foodSlot = slot;
        return true;
    }
    final ICitizenData citizenData = citizen.getCitizenData();
    if (InventoryUtils.hasItemInItemHandler(citizen.getInventoryCitizen(), ISCOOKABLE)) {
        citizenData.triggerInteraction(new StandardInteraction(new TranslationTextComponent(RAW_FOOD), ChatPriority.PENDING));
    } else if (InventoryUtils.hasItemInItemHandler(citizen.getInventoryCitizen(), stack -> CAN_EAT.test(stack) && !canEat(citizenData, stack))) {
        if (citizenData.isChild()) {
            citizenData.triggerInteraction(new StandardInteraction(new TranslationTextComponent(BETTER_FOOD_CHILDREN), ChatPriority.BLOCKING));
        } else {
            citizenData.triggerInteraction(new StandardInteraction(new TranslationTextComponent(BETTER_FOOD), ChatPriority.BLOCKING));
        }
    }
    return false;
}
Also used : SittingEntity(com.minecolonies.coremod.entity.SittingEntity) SATURATION(com.minecolonies.api.research.util.ResearchConstants.SATURATION) BuildingCook(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingCook) TickingTransition(com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickingTransition) ICitizenData(com.minecolonies.api.colony.ICitizenData) ItemParticleEffectMessage(com.minecolonies.coremod.network.messages.client.ItemParticleEffectMessage) AdvancementUtils(com.minecolonies.coremod.util.AdvancementUtils) LOW_SATURATION(com.minecolonies.api.util.constant.CitizenConstants.LOW_SATURATION) SEEK_DOCTOR_HEALTH(com.minecolonies.coremod.entity.citizen.citizenhandlers.CitizenDiseaseHandler.SEEK_DOCTOR_HEALTH) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Goal(net.minecraft.entity.ai.goal.Goal) CAN_EAT(com.minecolonies.api.util.ItemStackUtils.CAN_EAT) Hand(net.minecraft.util.Hand) Network(com.minecolonies.coremod.Network) Log(com.minecolonies.api.util.Log) CitizenConstants(com.minecolonies.api.util.constant.CitizenConstants) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) EnumSet(java.util.EnumSet) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) TickRateStateMachine(com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickRateStateMachine) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) SECONDS_A_MINUTE(com.minecolonies.api.util.constant.Constants.SECONDS_A_MINUTE) DesiredActivity(com.minecolonies.api.entity.ai.DesiredActivity) EatingState(com.minecolonies.coremod.entity.ai.minimal.EntityAIEatTask.EatingState) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) net.minecraft.item(net.minecraft.item) BlockPos(net.minecraft.util.math.BlockPos) SoundUtils(com.minecolonies.api.util.SoundUtils) BASIC_VOLUME(com.minecolonies.api.util.constant.GuardConstants.BASIC_VOLUME) SoundEvents(net.minecraft.util.SoundEvents) AdvancementTriggers(com.minecolonies.api.advancements.AdvancementTriggers) ISCOOKABLE(com.minecolonies.api.util.ItemStackUtils.ISCOOKABLE) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) InventoryUtils(com.minecolonies.api.util.InventoryUtils) IColony(com.minecolonies.api.colony.IColony) AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) IState(com.minecolonies.api.entity.ai.statemachine.states.IState) ItemStorage(com.minecolonies.api.crafting.ItemStorage) WorldUtil(com.minecolonies.api.util.WorldUtil) IJob(com.minecolonies.api.colony.jobs.IJob) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) ICitizenData(com.minecolonies.api.colony.ICitizenData) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent)

Example 32 with StandardInteraction

use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by Minecolonies.

the class EntityAIWorkEnchanter method decide.

/**
 * Decide method of the enchanter. Check if everything is alright to work and then decide between gathering and draining and actually enchanting.
 *
 * @return the next state to go to.
 */
protected IAIState decide() {
    worker.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
    if (walkToBuilding()) {
        return DECIDE;
    }
    final IAIState craftState = getNextCraftingState();
    if (craftState != getState() && !WorldUtil.isPastTime(world, 13000)) {
        return craftState;
    }
    if (getPrimarySkillLevel() < building.getBuildingLevel() * MANA_REQ_PER_LEVEL) {
        final BuildingEnchanter enchanterBuilding = building;
        final EnchanterStationsModule module = enchanterBuilding.getFirstModuleOccurance(EnchanterStationsModule.class);
        if (module.getBuildingsToGatherFrom().isEmpty()) {
            if (worker.getCitizenData() != null) {
                worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_WORKERS_TO_DRAIN_SET), ChatPriority.BLOCKING));
            }
            return IDLE;
        }
        final int booksInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), IS_BOOK);
        if (booksInInv <= 0) {
            final int numberOfBooksInBuilding = InventoryUtils.hasBuildingEnoughElseCount(building, IS_BOOK, 1);
            if (numberOfBooksInBuilding > 0) {
                needsCurrently = new Tuple<>(IS_BOOK, 1);
                return GATHERING_REQUIRED_MATERIALS;
            }
            checkIfRequestForItemExistOrCreateAsync(new ItemStack(Items.BOOK, 1));
            return IDLE;
        }
        final BlockPos posToDrainFrom = module.getRandomBuildingToDrainFrom();
        if (posToDrainFrom == null) {
            return IDLE;
        }
        job.setBuildingToDrainFrom(posToDrainFrom);
        return ENCHANTER_DRAIN;
    }
    final int ancientTomesInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), IS_ANCIENT_TOME);
    if (ancientTomesInInv <= 0) {
        final int amountOfAncientTomes = InventoryUtils.hasBuildingEnoughElseCount(building, IS_ANCIENT_TOME, 1);
        if (amountOfAncientTomes > 0) {
            needsCurrently = new Tuple<>(IS_ANCIENT_TOME, 1);
            return GATHERING_REQUIRED_MATERIALS;
        }
        checkIfRequestForItemExistOrCreateAsync(new ItemStack(ModItems.ancientTome, 1), 1, 1, false);
        return IDLE;
    }
    return ENCHANT;
}
Also used : BuildingEnchanter(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingEnchanter) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) EnchanterStationsModule(com.minecolonies.coremod.colony.buildings.modules.EnchanterStationsModule) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 33 with StandardInteraction

use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by Minecolonies.

the class EntityAIWorkFarmer method prepareForFarming.

/**
 * Prepares the farmer for farming. Also requests the tools and checks if the farmer has sufficient fields.
 *
 * @return the next IAIState
 */
@NotNull
private IAIState prepareForFarming() {
    if (building == null || building.getBuildingLevel() < 1) {
        return PREPARING;
    }
    if (!job.getTaskQueue().isEmpty() || getActionsDoneUntilDumping() <= job.getActionsDone()) {
        return START_WORKING;
    }
    worker.getCitizenData().setVisibleStatus(VisibleCitizenStatus.WORKING);
    final FarmerFieldModule module = building.getFirstModuleOccurance(FarmerFieldModule.class);
    module.syncWithColony(world);
    if (module.getFarmerFields().size() < building.getBuildingLevel() && !module.assignManually()) {
        searchAndAddFields();
    }
    if (module.getFarmerFields().size() == building.getMaxBuildingLevel()) {
        AdvancementUtils.TriggerAdvancementPlayersForColony(building.getColony(), AdvancementTriggers.MAX_FIELDS::trigger);
    }
    final int amountOfCompostInBuilding = InventoryUtils.hasBuildingEnoughElseCount(building, this::isCompost, 1);
    final int amountOfCompostInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), this::isCompost);
    if (amountOfCompostInBuilding + amountOfCompostInInv <= 0) {
        if (building.requestFertilizer() && !building.hasWorkerOpenRequestsOfType(worker.getCitizenData().getId(), TypeToken.of(StackList.class))) {
            final List<ItemStack> compostAbleItems = new ArrayList<>();
            compostAbleItems.add(new ItemStack(ModItems.compost, 1));
            compostAbleItems.add(new ItemStack(Items.BONE_MEAL, 1));
            worker.getCitizenData().createRequestAsync(new StackList(compostAbleItems, RequestSystemTranslationConstants.REQUEST_TYPE_FERTILIZER, STACKSIZE, 1));
        }
    } else if (amountOfCompostInInv <= 0 && amountOfCompostInBuilding > 0) {
        needsCurrently = new Tuple<>(this::isCompost, STACKSIZE);
        return GATHERING_REQUIRED_MATERIALS;
    }
    if (module.hasNoFields()) {
        if (worker.getCitizenData() != null) {
            worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_FREE_FIELDS), ChatPriority.BLOCKING));
        }
        worker.getCitizenData().setIdleAtJob(true);
        return PREPARING;
    }
    worker.getCitizenData().setIdleAtJob(false);
    // If the farmer has no currentField and there is no field which needs work, check fields.
    if (module.getCurrentField() == null && module.getFieldToWorkOn(world) == null) {
        module.resetFields();
        return IDLE;
    }
    @Nullable final BlockPos currentField = module.getCurrentField();
    final TileEntity entity = world.getBlockEntity(currentField);
    if (entity instanceof ScarecrowTileEntity && ((ScarecrowTileEntity) entity).needsWork()) {
        if (((ScarecrowTileEntity) entity).getFieldStage() == ScarecrowFieldStage.PLANTED && checkIfShouldExecute((ScarecrowTileEntity) entity, pos -> this.findHarvestableSurface(pos) != null)) {
            return FARMER_HARVEST;
        } else if (((ScarecrowTileEntity) entity).getFieldStage() == ScarecrowFieldStage.HOED) {
            return canGoPlanting((ScarecrowTileEntity) entity, building);
        } else if (((ScarecrowTileEntity) entity).getFieldStage() == ScarecrowFieldStage.EMPTY && checkIfShouldExecute((ScarecrowTileEntity) entity, pos -> this.findHoeableSurface(pos, (ScarecrowTileEntity) entity) != null)) {
            return FARMER_HOE;
        }
        ((ScarecrowTileEntity) entity).nextState();
    } else {
        module.setCurrentField(null);
    }
    return PREPARING;
}
Also used : Tags(net.minecraftforge.common.Tags) ServerWorld(net.minecraft.world.server.ServerWorld) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) Item(net.minecraft.item.Item) FarmerFieldModule(com.minecolonies.coremod.colony.buildings.modules.FarmerFieldModule) Compatibility(com.minecolonies.api.compatibility.Compatibility) AdvancementUtils(com.minecolonies.coremod.util.AdvancementUtils) Direction(net.minecraft.util.Direction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) PacketDistributor(net.minecraftforge.fml.network.PacketDistributor) Tuple(com.minecolonies.api.util.Tuple) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) ModItems(com.minecolonies.api.items.ModItems) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) Network(com.minecolonies.coremod.Network) NonNullList(net.minecraft.util.NonNullList) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) Constants(com.minecolonies.api.util.constant.Constants) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) STACKSIZE(com.minecolonies.api.util.constant.Constants.STACKSIZE) TOOL_LEVEL_WOOD_OR_GOLD(com.minecolonies.api.util.constant.ToolLevelConstants.TOOL_LEVEL_WOOD_OR_GOLD) JobFarmer(com.minecolonies.coremod.colony.jobs.JobFarmer) Predicate(java.util.function.Predicate) LootParameters(net.minecraft.loot.LootParameters) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) CompostParticleMessage(com.minecolonies.coremod.network.messages.client.CompostParticleMessage) Nullable(org.jetbrains.annotations.Nullable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) List(java.util.List) BlockItem(net.minecraft.item.BlockItem) BlockScarecrow(com.minecolonies.coremod.blocks.BlockScarecrow) NotNull(org.jetbrains.annotations.NotNull) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) BLOCK_BREAK_SOUND_RANGE(com.minecolonies.api.util.constant.CitizenConstants.BLOCK_BREAK_SOUND_RANGE) BuildingFarmer(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingFarmer) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) TypeToken(com.google.common.reflect.TypeToken) PosBasedInteraction(com.minecolonies.coremod.colony.interactionhandling.PosBasedInteraction) ArrayList(java.util.ArrayList) ScarecrowFieldStage(com.minecolonies.api.tileentities.ScarecrowFieldStage) ItemStack(net.minecraft.item.ItemStack) LootContext(net.minecraft.loot.LootContext) RequestSystemTranslationConstants(com.minecolonies.api.util.constant.translation.RequestSystemTranslationConstants) net.minecraft.block(net.minecraft.block) AbstractEntityAICrafting(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAICrafting) Hand(net.minecraft.util.Hand) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) AbstractScarecrowTileEntity(com.minecolonies.api.tileentities.AbstractScarecrowTileEntity) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) FARMING(com.minecolonies.api.research.util.ResearchConstants.FARMING) AdvancementTriggers(com.minecolonies.api.advancements.AdvancementTriggers) InventoryUtils(com.minecolonies.api.util.InventoryUtils) ResourceLocation(net.minecraft.util.ResourceLocation) IColony(com.minecolonies.api.colony.IColony) TileEntity(net.minecraft.tileentity.TileEntity) ToolType(com.minecolonies.api.util.constant.ToolType) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) ArrayList(java.util.ArrayList) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) FarmerFieldModule(com.minecolonies.coremod.colony.buildings.modules.FarmerFieldModule) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) AbstractScarecrowTileEntity(com.minecolonies.api.tileentities.AbstractScarecrowTileEntity) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) AbstractScarecrowTileEntity(com.minecolonies.api.tileentities.AbstractScarecrowTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Tuple(com.minecolonies.api.util.Tuple) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 34 with StandardInteraction

use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by Minecolonies.

the class EntityAIWorkFlorist method compost.

/**
 * Walk to the block to compost and apply compost to it.
 *
 * @return the next state to go to.
 */
private IAIState compost() {
    if (compostPosition == null) {
        return START_WORKING;
    }
    worker.getCitizenData().setVisibleStatus(GARDENING);
    if (walkToBlock(compostPosition)) {
        return getState();
    }
    final TileEntity entity = world.getBlockEntity(compostPosition);
    if (entity instanceof TileEntityCompostedDirt) {
        @Nullable final ItemStack stack = building.getFlowerToGrow();
        if (stack != null) {
            if (worker.getRandom().nextInt(200 - getPrimarySkillLevel()) < 0 || InventoryUtils.shrinkItemCountInItemHandler(worker.getInventoryCitizen(), IS_COMPOST)) {
                ((TileEntityCompostedDirt) entity).compost(PERCENT_CHANGE_FOR_GROWTH - (building.getBuildingLevel() * 0.01), building.getFlowerToGrow());
            }
        } else {
            worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_FLOWERS_IN_CONFIG), ChatPriority.BLOCKING));
        }
    }
    incrementActionsDone();
    worker.decreaseSaturationForContinuousAction();
    compostPosition = null;
    return START_WORKING;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) TileEntityCompostedDirt(com.minecolonies.coremod.tileentities.TileEntityCompostedDirt) ItemStack(net.minecraft.item.ItemStack) Nullable(org.jetbrains.annotations.Nullable)

Example 35 with StandardInteraction

use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by Minecolonies.

the class EntityAIWorkFlorist method decide.

/**
 * Main decision method of florist to decide what to do.
 *
 * @return the next AI state to go to.
 */
private IAIState decide() {
    worker.getCitizenData().setVisibleStatus(VisibleCitizenStatus.WORKING);
    if (building.getPlantGround().isEmpty()) {
        worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_PLANT_GROUND_FLORIST), ChatPriority.BLOCKING));
        return IDLE;
    }
    worker.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
    final long distance = BlockPosUtil.getDistance2D(worker.blockPosition(), building.getPosition());
    if (distance > MAX_DISTANCE && walkToBuilding()) {
        return DECIDE;
    }
    final int amountOfCompostInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), IS_COMPOST);
    if (amountOfCompostInInv <= 0) {
        final int amountOfCompostInBuilding = InventoryUtils.hasBuildingEnoughElseCount(building, IS_COMPOST, 1);
        if (amountOfCompostInBuilding > 0) {
            needsCurrently = new Tuple<>(IS_COMPOST, STACKSIZE);
            return GATHERING_REQUIRED_MATERIALS;
        } else {
            checkIfRequestForItemExistOrCreateAsync(new ItemStack(ModItems.compost, COMPOST_REQUEST_QTY));
        }
    }
    harvestPosition = areThereFlowersToGather();
    if (harvestPosition != null) {
        return FLORIST_HARVEST;
    }
    if (amountOfCompostInInv <= 0) {
        if (!isThereCompostedLand(building, world)) {
            worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_COMPOST), ChatPriority.BLOCKING));
            return START_WORKING;
        }
        return DECIDE;
    } else {
        compostPosition = getFirstNotCompostedLand();
        return FLORIST_COMPOST;
    }
}
Also used : StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack)

Aggregations

StandardInteraction (com.minecolonies.coremod.colony.interactionhandling.StandardInteraction)54 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)53 BlockPos (net.minecraft.util.math.BlockPos)26 ItemStack (net.minecraft.item.ItemStack)25 NotNull (org.jetbrains.annotations.NotNull)21 IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)19 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)17 ItemStorage (com.minecolonies.api.crafting.ItemStorage)15 AITarget (com.minecolonies.api.entity.ai.statemachine.AITarget)15 AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)15 InventoryUtils (com.minecolonies.api.util.InventoryUtils)12 TypeToken (com.google.common.reflect.TypeToken)11 StackList (com.minecolonies.api.colony.requestsystem.requestable.StackList)11 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)11 TranslationConstants (com.minecolonies.api.util.constant.TranslationConstants)11 Network (com.minecolonies.coremod.Network)11 Hand (net.minecraft.util.Hand)11 ICitizenData (com.minecolonies.api.colony.ICitizenData)10 ItemListModule (com.minecolonies.coremod.colony.buildings.modules.ItemListModule)10 TileEntity (net.minecraft.tileentity.TileEntity)9