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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations