Search in sources :

Example 36 with StandardInteraction

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

the class EntityAISickTask method searchHospital.

/**
 * Search for a placeToPath within the colony of the citizen.
 *
 * @return the next state to go to.
 */
private DiseaseState searchHospital() {
    final IColony colony = citizenData.getColony();
    placeToPath = colony.getBuildingManager().getBestBuilding(citizen, BuildingHospital.class);
    if (placeToPath == null) {
        final String id = citizen.getCitizenDiseaseHandler().getDisease();
        if (id.isEmpty()) {
            return IDLE;
        }
        final Disease disease = IColonyManager.getInstance().getCompatibilityManager().getDisease(id);
        citizenData.triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_HOSPITAL, disease.getName(), disease.getCureString()), new TranslationTextComponent(NO_HOSPITAL), ChatPriority.BLOCKING));
        return WANDER;
    } else if (!citizen.getCitizenDiseaseHandler().getDisease().isEmpty()) {
        final Disease disease = IColonyManager.getInstance().getCompatibilityManager().getDisease(citizen.getCitizenDiseaseHandler().getDisease());
        citizenData.triggerInteraction(new StandardInteraction(new TranslationTextComponent(WAITING_FOR_CURE, disease.getName(), disease.getCureString()), new TranslationTextComponent(WAITING_FOR_CURE), ChatPriority.BLOCKING));
    }
    return GO_TO_HOSPITAL;
}
Also used : BuildingHospital(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingHospital) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) IColony(com.minecolonies.api.colony.IColony) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent)

Example 37 with StandardInteraction

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

the class EntityAIWorkHealer method decide.

/**
 * Decide what to do next. Check if all patients are up date, else update their states. Then check if there is any patient we can cure or request things for.
 *
 * @return the next state to go to.
 */
private IAIState decide() {
    if (walkToBuilding()) {
        return DECIDE;
    }
    final BuildingHospital hospital = building;
    for (final AbstractEntityCitizen citizen : WorldUtil.getEntitiesWithinBuilding(world, AbstractEntityCitizen.class, building, cit -> cit.getCitizenDiseaseHandler().isSick())) {
        hospital.checkOrCreatePatientFile(citizen.getCivilianID());
    }
    for (final Patient patient : hospital.getPatients()) {
        final ICitizenData data = hospital.getColony().getCitizenManager().getCivilian(patient.getId());
        if (data == null || !data.getEntity().isPresent() || (data.getEntity().isPresent() && !data.getEntity().get().getCitizenDiseaseHandler().isSick())) {
            hospital.removePatientFile(patient);
            continue;
        }
        final EntityCitizen citizen = (EntityCitizen) data.getEntity().get();
        final String diseaseName = citizen.getCitizenDiseaseHandler().getDisease();
        @Nullable final Disease disease = diseaseName.isEmpty() ? null : IColonyManager.getInstance().getCompatibilityManager().getDisease(diseaseName);
        if (patient.getState() == Patient.PatientState.NEW) {
            this.currentPatient = patient;
            return REQUEST_CURE;
        }
        if (patient.getState() == Patient.PatientState.REQUESTED) {
            if (disease == null) {
                this.currentPatient = patient;
                return CURE;
            }
            if (testRandomCureChance()) {
                this.currentPatient = patient;
                return FREE_CURE;
            }
            if (!InventoryUtils.isItemHandlerFull(citizen.getInventoryCitizen())) {
                if (hasCureInInventory(disease, worker.getInventoryCitizen()) || hasCureInInventory(disease, building.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElseGet(null))) {
                    this.currentPatient = patient;
                    return CURE;
                }
                final ImmutableList<IRequest<? extends Stack>> list = building.getOpenRequestsOfType(worker.getCitizenData().getId(), TypeToken.of(Stack.class));
                final ImmutableList<IRequest<? extends Stack>> completed = building.getCompletedRequestsOfType(worker.getCitizenData(), TypeToken.of(Stack.class));
                for (final ItemStack cure : IColonyManager.getInstance().getCompatibilityManager().getDisease(diseaseName).getCure()) {
                    if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), cure::sameItem)) {
                        if (InventoryUtils.getItemCountInItemHandler(building.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElseGet(null), stack -> stack.sameItem(cure)) >= cure.getCount()) {
                            needsCurrently = new Tuple<>(stack -> stack.sameItem(cure), cure.getCount());
                            return GATHERING_REQUIRED_MATERIALS;
                        }
                        boolean hasCureRequested = false;
                        for (final IRequest<? extends Stack> request : list) {
                            if (request.getRequest().getStack().sameItem(cure)) {
                                hasCureRequested = true;
                                break;
                            }
                        }
                        for (final IRequest<? extends Stack> request : completed) {
                            if (request.getRequest().getStack().sameItem(cure)) {
                                hasCureRequested = true;
                                break;
                            }
                        }
                        if (!hasCureRequested) {
                            patient.setState(Patient.PatientState.NEW);
                            break;
                        }
                    }
                }
            } else {
                data.triggerInteraction(new StandardInteraction(new TranslationTextComponent(PATIENT_FULL_INVENTORY), ChatPriority.BLOCKING));
            }
        }
        if (patient.getState() == Patient.PatientState.TREATED) {
            if (disease == null) {
                this.currentPatient = patient;
                return CURE;
            }
            if (!hasCureInInventory(disease, citizen.getInventoryCitizen())) {
                patient.setState(Patient.PatientState.NEW);
                return DECIDE;
            }
        }
    }
    for (final PlayerEntity player : WorldUtil.getEntitiesWithinBuilding(world, PlayerEntity.class, building, player -> player.getHealth() < player.getMaxHealth() - 10 - (2 * building.getBuildingLevel()))) {
        playerToHeal = player;
        return CURE_PLAYER;
    }
    final ICitizenData data = building.getColony().getCitizenManager().getRandomCitizen();
    if (data.getEntity().isPresent() && data.getEntity().get().getHealth() < 10.0 && BlockPosUtil.getDistance2D(data.getEntity().get().blockPosition(), building.getPosition()) < building.getBuildingLevel() * 40) {
        remotePatient = data;
        return WANDER;
    }
    return DECIDE;
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) ICitizenData(com.minecolonies.api.colony.ICitizenData) TypeToken(com.google.common.reflect.TypeToken) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) ImmutableList(com.google.common.collect.ImmutableList) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) JobHealer(com.minecolonies.coremod.colony.jobs.JobHealer) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) com.minecolonies.api.util(com.minecolonies.api.util) Network(com.minecolonies.coremod.Network) PATIENT_FULL_INVENTORY(com.minecolonies.api.util.constant.TranslationConstants.PATIENT_FULL_INVENTORY) StreamParticleEffectMessage(com.minecolonies.coremod.network.messages.client.StreamParticleEffectMessage) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack) AbstractEntityAIInteract(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIInteract) PlayerEntity(net.minecraft.entity.player.PlayerEntity) CircleParticleEffectMessage(com.minecolonies.coremod.network.messages.client.CircleParticleEffectMessage) IColonyManager(com.minecolonies.api.colony.IColonyManager) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BlockPos(net.minecraft.util.math.BlockPos) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) ParticleTypes(net.minecraft.particles.ParticleTypes) Nullable(org.jetbrains.annotations.Nullable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) BuildingHospital(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingHospital) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) NotNull(org.jetbrains.annotations.NotNull) BuildingHospital(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingHospital) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) ICitizenData(com.minecolonies.api.colony.ICitizenData) ItemStack(net.minecraft.item.ItemStack) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) ItemStack(net.minecraft.item.ItemStack) Nullable(org.jetbrains.annotations.Nullable)

