Search in sources :

Example 26 with StandardInteraction

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

the class EntityAIQuarrier method checkIfCanceled.

@Override
protected boolean checkIfCanceled() {
    if (job.findQuarry() == null) {
        worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(QUARRY_MINER_NO_QUARRY), ChatPriority.BLOCKING));
        return true;
    } else if (job.findQuarry().getFirstModuleOccurance(QuarryModule.class).isFinished()) {
        worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(QUARRY_MINER_FINISHED_QUARRY), ChatPriority.BLOCKING));
        return true;
    } else if (job.getWorkOrder() != null && !job.getWorkOrder().getLocation().equals(job.findQuarry().getPosition().below(2))) {
        blockToMine = null;
        job.complete();
        building.setProgressPos(null, null);
        return true;
    }
    return super.checkIfCanceled();
}
Also used : StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent)

Example 27 with StandardInteraction

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

the class EntityAIQuarrier method startWorkingAtOwnBuilding.

// Miner wants to work but is not at building
@NotNull
private IAIState startWorkingAtOwnBuilding() {
    worker.getCitizenData().setVisibleStatus(VisibleCitizenStatus.WORKING);
    final IBuilding quarry = job.findQuarry();
    if (quarry == null) {
        walkToBuilding();
        worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(QUARRY_MINER_NO_QUARRY), ChatPriority.BLOCKING));
        return IDLE;
    }
    if (quarry.getFirstModuleOccurance(QuarryModule.class).isFinished()) {
        walkToBuilding();
        worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(QUARRY_MINER_FINISHED_QUARRY), ChatPriority.BLOCKING));
        return IDLE;
    }
    if (walkToBlock(quarry.getPosition())) {
        return getState();
    }
    // Miner is at building
    return LOAD_STRUCTURE;
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) QuarryModule(com.minecolonies.coremod.colony.buildings.modules.QuarryModule) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with StandardInteraction

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

the class EntityAIEatTask method searchRestaurant.

/**
 * Search for a placeToPath within the colony of the citizen.
 *
 * @return the next state to go to.
 */
private EatingState searchRestaurant() {
    final ICitizenData citizenData = citizen.getCitizenData();
    final IColony colony = citizenData.getColony();
    if (citizenData.getWorkBuilding() != null) {
        restaurantPos = colony.getBuildingManager().getBestBuilding(citizenData.getWorkBuilding().getPosition(), BuildingCook.class);
    } else if (citizenData.getHomeBuilding() != null) {
        restaurantPos = colony.getBuildingManager().getBestBuilding(citizenData.getHomeBuilding().getPosition(), BuildingCook.class);
    } else {
        restaurantPos = colony.getBuildingManager().getBestBuilding(citizen, BuildingCook.class);
    }
    final IJob<?> job = citizen.getCitizenJobHandler().getColonyJob();
    if (job != null && citizenData.isWorking()) {
        citizenData.setWorking(false);
    }
    if (restaurantPos == null) {
        citizenData.triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_RESTAURANT), ChatPriority.BLOCKING));
        return CHECK_FOR_FOOD;
    }
    return GO_TO_RESTAURANT;
}
Also used : StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) ICitizenData(com.minecolonies.api.colony.ICitizenData) IColony(com.minecolonies.api.colony.IColony) BuildingCook(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingCook) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent)

Example 29 with StandardInteraction

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

the class EntityAIWorkCook method getSmeltAbleClass.

