Search in sources :

Example 51 with ICitizenData

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

the class AbstractEntityAIBasic method dumpInventory.

/**
 * Walk to building and dump inventory. If inventory is dumped, continue execution so that the state can be resolved.
 *
 * @return INVENTORY_FULL | IDLE
 */
@NotNull
private IAIState dumpInventory() {
    final IBuilding building = getBuildingToDump();
    if (building == null) {
        // Uh oh, that shouldn't happen. Restart AI.
        return afterDump();
    }
    if (!worker.isWorkerAtSiteWithMove(building.getPosition(), DEFAULT_RANGE_FOR_DELAY)) {
        setDelay(WALK_DELAY);
        return INVENTORY_FULL;
    }
    if (InventoryUtils.isProviderFull(building)) {
        final ICitizenData citizenData = worker.getCitizenData();
        if (citizenData != null) {
            citizenData.triggerInteraction(new StandardInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_WORKER_INVENTORYFULLCHEST), ChatPriority.IMPORTANT));
        }
        // Note that this will not create a pickup request when another request is already in progress.
        if (building.getPickUpPriority() > 0) {
            building.createPickupRequest(getMaxBuildingPriority(true));
            hasDumpedItems = false;
        }
        alreadyKept.clear();
        slotAt = 0;
        this.clearActionsDone();
        return afterDump();
    } else if (dumpOneMoreSlot()) {
        return INVENTORY_FULL;
    }
    alreadyKept.clear();
    slotAt = 0;
    this.clearActionsDone();
    if (isAfterDumpPickupAllowed() && building.getPickUpPriority() > 0 && hasDumpedItems) {
        // Worker is not currently crafting, pickup is allowed.
        // Note that this will not create a pickup request when another request is already in progress.
        building.createPickupRequest(scaledPriority(building.getPickUpPriority()));
        hasDumpedItems = false;
    }
    return afterDump();
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) ICitizenData(com.minecolonies.api.colony.ICitizenData) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) NotNull(org.jetbrains.annotations.NotNull)

Example 52 with ICitizenData

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

the class CommandCitizenList method drawCitizens.

private void drawCitizens(@NotNull final CommandContext<CommandSource> context, final List<ICitizenData> citizensPage) {
    for (final ICitizenData citizen : citizensPage) {
        context.getSource().sendSuccess(new TranslationTextComponent(COMMAND_CITIZEN_INFO, citizen.getId(), citizen.getName()).setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format(COMMAND_CITIZEN_INFO_SUGGESTED, citizen.getColony().getID(), citizen.getId())))), true);
        citizen.getEntity().ifPresent(entityCitizen -> {
            final BlockPos position = entityCitizen.blockPosition();
            context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_INFO_POSITION, position.getX(), position.getY(), position.getZ()), true);
        });
    }
}
Also used : ClickEvent(net.minecraft.util.text.event.ClickEvent) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos)

Example 53 with ICitizenData

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

the class CommandCitizenList method displayListFor.

private int displayListFor(final CommandContext<CommandSource> context, int page) {
    // Colony
    final int colonyID = IntegerArgumentType.getInteger(context, COLONYID_ARG);
    final IColony colony = IColonyManager.getInstance().getColonyByDimension(colonyID, context.getSource().getLevel().dimension());
    if (colony == null) {
        context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_COLONY_ID_NOT_FOUND, colonyID), true);
        return 0;
    }
    final List<ICitizenData> citizens = colony.getCitizenManager().getCitizens();
    final int citizenCount = citizens.size();
    // check to see if we have to add one page to show the half page
    final int halfPage = (citizenCount % CITIZENS_ON_PAGE == 0) ? 0 : 1;
    final int pageCount = ((citizenCount) / CITIZENS_ON_PAGE) + halfPage;
    if (page < 1 || page > pageCount) {
        page = 1;
    }
    final int pageStartIndex = CITIZENS_ON_PAGE * (page - 1);
    final int pageStopIndex = Math.min(CITIZENS_ON_PAGE * page, citizenCount);
    final List<ICitizenData> citizensPage = getCitizensOnPage(citizens, citizenCount, pageStartIndex, pageStopIndex);
    final ITextComponent headerLine = new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_LIST_PAGE_TOP, page, pageCount);
    context.getSource().sendSuccess(headerLine, true);
    drawCitizens(context, citizensPage);
    drawPageSwitcher(context, page, citizenCount, halfPage, colony.getID());
    return 1;
}
Also used : IColony(com.minecolonies.api.colony.IColony) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 54 with ICitizenData

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

the class CommandCitizenTrack 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();
    if (!(sender instanceof PlayerEntity)) {
        return 1;
    }
    // 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(new TranslationTextComponent(CommandTranslationConstants.COMMAND_COLONY_ID_NOT_FOUND, colonyID), true);
        return 0;
    }
    final ICitizenData citizenData = colony.getCitizenManager().getCivilian(IntegerArgumentType.getInteger(context, CITIZENID_ARG));
    if (citizenData == null) {
        context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_NOT_FOUND), true);
        return 0;
    }
    final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
    if (!optionalEntityCitizen.isPresent()) {
        context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_NOT_LOADED), true);
        return 0;
    }
    final AbstractEntityCitizen entityCitizen = optionalEntityCitizen.get();
    if (AbstractPathJob.trackingMap.getOrDefault((PlayerEntity) sender, UUID.randomUUID()).equals(entityCitizen.getUUID())) {
        context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_ENTITY_TRACK_DISABLED), true);
        AbstractPathJob.trackingMap.remove((PlayerEntity) sender);
        Network.getNetwork().sendToPlayer(new SyncPathMessage(new HashSet<>(), new HashSet<>(), new HashSet<>()), (ServerPlayerEntity) sender);
    } else {
        context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_ENTITY_TRACK_ENABLED), true);
        AbstractPathJob.trackingMap.put((PlayerEntity) sender, entityCitizen.getUUID());
    }
    return 1;
}
Also used : Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SyncPathMessage(com.minecolonies.coremod.network.messages.client.SyncPathMessage) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) IColony(com.minecolonies.api.colony.IColony) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ICitizenData(com.minecolonies.api.colony.ICitizenData) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) HashSet(java.util.HashSet)

Example 55 with ICitizenData

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

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(new TranslationTextComponent(CommandTranslationConstants.COMMAND_COLONY_ID_NOT_FOUND, colonyID), true);
        return 0;
    }
    final ICitizenData citizenData = colony.getCitizenManager().getCivilian(IntegerArgumentType.getInteger(context, CITIZENID_ARG));
    if (citizenData == null) {
        context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_NOT_FOUND), true);
        return 0;
    }
    final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
    if (!optionalEntityCitizen.isPresent()) {
        context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_NOT_LOADED), 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) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) 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)

Aggregations

ICitizenData (com.minecolonies.api.colony.ICitizenData)180 NotNull (org.jetbrains.annotations.NotNull)49 BlockPos (net.minecraft.util.math.BlockPos)47 IColony (com.minecolonies.api.colony.IColony)46 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)40 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)33 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)31 ItemStack (net.minecraft.item.ItemStack)28 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)23 PlayerEntity (net.minecraft.entity.player.PlayerEntity)23 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)22 Nullable (org.jetbrains.annotations.Nullable)22 CompoundNBT (net.minecraft.nbt.CompoundNBT)18 Colony (com.minecolonies.coremod.colony.Colony)16 ArrayList (java.util.ArrayList)16 AbstractJobCrafter (com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)14 EntityCitizen (com.minecolonies.coremod.entity.citizen.EntityCitizen)14 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)13 AbstractAssignedCitizenModule (com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule)12 java.util (java.util)12