Search in sources :

Example 11 with EntityCitizen

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();
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen)

Example 12 with EntityCitizen

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();
}
Also used : EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen)

Aggregations

EntityCitizen (com.minecolonies.coremod.entity.EntityCitizen)12 BlockPos (net.minecraft.util.math.BlockPos)7 CitizenData (com.minecolonies.coremod.colony.CitizenData)4 TextComponentString (net.minecraft.util.text.TextComponentString)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)2 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)1 Colony (com.minecolonies.coremod.colony.Colony)1 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)1 AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)1 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)1 JobGuard (com.minecolonies.coremod.colony.jobs.JobGuard)1 Permissions (com.minecolonies.coremod.colony.permissions.Permissions)1 AbstractAISkeleton (com.minecolonies.coremod.entity.ai.basic.AbstractAISkeleton)1 InventoryCitizen (com.minecolonies.coremod.inventory.InventoryCitizen)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 VertexBuffer (net.minecraft.client.renderer.VertexBuffer)1 EntityMob (net.minecraft.entity.monster.EntityMob)1