Search in sources :

Example 96 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class AbstractBuildingGuards method setRallyLocation.

@Override
public void setRallyLocation(final ILocation location) {
    boolean reduceSaturation = false;
    if (rallyLocation != null && location == null) {
        reduceSaturation = true;
    }
    rallyLocation = location;
    for (final ICitizenData iCitizenData : getAllAssignedCitizen()) {
        if (reduceSaturation && iCitizenData.getSaturation() < LOW_SATURATION) {
            // In addition to the scaled saturation reduction during rallying, stopping a rally
            // will - if only LOW_SATURATION is left - set the saturation level to 0.
            iCitizenData.decreaseSaturation(LOW_SATURATION);
        }
    }
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 97 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class AbstractBuildingGuards method startPatrolNext.

/**
 * Starts the patrol to the next point
 */
private void startPatrolNext() {
    getNextPatrolTarget(true);
    patrolTimer = 5;
    for (final ICitizenData curguard : getAllAssignedCitizen()) {
        if (curguard.getEntity().isPresent()) {
            if (curguard.getEntity().get().getCitizenJobHandler().getColonyJob() instanceof AbstractJobGuard) {
                ((AbstractEntityAIGuard<?, ?>) curguard.getEntity().get().getCitizenJobHandler().getColonyJob().getWorkerAI()).setNextPatrolTarget(lastPatrolPoint);
            }
        }
    }
    arrivedAtPatrol.clear();
}
Also used : AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) AbstractEntityAIGuard(com.minecolonies.coremod.entity.ai.citizen.guard.AbstractEntityAIGuard) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 98 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class AbstractBuildingGuards method serializeToView.

@Override
public void serializeToView(@NotNull final PacketBuffer buf) {
    super.serializeToView(buf);
    buf.writeInt(patrolTargets.size());
    for (final BlockPos pos : patrolTargets) {
        buf.writeBlockPos(pos);
    }
    buf.writeInt(this.getAllAssignedCitizen().size());
    for (final ICitizenData citizen : this.getAllAssignedCitizen()) {
        buf.writeInt(citizen.getId());
    }
    if (minePos != null) {
        buf.writeBoolean(true);
        buf.writeBlockPos(minePos);
    } else {
        buf.writeBoolean(false);
    }
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos)

Example 99 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class AdjustSkillCitizenMessage method onExecute.

@Override
protected void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony) {
    final ICitizenData citizenData = colony.getCitizenManager().getCivilian(citizenId);
    if (citizenData == null) {
        Log.getLogger().warn("AdjustSkillCitizenMessage citizenData is null");
        return;
    }
    final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
    if (!optionalEntityCitizen.isPresent()) {
        Log.getLogger().warn("AdjustSkillCitizenMessage entity citizen is null");
        return;
    }
    final PlayerEntity player = ctxIn.getSender();
    if (player == null) {
        return;
    }
    final boolean isCreative = player.isCreative();
    if (!isCreative) {
        Log.getLogger().warn("AdjustSkillCitizenMessage player must be creative.");
        return;
    }
    citizenData.getCitizenSkillHandler().incrementLevel(skill, quantity);
    citizenData.markDirty();
}
Also used : AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) ICitizenData(com.minecolonies.api.colony.ICitizenData) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 100 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class RecallSingleCitizenMessage method onExecute.

@Override
protected void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony, final IBuilding building) {
    final ICitizenData citizenData = colony.getCitizenManager().getCivilian(citizenId);
    citizenData.setLastPosition(building.getPosition());
    Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
    if (!optionalEntityCitizen.isPresent()) {
        citizenData.updateEntityIfNecessary();
        optionalEntityCitizen = citizenData.getEntity();
    }
    if (optionalEntityCitizen.isPresent() && optionalEntityCitizen.get().getTicksExisted() == 0) {
        citizenData.updateEntityIfNecessary();
    }
    final BlockPos loc = building.getID();
    if (optionalEntityCitizen.isPresent() && !TeleportHelper.teleportCitizen(optionalEntityCitizen.get(), colony.getWorld(), loc)) {
        final PlayerEntity player = ctxIn.getSender();
        if (player == null) {
            return;
        }
        LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.workerhuts.recallFail");
    }
}
Also used : AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

ICitizenData (com.minecolonies.api.colony.ICitizenData)175 NotNull (org.jetbrains.annotations.NotNull)47 IColony (com.minecolonies.api.colony.IColony)45 BlockPos (net.minecraft.util.math.BlockPos)45 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)40 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)30 ItemStack (net.minecraft.item.ItemStack)28 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)27 PlayerEntity (net.minecraft.entity.player.PlayerEntity)26 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)22 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)22 Nullable (org.jetbrains.annotations.Nullable)22 CompoundNBT (net.minecraft.nbt.CompoundNBT)17 ArrayList (java.util.ArrayList)16 Colony (com.minecolonies.coremod.colony.Colony)15 AbstractJobCrafter (com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)14 EntityCitizen (com.minecolonies.coremod.entity.citizen.EntityCitizen)14 AbstractAssignedCitizenModule (com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule)12 java.util (java.util)12 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)12