use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.
the class RegisteredStructureManager method guardBuildingChangedAt.
@Override
public void guardBuildingChangedAt(final IBuilding guardBuilding, final int newLevel) {
final int claimRadius = guardBuilding.getClaimRadius(Math.max(guardBuilding.getBuildingLevel(), newLevel));
final MutableBoundingBox guardedRegion = BlockPosUtil.getChunkAlignedBB(guardBuilding.getPosition(), claimRadius);
for (final IBuilding building : getBuildings().values()) {
if (guardedRegion.isInside(building.getPosition())) {
building.resetGuardBuildingNear();
}
}
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.
the class ReproductionManager method trySpawnChild.
/**
* Try to spawn a new citizen as child. Mom / dad entities are required and chosen randomly in this hut. Childs inherit stats from their parents, avergaged +-2 Childs get
* assigned to a free housing slot in the colony to be raised there, if the house has an adult living there the child takes its name and gets raised by it.
*/
public void trySpawnChild() {
// Spawn a child when adults are present
if (colony.canMoveIn() && colony.getCitizenManager().getCurrentCitizenCount() < colony.getCitizenManager().getMaxCitizens() && colony.getCitizenManager().getCurrentCitizenCount() >= Math.min(MIN_SIZE_FOR_REPRO, MinecoloniesAPIProxy.getInstance().getConfig().getServer().initialCitizenAmount.get())) {
if (!checkForBioParents()) {
return;
}
final IBuilding newHome = colony.getBuildingManager().getHouseWithSpareBed();
if (newHome == null) {
return;
}
final LivingBuildingModule module = newHome.getFirstModuleOccurance(LivingBuildingModule.class);
final List<ICitizenData> assignedCitizens = module.getAssignedCitizen();
assignedCitizens.removeIf(ICitizen::isChild);
final ICitizenData newCitizen = colony.getCitizenManager().createAndRegisterCivilianData();
ICitizenData firstParent;
ICitizenData secondParent;
if (!assignedCitizens.isEmpty()) {
firstParent = assignedCitizens.get(random.nextInt(assignedCitizens.size()));
secondParent = firstParent.getPartner();
if (secondParent == null) {
assignedCitizens.removeIf(cit -> cit.getPartner() != null || cit.getName().equals(firstParent.getName()) || cit.isRelatedTo(firstParent));
if (assignedCitizens.size() > 0 && random.nextBoolean()) {
secondParent = assignedCitizens.get(random.nextInt(assignedCitizens.size()));
} else {
final BlockPos altPos = colony.getBuildingManager().getRandomBuilding(b -> b.hasModule(LivingBuildingModule.class) && !b.getPosition().equals(newHome.getPosition()) && BlockPosUtil.getDistance2D(b.getPosition(), newHome.getPosition()) < 50);
if (altPos != null) {
final IBuilding building = colony.getBuildingManager().getBuilding(altPos);
final LivingBuildingModule altModule = building.getFirstModuleOccurance(LivingBuildingModule.class);
final List<ICitizenData> newAssignedCitizens = altModule.getAssignedCitizen();
newAssignedCitizens.removeIf(cit -> cit.isChild() || cit.getPartner() != null || cit.isRelatedTo(firstParent));
if (newAssignedCitizens.size() > 0) {
secondParent = newAssignedCitizens.get(random.nextInt(newAssignedCitizens.size()));
}
}
}
}
} else {
firstParent = null;
secondParent = null;
}
if (secondParent != null) {
firstParent.setPartner(secondParent.getId());
secondParent.setPartner(firstParent.getId());
}
newCitizen.getCitizenSkillHandler().init(colony, firstParent, secondParent, random);
newCitizen.setIsChild(true);
final List<String> possibleSuffixes = new ArrayList<>();
if (firstParent != null) {
newCitizen.addSiblings(firstParent.getChildren().toArray(new Integer[0]));
firstParent.addChildren(newCitizen.getId());
possibleSuffixes.add(firstParent.getTextureSuffix());
}
if (secondParent != null) {
newCitizen.addSiblings(secondParent.getChildren().toArray(new Integer[0]));
secondParent.addChildren(newCitizen.getId());
possibleSuffixes.add(secondParent.getTextureSuffix());
}
newCitizen.setParents(firstParent == null ? "" : firstParent.getName(), secondParent == null ? "" : secondParent.getName());
newCitizen.generateName(random, firstParent == null ? "" : firstParent.getName(), secondParent == null ? "" : secondParent.getName());
module.assignCitizen(newCitizen);
for (final int sibling : newCitizen.getSiblings()) {
final ICitizenData siblingData = colony.getCitizenManager().getCivilian(sibling);
if (siblingData != null) {
siblingData.addSiblings(newCitizen.getId());
}
}
if (possibleSuffixes.contains("_w") && possibleSuffixes.contains("_d")) {
possibleSuffixes.add("_b");
}
if (possibleSuffixes.isEmpty()) {
possibleSuffixes.addAll(SUFFIXES);
}
newCitizen.setSuffix(possibleSuffixes.get(random.nextInt(possibleSuffixes.size())));
final int populationCount = colony.getCitizenManager().getCurrentCitizenCount();
AdvancementUtils.TriggerAdvancementPlayersForColony(colony, playerMP -> AdvancementTriggers.COLONY_POPULATION.trigger(playerMP, populationCount));
MessageUtils.format(MESSAGE_NEW_CHILD_BORN, newCitizen.getName(), colony.getName()).with(TextFormatting.GOLD).sendTo(colony).forManagers();
colony.getCitizenManager().spawnOrCreateCitizen(newCitizen, colony.getWorld(), newHome.getPosition());
colony.getEventDescriptionManager().addEventDescription(new CitizenBornEvent(newHome.getPosition(), newCitizen.getName()));
}
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.
the class CitizenManager method calculateMaxCitizens.
@Override
public void calculateMaxCitizens() {
int newMaxCitizens = 0;
int potentialMax = 0;
for (final IBuilding b : colony.getBuildingManager().getBuildings().values()) {
if (b.getBuildingLevel() > 0) {
if (b.hasModule(BedHandlingModule.class) && b.hasModule(WorkAtHomeBuildingModule.class)) {
final WorkAtHomeBuildingModule module = b.getFirstModuleOccurance(WorkAtHomeBuildingModule.class);
newMaxCitizens += b.getAllAssignedCitizen().size();
potentialMax += module.getModuleMax() - b.getAllAssignedCitizen().size();
} else if (b.hasModule(LivingBuildingModule.class)) {
newMaxCitizens += b.getFirstModuleOccurance(LivingBuildingModule.class).getModuleMax();
}
}
}
if (getMaxCitizens() != newMaxCitizens) {
setMaxCitizens(newMaxCitizens);
setPotentialMaxCitizens(potentialMax + newMaxCitizens);
colony.markDirty();
}
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.
the class Tree method checkIfInColonyAndNotInBuilding.
/**
* Calculates with a colony if the position is inside the colony and if it is inside a building.
*
* @param pos the position.
* @param colony the colony.
* @param world the world to use
* @return return false if not inside the colony or if inside a building.
*/
public static boolean checkIfInColonyAndNotInBuilding(final BlockPos pos, final IColony colony, final IWorldReader world) {
final IChunk chunk = world.getChunk(pos);
if (!(chunk instanceof Chunk)) {
return false;
}
final IColonyTagCapability cap = ((Chunk) chunk).getCapability(CLOSE_COLONY_CAP, null).resolve().orElse(null);
if (cap != null && cap.getOwningColony() != colony.getID()) {
return false;
}
// Dynamic tree's are never part of buildings
if (Compatibility.isDynamicBlock(world.getBlockState(pos).getBlock())) {
return true;
}
for (final IBuilding building : colony.getBuildingManager().getBuildings().values()) {
if (building.isInBuilding(pos)) {
return false;
}
}
return true;
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.
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;
}
Aggregations