Search in sources :

Example 1 with CitizenSpawnedEvent

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;
}
Also used : java.util(java.util) LanguageHandler(com.ldtteam.structurize.util.LanguageHandler) ALL_CITIZENS_ARE_SLEEPING(com.minecolonies.api.util.constant.TranslationConstants.ALL_CITIZENS_ARE_SLEEPING) BedHandlingModule(com.minecolonies.coremod.colony.buildings.modules.BedHandlingModule) Constants(net.minecraftforge.common.util.Constants) CompoundNBT(net.minecraft.nbt.CompoundNBT) ICitizenData(com.minecolonies.api.colony.ICitizenData) Function(java.util.function.Function) MinecoloniesAPIProxy(com.minecolonies.api.MinecoloniesAPIProxy) CitizenData(com.minecolonies.coremod.colony.CitizenData) LivingBuildingModule(com.minecolonies.coremod.colony.buildings.modules.LivingBuildingModule) Network(com.minecolonies.coremod.Network) ICitizenDataManager(com.minecolonies.api.colony.ICitizenDataManager) EntityUtils(com.minecolonies.api.util.EntityUtils) ICitizenManager(com.minecolonies.api.colony.managers.interfaces.ICitizenManager) CitizenSpawnedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenSpawnedEvent) Constants(com.minecolonies.api.util.constant.Constants) ColonyViewRemoveCitizenMessage(com.minecolonies.coremod.network.messages.client.colony.ColonyViewRemoveCitizenMessage) ListNBT(net.minecraft.nbt.ListNBT) Entity(net.minecraft.entity.Entity) AbstractAssignedCitizenModule(com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule) CITIZEN_CAP(com.minecolonies.api.research.util.ResearchConstants.CITIZEN_CAP) Colony(com.minecolonies.coremod.colony.Colony) WorkAtHomeBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkAtHomeBuildingModule) World(net.minecraft.world.World) ModEntities(com.minecolonies.api.entity.ModEntities) JobUndertaker(com.minecolonies.coremod.colony.jobs.JobUndertaker) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) AbstractCivilianEntity(com.minecolonies.api.entity.citizen.AbstractCivilianEntity) ICivilianData(com.minecolonies.api.colony.ICivilianData) Nullable(org.jetbrains.annotations.Nullable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) MineColonies(com.minecolonies.coremod.MineColonies) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) NBTUtils(com.minecolonies.api.util.NBTUtils) IColony(com.minecolonies.api.colony.IColony) AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) ColonyViewCitizenViewMessage(com.minecolonies.coremod.network.messages.client.colony.ColonyViewCitizenViewMessage) TAG_CITIZENS(com.minecolonies.api.util.constant.NbtTagConstants.TAG_CITIZENS) COM_MINECOLONIES_COREMOD_MOURN(com.minecolonies.api.util.constant.TranslationConstants.COM_MINECOLONIES_COREMOD_MOURN) TAG_ID(com.minecolonies.api.util.constant.NbtTagConstants.TAG_ID) WorldUtil(com.minecolonies.api.util.WorldUtil) NotNull(org.jetbrains.annotations.NotNull) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) CitizenSpawnedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenSpawnedEvent) ICitizenData(com.minecolonies.api.colony.ICitizenData) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with CitizenSpawnedEvent

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()));
        }
    }
}
Also used : CitizenSpawnedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenSpawnedEvent) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 3 with CitizenSpawnedEvent

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()));
        }
    }
}
Also used : CitizenSpawnedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenSpawnedEvent) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 4 with CitizenSpawnedEvent

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;
}
Also used : java.util(java.util) BedHandlingModule(com.minecolonies.coremod.colony.buildings.modules.BedHandlingModule) Constants(net.minecraftforge.common.util.Constants) CompoundNBT(net.minecraft.nbt.CompoundNBT) ICitizenData(com.minecolonies.api.colony.ICitizenData) Function(java.util.function.Function) MinecoloniesAPIProxy(com.minecolonies.api.MinecoloniesAPIProxy) CitizenData(com.minecolonies.coremod.colony.CitizenData) LivingBuildingModule(com.minecolonies.coremod.colony.buildings.modules.LivingBuildingModule) Network(com.minecolonies.coremod.Network) ICitizenDataManager(com.minecolonies.api.colony.ICitizenDataManager) EntityUtils(com.minecolonies.api.util.EntityUtils) ICitizenManager(com.minecolonies.api.colony.managers.interfaces.ICitizenManager) CitizenSpawnedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenSpawnedEvent) Constants(com.minecolonies.api.util.constant.Constants) ColonyViewRemoveCitizenMessage(com.minecolonies.coremod.network.messages.client.colony.ColonyViewRemoveCitizenMessage) ListNBT(net.minecraft.nbt.ListNBT) Entity(net.minecraft.entity.Entity) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) MessageUtils(com.minecolonies.api.util.MessageUtils) AbstractAssignedCitizenModule(com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule) CITIZEN_CAP(com.minecolonies.api.research.util.ResearchConstants.CITIZEN_CAP) Colony(com.minecolonies.coremod.colony.Colony) WorkAtHomeBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkAtHomeBuildingModule) World(net.minecraft.world.World) ModEntities(com.minecolonies.api.entity.ModEntities) JobUndertaker(com.minecolonies.coremod.colony.jobs.JobUndertaker) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) AbstractCivilianEntity(com.minecolonies.api.entity.citizen.AbstractCivilianEntity) ICivilianData(com.minecolonies.api.colony.ICivilianData) Nullable(org.jetbrains.annotations.Nullable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) MineColonies(com.minecolonies.coremod.MineColonies) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) NBTUtils(com.minecolonies.api.util.NBTUtils) IColony(com.minecolonies.api.colony.IColony) AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) ColonyViewCitizenViewMessage(com.minecolonies.coremod.network.messages.client.colony.ColonyViewCitizenViewMessage) TAG_CITIZENS(com.minecolonies.api.util.constant.NbtTagConstants.TAG_CITIZENS) TAG_ID(com.minecolonies.api.util.constant.NbtTagConstants.TAG_ID) WorldUtil(com.minecolonies.api.util.WorldUtil) NotNull(org.jetbrains.annotations.NotNull) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) CitizenSpawnedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenSpawnedEvent) ICitizenData(com.minecolonies.api.colony.ICitizenData) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ICitizenData (com.minecolonies.api.colony.ICitizenData)4 CitizenSpawnedEvent (com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenSpawnedEvent)4 MinecoloniesAPIProxy (com.minecolonies.api.MinecoloniesAPIProxy)2 ICitizenDataManager (com.minecolonies.api.colony.ICitizenDataManager)2 ICivilianData (com.minecolonies.api.colony.ICivilianData)2 IColony (com.minecolonies.api.colony.IColony)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 ICitizenManager (com.minecolonies.api.colony.managers.interfaces.ICitizenManager)2 ModEntities (com.minecolonies.api.entity.ModEntities)2 AbstractCivilianEntity (com.minecolonies.api.entity.citizen.AbstractCivilianEntity)2 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)2 CITIZEN_CAP (com.minecolonies.api.research.util.ResearchConstants.CITIZEN_CAP)2 EntityUtils (com.minecolonies.api.util.EntityUtils)2 NBTUtils (com.minecolonies.api.util.NBTUtils)2 WorldUtil (com.minecolonies.api.util.WorldUtil)2 Constants (com.minecolonies.api.util.constant.Constants)2 TAG_CITIZENS (com.minecolonies.api.util.constant.NbtTagConstants.TAG_CITIZENS)2 TAG_ID (com.minecolonies.api.util.constant.NbtTagConstants.TAG_ID)2 MineColonies (com.minecolonies.coremod.MineColonies)2 Network (com.minecolonies.coremod.Network)2