Search in sources :

Example 31 with ICitizenData

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

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 32 with ICitizenData

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

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 33 with ICitizenData

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

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 34 with ICitizenData

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

the class EntityAIWorkUndertaker method tryResurrect.

/**
 * Attempt to resurrect buried citizen from its citizen data
 * Randomize to see if resurrection successful and resurrect if need be
 *
 * @return the next IAIState
 */
private IAIState tryResurrect() {
    @Nullable final BuildingGraveyard buildingGraveyard = getOwnBuilding();
    if (checkForToolOrWeapon(ToolType.SHOVEL) || buildingGraveyard.getFirstModuleOccurance(GraveyardManagementModule.class).getLastGraveData() == null || buildingGraveyard.getGraveToWorkOn() == null) {
        return IDLE;
    }
    unequip();
    @Nullable final BlockPos gravePos = buildingGraveyard.getGraveToWorkOn();
    if (gravePos == null) {
        return IDLE;
    }
    // Still moving to the block
    if (walkToBlock(gravePos, 3)) {
        return getState();
    }
    final TileEntity entity = world.getBlockEntity(gravePos);
    if (entity instanceof TileEntityGrave) {
        if (effortCounter < EFFORT_RESURRECT) {
            worker.swing(Hand.MAIN_HAND);
            effortCounter += getSecondarySkillLevel();
            return getState();
        }
        effortCounter = 0;
        shouldDumpInventory = true;
        final double chance = getResurrectChance(buildingGraveyard);
        if (getTotemResurrectChance() > 0 && random.nextDouble() <= TOTEM_BREAK_CHANCE) {
            worker.getInventoryCitizen().extractItem(InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), Items.TOTEM_OF_UNDYING), 1, false);
            worker.playSound(SoundEvents.TOTEM_USE, 1.0f, 1.0f);
        }
        if (chance >= random.nextDouble()) {
            final ICitizenData citizenData = buildingGraveyard.getColony().getCitizenManager().resurrectCivilianData(buildingGraveyard.getFirstModuleOccurance(GraveyardManagementModule.class).getLastGraveData().getCitizenDataNBT(), true, world, gravePos);
            LanguageHandler.sendPlayersMessage(buildingGraveyard.getColony().getImportantMessageEntityPlayers(), "com.minecolonies.coremod.resurrect", citizenData.getName());
            worker.getCitizenColonyHandler().getColony().getCitizenManager().updateCitizenMourn(citizenData, false);
            AdvancementUtils.TriggerAdvancementPlayersForColony(worker.getCitizenColonyHandler().getColony(), playerMP -> AdvancementTriggers.CITIZEN_RESURRECT.trigger(playerMP));
            buildingGraveyard.getFirstModuleOccurance(GraveyardManagementModule.class).setLastGraveData(null);
            world.setBlockAndUpdate(gravePos, Blocks.AIR.defaultBlockState());
            return INVENTORY_FULL;
        }
    }
    return DIG_GRAVE;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BuildingGraveyard(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingGraveyard) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave) Nullable(org.jetbrains.annotations.Nullable) GraveyardManagementModule(com.minecolonies.coremod.colony.buildings.modules.GraveyardManagementModule)

Example 35 with ICitizenData

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

the class CitizenExperienceHandler method addExperience.

@Override
public void addExperience(final double xp) {
    final IBuilding home = citizen.getCitizenColonyHandler().getHomeBuilding();
    final double citizenHutLevel = home == null ? 0 : home.getBuildingLevel();
    final ICitizenData data = citizen.getCitizenData();
    final IBuilding workBuilding = data.getWorkBuilding();
    if (workBuilding == null || !workBuilding.hasModule(WorkerBuildingModule.class)) {
        return;
    }
    final double workBuildingLevel = workBuilding.getBuildingLevel();
    final double buildingXPModifier = 1 + (workBuildingLevel + citizenHutLevel) / 10;
    double localXp = xp * buildingXPModifier;
    final double saturation = citizen.getCitizenData().getSaturation();
    final int intelligenceLevel = data.getCitizenSkillHandler().getLevel(Skill.Intelligence);
    localXp += localXp * (intelligenceLevel / 100.0);
    if (saturation <= 0) {
        return;
    }
    localXp *= (1 + citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(LEVELING));
    localXp = citizen.getCitizenItemHandler().applyMending(localXp);
    final WorkerBuildingModule module = workBuilding.getModuleMatching(WorkerBuildingModule.class, m -> m.getAssignedCitizen().contains(data));
    final Skill primary = module.getPrimarySkill();
    final Skill secondary = module.getSecondarySkill();
    data.getCitizenSkillHandler().addXpToSkill(primary, localXp, data);
    data.getCitizenSkillHandler().addXpToSkill(primary.getComplimentary(), localXp / (100.0 / PRIMARY_DEPENDENCY_SHARE), data);
    data.getCitizenSkillHandler().removeXpFromSkill(primary.getAdverse(), localXp / (100.0 / PRIMARY_DEPENDENCY_SHARE), data);
    data.getCitizenSkillHandler().addXpToSkill(secondary, localXp / 2.0, data);
    data.getCitizenSkillHandler().addXpToSkill(secondary.getComplimentary(), localXp / (100.0 / SECONDARY_DEPENDENCY_SHARE), data);
    data.getCitizenSkillHandler().removeXpFromSkill(secondary.getAdverse(), localXp / (100.0 / SECONDARY_DEPENDENCY_SHARE), data);
}
Also used : Skill(com.minecolonies.api.entity.citizen.Skill) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) 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