Search in sources :

Example 1 with DiseaseState

use of com.minecolonies.coremod.entity.ai.minimal.EntityAISickTask.DiseaseState in project minecolonies by ldtteam.

the class EntityAISickTask method waitForCure.

/**
 * Stay in bed while waiting to be cured.
 *
 * @return the next state to go to.
 */
private DiseaseState waitForCure() {
    final IColony colony = citizenData.getColony();
    placeToPath = colony.getBuildingManager().getBestBuilding(citizen, BuildingHospital.class);
    if (placeToPath == null) {
        return SEARCH_HOSPITAL;
    }
    final DiseaseState state = checkForCure();
    if (state == APPLY_CURE) {
        return APPLY_CURE;
    } else if (state == IDLE) {
        reset();
        return IDLE;
    }
    if (citizen.getRandom().nextInt(10000) < CHANCE_FOR_RANDOM_CURE) {
        cure();
        return IDLE;
    }
    if (citizen.getCitizenSleepHandler().isAsleep()) {
        final BlockPos hospital = colony.getBuildingManager().getBestBuilding(citizen, BuildingHospital.class);
        if (hospital != null) {
            final IBuilding building = colony.getBuildingManager().getBuilding(hospital);
            if (building instanceof BuildingHospital && !((BuildingHospital) building).getBedList().contains(citizen.getCitizenSleepHandler().getBedLocation())) {
                citizen.getCitizenSleepHandler().onWakeUp();
            }
        }
    }
    if (!citizen.getCitizenSleepHandler().isAsleep() && BlockPosUtil.getDistance2D(placeToPath, citizen.blockPosition()) > MINIMUM_DISTANCE_TO_HOSPITAL) {
        return GO_TO_HOSPITAL;
    }
    if (!citizen.getCitizenSleepHandler().isAsleep()) {
        return FIND_EMPTY_BED;
    }
    return WAIT_FOR_CURE;
}
Also used : BuildingHospital(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingHospital) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) IColony(com.minecolonies.api.colony.IColony) BlockPos(net.minecraft.util.math.BlockPos) DiseaseState(com.minecolonies.coremod.entity.ai.minimal.EntityAISickTask.DiseaseState)

Example 2 with DiseaseState

use of com.minecolonies.coremod.entity.ai.minimal.EntityAISickTask.DiseaseState in project minecolonies by Minecolonies.

the class EntityAISickTask method waitForCure.

/**
 * Stay in bed while waiting to be cured.
 *
 * @return the next state to go to.
 */
private DiseaseState waitForCure() {
    final IColony colony = citizenData.getColony();
    placeToPath = colony.getBuildingManager().getBestBuilding(citizen, BuildingHospital.class);
    if (placeToPath == null) {
        return SEARCH_HOSPITAL;
    }
    final DiseaseState state = checkForCure();
    if (state == APPLY_CURE) {
        return APPLY_CURE;
    } else if (state == IDLE) {
        reset();
        return IDLE;
    }
    if (citizen.getRandom().nextInt(10000) < CHANCE_FOR_RANDOM_CURE) {
        cure();
        return IDLE;
    }
    if (citizen.getCitizenSleepHandler().isAsleep()) {
        final BlockPos hospital = colony.getBuildingManager().getBestBuilding(citizen, BuildingHospital.class);
        if (hospital != null) {
            final IBuilding building = colony.getBuildingManager().getBuilding(hospital);
            if (building instanceof BuildingHospital && !((BuildingHospital) building).getBedList().contains(citizen.getCitizenSleepHandler().getBedLocation())) {
                citizen.getCitizenSleepHandler().onWakeUp();
            }
        }
    }
    if (!citizen.getCitizenSleepHandler().isAsleep() && BlockPosUtil.getDistance2D(placeToPath, citizen.blockPosition()) > MINIMUM_DISTANCE_TO_HOSPITAL) {
        return GO_TO_HOSPITAL;
    }
    if (!citizen.getCitizenSleepHandler().isAsleep()) {
        return FIND_EMPTY_BED;
    }
    return WAIT_FOR_CURE;
}
Also used : BuildingHospital(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingHospital) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) IColony(com.minecolonies.api.colony.IColony) BlockPos(net.minecraft.util.math.BlockPos) DiseaseState(com.minecolonies.coremod.entity.ai.minimal.EntityAISickTask.DiseaseState)

Aggregations

IColony (com.minecolonies.api.colony.IColony)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 BuildingHospital (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingHospital)2 DiseaseState (com.minecolonies.coremod.entity.ai.minimal.EntityAISickTask.DiseaseState)2 BlockPos (net.minecraft.util.math.BlockPos)2