use of com.minecolonies.coremod.entity.EntityCitizen in project minecolonies by Minecolonies.
the class Colony method spawnCitizen.
/**
* Spawn a citizen with specific citizen data.
*
* @param data Data to use to spawn citizen.
*/
public void spawnCitizen(final CitizenData data) {
final BlockPos townHallLocation = townHall.getLocation();
if (!world.isBlockLoaded(townHallLocation)) {
// Chunk with TownHall Block is not loaded
return;
}
final BlockPos spawnPoint = EntityUtils.getSpawnPoint(world, townHallLocation);
if (spawnPoint != null) {
final EntityCitizen entity = new EntityCitizen(world);
CitizenData citizenData = data;
if (citizenData == null) {
//That's needed to prevent bugs when calling IDs that are not used.
for (int i = 1; i <= this.getMaxCitizens(); i++) {
if (this.getCitizen(i) == null) {
topCitizenId = i;
break;
}
}
citizenData = new CitizenData(topCitizenId, this);
citizenData.initializeFromEntity(entity);
citizens.put(citizenData.getId(), citizenData);
if (getMaxCitizens() == getCitizens().size()) {
//TODO: add Colony Name prefix?
LanguageHandler.sendPlayersMessage(this.getMessageEntityPlayers(), "tile.blockHutTownHall.messageMaxSize");
}
}
entity.setColony(this, citizenData);
entity.setPosition(spawnPoint.getX() + 0.5D, spawnPoint.getY() + 0.1D, spawnPoint.getZ() + 0.5D);
world.spawnEntity(entity);
checkAchievements();
markCitizensDirty();
}
}
use of com.minecolonies.coremod.entity.EntityCitizen in project minecolonies by Minecolonies.
the class AbstractBuildingWorker method setWorker.
/**
* Set the worker of the current building.
*
* @param citizen {@link CitizenData} of the worker
*/
public void setWorker(final CitizenData citizen) {
if (worker == citizen) {
return;
}
// If we have a worker, it no longer works here
if (worker != null) {
final EntityCitizen tempCitizen = worker.getCitizenEntity();
worker.setWorkBuilding(null);
if (tempCitizen != null) {
tempCitizen.setLastJob(getJobName());
}
}
worker = citizen;
// If we set a worker, inform it of such
if (worker != null) {
final EntityCitizen tempCitizen = citizen.getCitizenEntity();
if (tempCitizen != null && !tempCitizen.getLastJob().equals(getJobName())) {
citizen.resetExperienceAndLevel();
}
worker.setWorkBuilding(this);
}
markDirty();
}
Aggregations