use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.
the class EntityAIQuarrier method executeSpecificCompleteActions.
@Override
public void executeSpecificCompleteActions() {
super.executeSpecificCompleteActions();
final IBuilding quarry = job.findQuarry();
if (quarry != null) {
quarry.getFirstModuleOccurance(QuarryModule.class).setFinished();
}
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.
the class EntityAIQuarrier method startWorkingAtOwnBuilding.
// Miner wants to work but is not at building
@NotNull
private IAIState startWorkingAtOwnBuilding() {
worker.getCitizenData().setVisibleStatus(VisibleCitizenStatus.WORKING);
final IBuilding quarry = job.findQuarry();
if (quarry == null) {
walkToBuilding();
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(QUARRY_MINER_NO_QUARRY), ChatPriority.BLOCKING));
return IDLE;
}
if (quarry.getFirstModuleOccurance(QuarryModule.class).isFinished()) {
walkToBuilding();
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(QUARRY_MINER_FINISHED_QUARRY), ChatPriority.BLOCKING));
return IDLE;
}
if (walkToBlock(quarry.getPosition())) {
return getState();
}
// Miner is at building
return LOAD_STRUCTURE;
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.
the class EntityAISickTask method cure.
/**
* Cure the citizen.
*/
private void cure() {
final Disease disease = IColonyManager.getInstance().getCompatibilityManager().getDisease(citizen.getCitizenDiseaseHandler().getDisease());
if (disease != null) {
for (final ItemStack cure : disease.getCure()) {
final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(citizen, stack -> stack.sameItem(cure));
if (slot != -1) {
citizenData.getInventory().extractItem(slot, 1, false);
}
}
}
if (usedBed != null) {
final BlockPos hospitalPos = citizen.getCitizenColonyHandler().getColony().getBuildingManager().getBestBuilding(citizen, BuildingHospital.class);
final IColony colony = citizen.getCitizenColonyHandler().getColony();
final IBuilding hospital = colony.getBuildingManager().getBuilding(hospitalPos);
((BuildingHospital) hospital).registerPatient(usedBed, 0);
usedBed = null;
citizen.getCitizenData().setBedPos(BlockPos.ZERO);
}
citizen.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
citizenData.markDirty();
citizen.getCitizenDiseaseHandler().cure();
citizen.setHealth(citizen.getMaxHealth());
reset();
}
use of com.minecolonies.api.colony.buildings.IBuilding 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;
}
use of com.minecolonies.api.colony.buildings.IBuilding 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