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();
}
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);
});
}
}
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;
}
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;
}
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;
}
Aggregations