@Override
protected IRequestable getSmeltAbleClass() {
    final List<ItemStorage> blockedItems = new ArrayList<>(building.getModuleMatching(ItemListModule.class, m -> m.getId().equals(FOOD_EXCLUSION_LIST)).getList());
    for (final Map.Entry<ItemStorage, Integer> content : building.getTileEntity().getAllContent().entrySet()) {
        if (content.getValue() > content.getKey().getItemStack().getMaxStackSize() * 6 && ItemStackUtils.CAN_EAT.test(content.getKey().getItemStack())) {
            blockedItems.add(content.getKey());
        }
    }
    blockedItems.removeIf(item -> item.getItem().getFoodProperties() == null || item.getItem().getFoodProperties().getNutrition() < building.getBuildingLevel() - 1);
    if (!blockedItems.isEmpty()) {
        if (IColonyManager.getInstance().getCompatibilityManager().getEdibles(building.getBuildingLevel() - 1).size() <= blockedItems.size()) {
            if (worker.getCitizenData() != null) {
                worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(FURNACE_USER_NO_FOOD), ChatPriority.BLOCKING));
                return null;
            }
        }
        return new Food(STACKSIZE, blockedItems, building.getBuildingLevel() - 1);
    }
    return new Food(STACKSIZE, building.getBuildingLevel() - 1);
}
Also used : StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStorage(com.minecolonies.api.crafting.ItemStorage) Food(com.minecolonies.api.colony.requestsystem.requestable.Food)

Example 30 with StandardInteraction

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

the class EntityCitizen method determineDesiredActivity.

/**
 * Determines the desired activity
 */
private boolean determineDesiredActivity() {
    if (citizenJobHandler.getColonyJob() instanceof AbstractJobGuard) {
        desiredActivity = DesiredActivity.WORK;
        return false;
    }
    if (getCitizenColonyHandler().getColony().getRaiderManager().isRaided()) {
        citizenData.triggerInteraction(new StandardInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_RAID), ChatPriority.IMPORTANT));
        setVisibleStatusIfNone(RAIDED);
        desiredActivity = DesiredActivity.SLEEP;
        return false;
    }
    // Sleeping
    if (!WorldUtil.isPastTime(CompatibilityUtils.getWorldFromCitizen(this), NIGHT - 2000)) {
        if (desiredActivity == DesiredActivity.SLEEP) {
            setVisibleStatusIfNone(SLEEP);
            return false;
        }
        if (citizenSleepHandler.shouldGoSleep()) {
            citizenData.onGoSleep();
            citizenData.decreaseSaturation(citizenColonyHandler.getPerBuildingFoodCost() * 2);
            citizenData.markDirty();
            citizenStatusHandler.setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.sleeping"));
            desiredActivity = DesiredActivity.SLEEP;
            return false;
        }
    }
    // Mourning
    if (citizenData.getCitizenMournHandler().isMourning() && citizenData.getCitizenMournHandler().shouldMourn()) {
        if (!getCitizenColonyHandler().getColony().getRaiderManager().isRaided()) {
            citizenData.triggerInteraction(new StandardInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_MOURNING, citizenData.getCitizenMournHandler().getDeceasedCitizens().iterator().next()), new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_MOURNING), ChatPriority.IMPORTANT));
        }
        setVisibleStatusIfNone(MOURNING);
        desiredActivity = DesiredActivity.MOURN;
        return false;
    }
    if (citizenSleepHandler.isAsleep() && !citizenDiseaseHandler.isSick()) {
        citizenSleepHandler.onWakeUp();
    }
    // Raining
    if (CompatibilityUtils.getWorldFromCitizen(this).isRaining() && !shouldWorkWhileRaining() && !WorldUtil.isNetherType(level)) {
        citizenStatusHandler.setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.waiting"), new TranslationTextComponent("com.minecolonies.coremod.status.rainStop"));
        setVisibleStatusIfNone(BAD_WEATHER);
        if (!citizenData.getColony().getRaiderManager().isRaided() && !citizenData.getCitizenMournHandler().isMourning()) {
            citizenData.triggerInteraction(new StandardInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_RAINING), ChatPriority.HIDDEN));
        }
        desiredActivity = DesiredActivity.SLEEP;
        return false;
    }
    if (isBaby() && getCitizenJobHandler().getColonyJob() instanceof JobPupil && level.getDayTime() % 24000 > NOON) {
        setVisibleStatusIfNone(HOUSE);
        desiredActivity = DesiredActivity.IDLE;
        return false;
    }
    if (getCitizenJobHandler().getColonyJob() != null) {
        desiredActivity = DesiredActivity.WORK;
        return false;
    }
    setVisibleStatusIfNone(HOUSE);
    desiredActivity = DesiredActivity.IDLE;
    return false;
}
Also used : StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction)

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