Search in sources :

Example 1 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().getSchematicLocation().equals(job.findQuarry().getPosition().below(2))) {
        blockToMine = null;
        job.complete();
        getOwnBuilding().setProgressPos(null, null);
        return true;
    }
    return super.checkIfCanceled();
}
Also used : StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent)

Example 2 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 3 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 4 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) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent)

Example 5 with StandardInteraction

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

the class AbstractEntityAIRequestSmelter method craft.

@Override
protected IAIState craft() {
    final FurnaceUserModule module = getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class);
    final List<ItemStack> possibleFuels = getAllowedFuel();
    if (possibleFuels.isEmpty()) {
        if (worker.getCitizenData() != null) {
            worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(FURNACE_USER_NO_FUEL), ChatPriority.BLOCKING));
        }
        return getState();
    }
    if (currentRecipeStorage != null) {
        possibleFuels.removeIf(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, currentRecipeStorage.getPrimaryOutput()));
        // There is always only one input.
        possibleFuels.removeIf(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, currentRecipeStorage.getCleanedInput().get(0).getItemStack()));
    }
    if (walkToBuilding()) {
        setDelay(STANDARD_DELAY);
        return getState();
    }
    if (currentRecipeStorage != null && currentRequest == null) {
        currentRequest = job.getCurrentTask();
    }
    if (currentRecipeStorage != null && currentRecipeStorage.getIntermediate() != Blocks.FURNACE) {
        return super.craft();
    }
    if (module.getFurnaces().isEmpty()) {
        if (worker.getCitizenData() != null) {
            worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(BAKER_HAS_NO_FURNACES_MESSAGE), ChatPriority.BLOCKING));
        }
        setDelay(STANDARD_DELAY);
        return START_WORKING;
    }
    final BlockPos furnacePosWithUsedFuel = getPositionOfOvenToRetrieveFuelFrom();
    if (furnacePosWithUsedFuel != null) {
        walkTo = furnacePosWithUsedFuel;
        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;
    }
    // Safety net, should get caught removing things from the furnace.
    if (currentRequest != null && job.getMaxCraftingCount() > 0 && job.getCraftCounter() >= job.getMaxCraftingCount()) {
        job.finishRequest(true);
        currentRecipeStorage = null;
        currentRequest = null;
        resetValues();
        return INVENTORY_FULL;
    }
    if (currentRequest != null && (currentRequest.getState() == RequestState.CANCELLED || currentRequest.getState() == RequestState.FAILED)) {
        incrementActionsDone(getActionRewardForCraftingSuccess());
        currentRecipeStorage = null;
        currentRequest = null;
        resetValues();
        return START_WORKING;
    }
    return checkIfAbleToSmelt();
}
Also used : StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) FurnaceUserModule(com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule)

Aggregations

StandardInteraction (com.minecolonies.coremod.colony.interactionhandling.StandardInteraction)51 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)51 ItemStack (net.minecraft.item.ItemStack)24 BlockPos (net.minecraft.util.math.BlockPos)24 NotNull (org.jetbrains.annotations.NotNull)20 IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)18 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)16 AITarget (com.minecolonies.api.entity.ai.statemachine.AITarget)14 AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)14 ItemStorage (com.minecolonies.api.crafting.ItemStorage)13 InventoryUtils (com.minecolonies.api.util.InventoryUtils)12 TypeToken (com.google.common.reflect.TypeToken)10 ICitizenData (com.minecolonies.api.colony.ICitizenData)10 StackList (com.minecolonies.api.colony.requestsystem.requestable.StackList)10 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)10 TranslationConstants (com.minecolonies.api.util.constant.TranslationConstants)10 Network (com.minecolonies.coremod.Network)10 ItemListModule (com.minecolonies.coremod.colony.buildings.modules.ItemListModule)10 Hand (net.minecraft.util.Hand)10 IColony (com.minecolonies.api.colony.IColony)8