Search in sources :

Example 21 with EntityCitizen

use of com.minecolonies.coremod.entity.citizen.EntityCitizen in project minecolonies by ldtteam.

the class CommandCitizenTriggerWalkTo method onExecute.

/**
 * What happens when the command is executed after preConditions are successful.
 *
 * @param context the context of the command execution
 */
@Override
public int onExecute(final CommandContext<CommandSource> context) {
    final Entity sender = context.getSource().getEntity();
    // Colony
    final int colonyID = IntegerArgumentType.getInteger(context, COLONYID_ARG);
    final IColony colony = IColonyManager.getInstance().getColonyByDimension(colonyID, sender == null ? World.OVERWORLD : context.getSource().getLevel().dimension());
    if (colony == null) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.colonyidnotfound", colonyID), true);
        return 0;
    }
    final ICitizenData citizenData = colony.getCitizenManager().getCivilian(IntegerArgumentType.getInteger(context, CITIZENID_ARG));
    if (citizenData == null) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notfound"), true);
        return 0;
    }
    final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
    if (!optionalEntityCitizen.isPresent()) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notloaded"), true);
        return 0;
    }
    final AbstractEntityCitizen entityCitizen = optionalEntityCitizen.get();
    final ILocationArgument targetLocation = Vec3Argument.getCoordinates(context, POS_ARG);
    final BlockPos targetPos = targetLocation.getBlockPos(context.getSource());
    if (context.getSource().getLevel() == entityCitizen.level) {
        if (entityCitizen instanceof EntityCitizen && entityCitizen.getCitizenJobHandler().getColonyJob() != null) {
            final AbstractEntityAIBasic basic = ((AbstractEntityAIBasic) entityCitizen.getCitizenJobHandler().getColonyJob().getWorkerAI());
            basic.setWalkTo(targetPos);
            basic.registerTarget(new AIOneTimeEventTarget(AIWorkerState.WALK_TO));
        } else {
            entityCitizen.getNavigation().moveTo(targetPos.getX(), targetPos.getY(), targetPos.getZ(), 1f);
        }
    }
    return 1;
}
Also used : Entity(net.minecraft.entity.Entity) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) AIOneTimeEventTarget(com.minecolonies.api.entity.ai.statemachine.AIOneTimeEventTarget) IColony(com.minecolonies.api.colony.IColony) ICitizenData(com.minecolonies.api.colony.ICitizenData) ILocationArgument(net.minecraft.command.arguments.ILocationArgument) BlockPos(net.minecraft.util.math.BlockPos) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) AbstractEntityAIBasic(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIBasic)

Example 22 with EntityCitizen

use of com.minecolonies.coremod.entity.citizen.EntityCitizen in project minecolonies by ldtteam.

the class EntityAIWorkHealer method freeCure.

/**
 * Do free cure magic.
 *
 * @return the next state to go to.
 */
private IAIState freeCure() {
    if (currentPatient == null) {
        return DECIDE;
    }
    final ICitizenData data = getOwnBuilding().getColony().getCitizenManager().getCivilian(currentPatient.getId());
    if (data == null || !data.getEntity().isPresent() || !data.getEntity().get().getCitizenDiseaseHandler().isSick()) {
        currentPatient = null;
        return DECIDE;
    }
    final EntityCitizen citizen = (EntityCitizen) data.getEntity().get();
    if (walkToBlock(citizen.blockPosition())) {
        progressTicks = 0;
        return FREE_CURE;
    }
    progressTicks++;
    if (progressTicks < MAX_PROGRESS_TICKS) {
        Network.getNetwork().sendToTrackingEntity(new StreamParticleEffectMessage(worker.position().add(0, 2, 0), citizen.position(), ParticleTypes.HEART, progressTicks % MAX_PROGRESS_TICKS, MAX_PROGRESS_TICKS), worker);
        Network.getNetwork().sendToTrackingEntity(new CircleParticleEffectMessage(worker.position().add(0, 2, 0), ParticleTypes.HEART, progressTicks), worker);
        return getState();
    }
    progressTicks = 0;
    worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
    citizen.getCitizenDiseaseHandler().cure();
    currentPatient.setState(Patient.PatientState.TREATED);
    currentPatient = null;
    return DECIDE;
}
Also used : StreamParticleEffectMessage(com.minecolonies.coremod.network.messages.client.StreamParticleEffectMessage) ICitizenData(com.minecolonies.api.colony.ICitizenData) CircleParticleEffectMessage(com.minecolonies.coremod.network.messages.client.CircleParticleEffectMessage) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen)

Example 23 with EntityCitizen

use of com.minecolonies.coremod.entity.citizen.EntityCitizen in project minecolonies by ldtteam.

the class EntityAIWorkHealer method wander.

/**
 * Wander around in the colony from citizen to citizen.
 *
 * @return the next state to go to.
 */
