Search in sources :

Example 81 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class EntityAIEatTask method waitForFood.

/**
 * Wander around the placeToPath a bit while waiting for the cook to deliver food. After waiting for a certain time, get the food yourself.
 *
 * @return the next state to go to.
 */
private EatingState waitForFood() {
    final ICitizenData citizenData = citizen.getCitizenData();
    final IColony colony = citizenData.getColony();
    restaurantPos = colony.getBuildingManager().getBestBuilding(citizen, BuildingCook.class);
    if (restaurantPos == null) {
        return SEARCH_RESTAURANT;
    }
    if (!colony.getBuildingManager().getBuilding(restaurantPos).isInBuilding(citizen.blockPosition())) {
        return GO_TO_RESTAURANT;
    }
    eatPos = findPlaceToEat();
    if (eatPos != null) {
        return GO_TO_EAT_POS;
    }
    if (hasFood()) {
        return EAT;
    }
    return WAIT_FOR_FOOD;
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData) IColony(com.minecolonies.api.colony.IColony) BuildingCook(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingCook)

Example 82 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class EntityAIWorkNether method checkHeal.

/**
 * Checks the citizens health status and heals the citizen if necessary.
 */
private float checkHeal(AbstractEntityCitizen citizen) {
    ICitizenData citizenData = citizen.getCitizenData();
    double healAmount = 0D;
    if (citizen.getHealth() < citizen.getMaxHealth()) {
        final double limitDecrease = citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(SATLIMIT);
        if (citizenData.getSaturation() >= FULL_SATURATION + limitDecrease) {
            healAmount = 2 * (1.0 + citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(REGENERATION));
        } else if (citizenData.getSaturation() < LOW_SATURATION) {
            return (float) healAmount;
        } else {
            healAmount = 1 * (1.0 + citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(REGENERATION));
        }
        citizen.heal((float) healAmount);
        if (healAmount > 0.1D) {
            citizenData.markDirty();
        }
    }
    return (float) healAmount;
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 83 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class EntityAIWorkHealer method freeCure.

/**
 * Do free cure magic.
 *
 * @return the next state to go to.
 */
private IAIState freeCure() {
    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(citizen.blockPosition())) {
        progressTicks = 0;
        return FREE_CURE;
    }
    progressTicks++;
    if (progressTicks < MAX_PROGRESS_TICKS) {
        Network.getNetwork().sendToTrackingEntity(new StreamParticleEffectMessage(worker.position().add(0, 2, 0), citizen.position(), ParticleTypes.HEART, progressTicks % MAX_PROGRESS_TICKS, MAX_PROGRESS_TICKS), worker);
        Network.getNetwork().sendToTrackingEntity(new CircleParticleEffectMessage(worker.position().add(0, 2, 0), ParticleTypes.HEART, progressTicks), worker);
        return getState();
    }
    progressTicks = 0;
    worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
    citizen.getCitizenDiseaseHandler().cure();
    currentPatient.setState(Patient.PatientState.TREATED);
    currentPatient = null;
    return DECIDE;
}
Also used : StreamParticleEffectMessage(com.minecolonies.coremod.network.messages.client.StreamParticleEffectMessage) ICitizenData(com.minecolonies.api.colony.ICitizenData) CircleParticleEffectMessage(com.minecolonies.coremod.network.messages.client.CircleParticleEffectMessage) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen)

Example 84 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class EntityAIWorkHealer method requestCure.

/**
 * Request the cure for a given patient.
 *
 * @return the next state to go to.
 */
private IAIState requestCure() {
    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(citizen.blockPosition())) {
        return REQUEST_CURE;
    }
    final String diseaseName = citizen.getCitizenDiseaseHandler().getDisease();
    if (diseaseName.isEmpty()) {
        currentPatient.setState(Patient.PatientState.REQUESTED);
        currentPatient = null;
        return DECIDE;
    }
    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) && !InventoryUtils.hasItemInItemHandler(building.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElseGet(null), cure::sameItem)) {
            boolean hasRequest = false;
            for (final IRequest<? extends Stack> request : list) {
                if (request.getRequest().getStack().sameItem(cure)) {
                    hasRequest = true;
                    break;
                }
            }
            for (final IRequest<? extends Stack> request : completed) {
                if (request.getRequest().getStack().sameItem(cure)) {
                    hasRequest = true;
                    break;
                }
            }
            if (!hasRequest) {
                worker.getCitizenData().createRequestAsync(new Stack(cure, REQUEST_COUNT, 1));
            }
        }
    }
    currentPatient.setState(Patient.PatientState.REQUESTED);
    currentPatient = null;
    return DECIDE;
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData) 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) ItemStack(net.minecraft.item.ItemStack) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack)

Example 85 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class CitizenHappinessHandler method getGuardFactor.

/**
 * Get the guard security happiness modifier from the colony.
 *
 * @param colony the colony.
 * @return true if so.
 */
private double getGuardFactor(final IColony colony) {
    double guards = 1;
    double workers = 1;
    for (final ICitizenData citizen : colony.getCitizenManager().getCitizens()) {
        if (citizen.getJob() instanceof AbstractJobGuard) {
            guards++;
        } else {
            workers++;
        }
    }
    return Math.min(guards / (workers * 2 / 3), 2);
}
Also used : AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Aggregations

ICitizenData (com.minecolonies.api.colony.ICitizenData)180 NotNull (org.jetbrains.annotations.NotNull)49 BlockPos (net.minecraft.util.math.BlockPos)47 IColony (com.minecolonies.api.colony.IColony)46 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)40 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)33 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)31 ItemStack (net.minecraft.item.ItemStack)28 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)23 PlayerEntity (net.minecraft.entity.player.PlayerEntity)23 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)22 Nullable (org.jetbrains.annotations.Nullable)22 CompoundNBT (net.minecraft.nbt.CompoundNBT)18 Colony (com.minecolonies.coremod.colony.Colony)16 ArrayList (java.util.ArrayList)16 AbstractJobCrafter (com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)14 EntityCitizen (com.minecolonies.coremod.entity.citizen.EntityCitizen)14 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)13 AbstractAssignedCitizenModule (com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule)12 java.util (java.util)12