Example 38 with StandardInteraction

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

the class EntityAIWorkHealer method cure.

/**
 * Give a citizen the cure.
 *
 * @return the next state to go to.
 */
private IAIState cure() {
    if (currentPatient == null) {
        return DECIDE;
    }
    final ICitizenData data = building.getColony().getCitizenManager().getCivilian(currentPatient.getId());
    if (data == null || !data.getEntity().isPresent() || !data.getEntity().get().getCitizenDiseaseHandler().isSick()) {
        currentPatient = null;
        return DECIDE;
    }
    final EntityCitizen citizen = (EntityCitizen) data.getEntity().get();
    if (walkToBlock(data.getEntity().get().blockPosition())) {
        return CURE;
    }
    final String diseaseName = citizen.getCitizenDiseaseHandler().getDisease();
    final Disease disease = IColonyManager.getInstance().getCompatibilityManager().getDisease(diseaseName);
    if (diseaseName.isEmpty()) {
        currentPatient = null;
        citizen.heal(10);
        worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
        citizen.markDirty();
        return DECIDE;
    }
    if (!hasCureInInventory(disease, worker.getInventoryCitizen())) {
        if (hasCureInInventory(disease, building.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElseGet(null))) {
            for (final ItemStack cure : disease.getCure()) {
                if (InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), stack -> stack.sameItem(cure)) < cure.getCount()) {
                    needsCurrently = new Tuple<>(stack -> stack.sameItem(cure), 1);
                    return GATHERING_REQUIRED_MATERIALS;
                }
            }
        }
        currentPatient = null;
        return DECIDE;
    }
    if (!hasCureInInventory(disease, citizen.getInventoryCitizen())) {
        for (final ItemStack cure : disease.getCure()) {
            if (InventoryUtils.getItemCountInItemHandler(citizen.getInventoryCitizen(), stack -> stack.sameItem(cure)) < cure.getCount()) {
                if (InventoryUtils.isItemHandlerFull(citizen.getInventoryCitizen())) {
                    data.triggerInteraction(new StandardInteraction(new TranslationTextComponent(PATIENT_FULL_INVENTORY), ChatPriority.BLOCKING));
                    currentPatient = null;
                    return DECIDE;
                }
                InventoryUtils.transferXOfFirstSlotInItemHandlerWithIntoNextFreeSlotInItemHandler(worker.getInventoryCitizen(), cure::sameItem, cure.getCount(), citizen.getInventoryCitizen());
            }
        }
    }
    worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
    currentPatient.setState(Patient.PatientState.TREATED);
    currentPatient = null;
    return DECIDE;
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) ICitizenData(com.minecolonies.api.colony.ICitizenData) TypeToken(com.google.common.reflect.TypeToken) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) ImmutableList(com.google.common.collect.ImmutableList) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) JobHealer(com.minecolonies.coremod.colony.jobs.JobHealer) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) com.minecolonies.api.util(com.minecolonies.api.util) Network(com.minecolonies.coremod.Network) PATIENT_FULL_INVENTORY(com.minecolonies.api.util.constant.TranslationConstants.PATIENT_FULL_INVENTORY) StreamParticleEffectMessage(com.minecolonies.coremod.network.messages.client.StreamParticleEffectMessage) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack) AbstractEntityAIInteract(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIInteract) PlayerEntity(net.minecraft.entity.player.PlayerEntity) CircleParticleEffectMessage(com.minecolonies.coremod.network.messages.client.CircleParticleEffectMessage) IColonyManager(com.minecolonies.api.colony.IColonyManager) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BlockPos(net.minecraft.util.math.BlockPos) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) ParticleTypes(net.minecraft.particles.ParticleTypes) Nullable(org.jetbrains.annotations.Nullable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) BuildingHospital(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingHospital) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) NotNull(org.jetbrains.annotations.NotNull) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) ICitizenData(com.minecolonies.api.colony.ICitizenData) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) ItemStack(net.minecraft.item.ItemStack)

