use of com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenSpawnedEvent in project minecolonies by ldtteam.
the class CitizenManager method spawnCitizenOnPosition.
@NotNull
private ICitizenData spawnCitizenOnPosition(@Nullable final ICitizenData data, @NotNull final World world, final boolean force, final BlockPos spawnPoint) {
ICitizenData citizenData = data;
if (citizenData == null) {
citizenData = createAndRegisterCivilianData();
if (getMaxCitizens() >= getCurrentCitizenCount() && !force) {
if (maxCitizensFromResearch() <= getCurrentCitizenCount()) {
LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "block.blockhuttownhall.messagemaxsize.research", colony.getName());
} else {
LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "block.blockhuttownhall.messagemaxsize.config", colony.getName());
}
}
colony.getEventDescriptionManager().addEventDescription(new CitizenSpawnedEvent(spawnPoint, citizenData.getName()));
}
final EntityCitizen entity = (EntityCitizen) ModEntities.CITIZEN.create(world);
entity.setPos(spawnPoint.getX() + HALF_BLOCK, spawnPoint.getY() + SLIGHTLY_UP, spawnPoint.getZ() + HALF_BLOCK);
world.addFreshEntity(entity);
entity.getCitizenColonyHandler().registerWithColony(citizenData.getColony().getID(), citizenData.getId());
colony.getProgressManager().progressCitizenSpawn(citizens.size(), citizens.values().stream().filter(tempDate -> tempDate.getJob() != null).collect(Collectors.toList()).size());
markDirty();
return citizenData;
}
use of com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenSpawnedEvent in project minecolonies by ldtteam.
the class CitizenManager method onColonyTick.
/**
* Updates the citizen entities when needed and spawn the initial citizens on colony tick.
*
* @param colony the colony being ticked.
*/
@Override
public void onColonyTick(final IColony colony) {
if (colony.hasTownHall()) {
getCitizens().stream().filter(Objects::nonNull).forEach(ICitizenData::updateEntityIfNecessary);
}
// Spawn initial Citizens
if (colony.canMoveIn() && colony.hasTownHall() && getCitizens().size() < MineColonies.getConfig().getServer().initialCitizenAmount.get()) {
respawnInterval -= 500 + (SECONDS_A_MINUTE * colony.getBuildingManager().getTownHall().getBuildingLevel());
if (respawnInterval <= 0) {
respawnInterval = MineColonies.getConfig().getServer().citizenRespawnInterval.get() * TICKS_SECOND;
int femaleCount = 0;
for (ICitizenData citizens : getCitizens()) {
femaleCount += citizens.isFemale() ? 1 : 0;
}
final ICitizenData newCitizen = createAndRegisterCivilianData();
// For first citizen, give a random chance of male or female.
if (getCitizens().size() == 1) {
newCitizen.setGenderAndGenerateName(random.nextBoolean());
} else // Use double division to avoid getting two male colonists in a row for the first set.
if (femaleCount < (getCitizens().size() - 1) / 2.0) {
newCitizen.setGenderAndGenerateName(true);
} else {
newCitizen.setGenderAndGenerateName(false);
}
spawnOrCreateCivilian(newCitizen, colony.getWorld(), null, true);
colony.getEventDescriptionManager().addEventDescription(new CitizenSpawnedEvent(colony.getBuildingManager().getTownHall().getPosition(), newCitizen.getName()));
}
}
}
use of com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenSpawnedEvent in project minecolonies by Minecolonies.
the class CitizenManager method onColonyTick.
/**
* Updates the citizen entities when needed and spawn the initial citizens on colony tick.
*
* @param colony the colony being ticked.
*/
@Override
public void onColonyTick(final IColony colony) {
if (colony.hasTownHall()) {
getCitizens().stream().filter(Objects::nonNull).forEach(ICitizenData::updateEntityIfNecessary);
}
// Spawn initial Citizens
if (colony.canMoveIn() && colony.hasTownHall() && getCitizens().size() < MineColonies.getConfig().getServer().initialCitizenAmount.get()) {
respawnInterval -= 500 + (SECONDS_A_MINUTE * colony.getBuildingManager().getTownHall().getBuildingLevel());
if (respawnInterval <= 0) {
respawnInterval = MineColonies.getConfig().getServer().citizenRespawnInterval.get() * TICKS_SECOND;
int femaleCount = 0;
for (ICitizenData citizens : getCitizens()) {
femaleCount += citizens.isFemale() ? 1 : 0;
}
final ICitizenData newCitizen = createAndRegisterCivilianData();
// For first citizen, give a random chance of male or female.
if (getCitizens().size() == 1) {
newCitizen.setGenderAndGenerateName(random.nextBoolean());
} else // Use double division to avoid getting two male colonists in a row for the first set.
if (femaleCount < (getCitizens().size() - 1) / 2.0) {
newCitizen.setGenderAndGenerateName(true);
} else {
newCitizen.setGenderAndGenerateName(false);
}
spawnOrCreateCivilian(newCitizen, colony.getWorld(), null, true);
colony.getEventDescriptionManager().addEventDescription(new CitizenSpawnedEvent(colony.getBuildingManager().getTownHall().getPosition(), newCitizen.getName()));
}
}
}
use of com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenSpawnedEvent in project minecolonies by Minecolonies.
the class CitizenManager method spawnCitizenOnPosition.
@NotNull
private ICitizenData spawnCitizenOnPosition(@Nullable final ICitizenData data, @NotNull final World world, final boolean force, final BlockPos spawnPoint) {
ICitizenData citizenData = data;
if (citizenData == null) {
citizenData = createAndRegisterCivilianData();
if (getMaxCitizens() >= getCurrentCitizenCount() && !force) {
if (maxCitizensFromResearch() <= getCurrentCitizenCount()) {
MessageUtils.format(WARNING_MAX_CITIZENS_RESEARCH, colony.getName()).sendTo(colony).forAllPlayers();
} else {
MessageUtils.format(WARNING_MAX_CITIZENS_CONFIG, colony.getName()).sendTo(colony).forAllPlayers();
}
}
colony.getEventDescriptionManager().addEventDescription(new CitizenSpawnedEvent(spawnPoint, citizenData.getName()));
}
final EntityCitizen entity = (EntityCitizen) ModEntities.CITIZEN.create(world);
entity.setPos(spawnPoint.getX() + HALF_BLOCK, spawnPoint.getY() + SLIGHTLY_UP, spawnPoint.getZ() + HALF_BLOCK);
world.addFreshEntity(entity);
entity.getCitizenColonyHandler().registerWithColony(citizenData.getColony().getID(), citizenData.getId());
colony.getProgressManager().progressCitizenSpawn(citizens.size(), citizens.values().stream().filter(tempDate -> tempDate.getJob() != null).collect(Collectors.toList()).size());
markDirty();
return citizenData;
}
Aggregations