private IAIState wander() {
    if (remotePatient == null || !remotePatient.getEntity().isPresent()) {
        return DECIDE;
    }
    final EntityCitizen citizen = (EntityCitizen) remotePatient.getEntity().get();
    if (walkToBlock(remotePatient.getEntity().get().blockPosition())) {
        return getState();
    }
    Network.getNetwork().sendToTrackingEntity(new CircleParticleEffectMessage(remotePatient.getEntity().get().position(), ParticleTypes.HEART, 1), worker);
    citizen.heal(citizen.getMaxHealth() - citizen.getHealth() - 5 - getOwnBuilding().getBuildingLevel());
    citizen.markDirty();
    worker.getCitizenExperienceHandler().addExperience(1);
    remotePatient = null;
    return START_WORKING;
}
Also used : CircleParticleEffectMessage(com.minecolonies.coremod.network.messages.client.CircleParticleEffectMessage) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen)

Example 24 with EntityCitizen

use of com.minecolonies.coremod.entity.citizen.EntityCitizen in project minecolonies by ldtteam.

the class EntityAIWorkHealer method requestCure.

/**
 * Request the cure for a given patient.
 *
 * @return the next state to go to.
 */
private IAIState requestCure() {
    if (currentPatient == null) {
        return DECIDE;
    }
    final ICitizenData data = getOwnBuilding().getColony().getCitizenManager().getCivilian(currentPatient.getId());
    if (data == null || !data.getEntity().isPresent() || !data.getEntity().get().getCitizenDiseaseHandler().isSick()) {
        currentPatient = null;
        return DECIDE;
    }
    final EntityCitizen citizen = (EntityCitizen) data.getEntity().get();
    if (walkToBlock(citizen.blockPosition())) {
        return REQUEST_CURE;
    }
    final String diseaseName = citizen.getCitizenDiseaseHandler().getDisease();
    if (diseaseName.isEmpty()) {
        currentPatient.setState(Patient.PatientState.REQUESTED);
        currentPatient = null;
        return DECIDE;
    }
    final ImmutableList<IRequest<? extends Stack>> list = getOwnBuilding().getOpenRequestsOfType(worker.getCitizenData().getId(), TypeToken.of(Stack.class));
    final ImmutableList<IRequest<? extends Stack>> completed = getOwnBuilding().getCompletedRequestsOfType(worker.getCitizenData(), TypeToken.of(Stack.class));
    for (final ItemStack cure : IColonyManager.getInstance().getCompatibilityManager().getDisease(diseaseName).getCure()) {
        if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), cure::sameItem) && !InventoryUtils.hasItemInItemHandler(getOwnBuilding().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElseGet(null), cure::sameItem)) {
            boolean hasRequest = false;
            for (final IRequest<? extends Stack> request : list) {
                if (request.getRequest().getStack().sameItem(cure)) {
                    hasRequest = true;
                    break;
                }
            }
            for (final IRequest<? extends Stack> request : completed) {
                if (request.getRequest().getStack().sameItem(cure)) {
                    hasRequest = true;
                    break;
                }
            }
            if (!hasRequest) {
                worker.getCitizenData().createRequestAsync(new Stack(cure, REQUEST_COUNT, 1));
            }
        }
    }
    currentPatient.setState(Patient.PatientState.REQUESTED);
    currentPatient = null;
    return DECIDE;
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) ItemStack(net.minecraft.item.ItemStack) ItemStack(net.minecraft.item.ItemStack) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack)

Aggregations

EntityCitizen (com.minecolonies.coremod.entity.citizen.EntityCitizen)24 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)18 ICitizenData (com.minecolonies.api.colony.ICitizenData)12 ItemStack (net.minecraft.item.ItemStack)10 BlockPos (net.minecraft.util.math.BlockPos)10 NotNull (org.jetbrains.annotations.NotNull)10 CircleParticleEffectMessage (com.minecolonies.coremod.network.messages.client.CircleParticleEffectMessage)8 PlayerEntity (net.minecraft.entity.player.PlayerEntity)8 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)6 Stack (com.minecolonies.api.colony.requestsystem.requestable.Stack)6 Network (com.minecolonies.coremod.Network)6 AbstractJobGuard (com.minecolonies.coremod.colony.jobs.AbstractJobGuard)6 StreamParticleEffectMessage (com.minecolonies.coremod.network.messages.client.StreamParticleEffectMessage)6 IItemHandler (net.minecraftforge.items.IItemHandler)6 Nullable (org.jetbrains.annotations.Nullable)6 ImmutableList (com.google.common.collect.ImmutableList)4 TypeToken (com.google.common.reflect.TypeToken)4 IColony (com.minecolonies.api.colony.IColony)4 IColonyManager (com.minecolonies.api.colony.IColonyManager)4 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)4