Example 39 with StandardInteraction

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

the class EntityAIStructureMiner method checkMineShaft.

@NotNull
private IAIState checkMineShaft() {
    final BuildingMiner buildingMiner = building;
    // Check if we reached the bottom of the shaft
    if (getLastLadder(buildingMiner.getLadderLocation(), world) < SHAFT_BASE_DEPTH) {
        AdvancementUtils.TriggerAdvancementPlayersForColony(job.getColony(), AdvancementTriggers.DEEP_MINE::trigger);
    }
    // Check if we reached the mineshaft depth limit
    if (getLastLadder(buildingMiner.getLadderLocation(), world) < buildingMiner.getDepthLimit()) {
        // If the miner hut has been placed too deep.
        if (buildingMiner.getFirstModuleOccurance(MinerLevelManagementModule.class).getNumberOfLevels() == 0) {
            worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NEEDS_BETTER_HUT), ChatPriority.BLOCKING));
            return IDLE;
        }
        worker.getCitizenData().setVisibleStatus(MINING);
        return MINER_MINING_NODE;
    }
    worker.getCitizenData().setVisibleStatus(MINING);
    return MINER_MINING_SHAFT;
}
Also used : StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BuildingMiner(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingMiner) NotNull(org.jetbrains.annotations.NotNull)

Example 40 with StandardInteraction

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

the class CitizenSleepHandler method trySleep.

/**
 * Attempts a sleep interaction with the citizen and the given bed.
 *
 * @param bedLocation The possible location to sleep.
 */
@Override
public boolean trySleep(final BlockPos bedLocation) {
    final BlockState state = WorldUtil.isEntityBlockLoaded(citizen.level, bedLocation) ? citizen.level.getBlockState(bedLocation) : null;
    final boolean isBed = state != null && state.getBlock().isBed(state, citizen.level, bedLocation, citizen);
    if (!isBed) {
        return false;
    }
    citizen.updatePose(Pose.SLEEPING);
    citizen.getNavigation().stop();
    citizen.setPos(((float) bedLocation.getX() + HALF_BLOCK), (float) bedLocation.getY() + 0.8F, ((float) bedLocation.getZ() + HALF_BLOCK));
    citizen.setSleepingPos(bedLocation);
    citizen.setDeltaMovement(Vector3d.ZERO);
    citizen.hasImpulse = true;
    // Remove item while citizen is asleep.
    citizen.getCitizenItemHandler().removeHeldItem();
    setIsAsleep(true);
    citizen.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_SLEEPING), ChatPriority.HIDDEN));
    if (citizen.getCitizenData() != null) {
        citizen.getCitizenData().setBedPos(bedLocation);
    }
    citizen.getEntityData().set(DATA_BED_POS, bedLocation);
    citizen.getCitizenData().getColony().getCitizenManager().onCitizenSleep();
    return true;
}
Also used : BlockState(net.minecraft.block.BlockState) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent)

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