use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class DeliverymenRequestResolver method attemptResolveRequest.
@Nullable
@Override
public List<IToken<?>> attemptResolveRequest(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends R> request) {
if (manager.getColony().getWorld().isClientSide) {
return null;
}
ICitizenData chosenCourier = null;
Tuple<Double, Integer> bestScore = null;
for (final ICitizenData citizen : getResolveAbleDeliverymen(manager)) {
if (citizen.isWorking()) {
Tuple<Double, Integer> localScore = ((JobDeliveryman) citizen.getJob()).getScoreForDelivery(request);
if (bestScore == null || localScore.getA() < bestScore.getA()) {
bestScore = localScore;
chosenCourier = citizen;
}
}
}
if (chosenCourier == null) {
return null;
}
final JobDeliveryman job = (JobDeliveryman) chosenCourier.getJob();
job.addRequest(request.getId(), bestScore.getB());
return Lists.newArrayList();
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class StandardPlayerRequestResolver method resolveRequest.
@Override
public void resolveRequest(@NotNull final IRequestManager manager, @NotNull final IRequest<?> request) throws RuntimeException {
final IColony colony = manager.getColony();
if (colony instanceof Colony) {
if (MinecoloniesAPIProxy.getInstance().getConfig().getServer().creativeResolve.get() && request.getRequest() instanceof IDeliverable && request.getRequester() instanceof BuildingBasedRequester && ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getId()).isPresent() && ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getId()).get() instanceof AbstractBuilding) {
final AbstractBuilding building = (AbstractBuilding) ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getId()).get();
final Optional<ICitizenData> citizenDataOptional = building.getCitizenForRequest(request.getId());
final List<ItemStack> resolvablestacks = request.getDisplayStacks();
if (!resolvablestacks.isEmpty() && citizenDataOptional.isPresent()) {
final ItemStack resolveStack = resolvablestacks.get(0);
resolveStack.setCount(Math.min(((IDeliverable) request.getRequest()).getCount(), resolveStack.getMaxStackSize()));
final ItemStack remainingItemStack = InventoryUtils.addItemStackToItemHandlerWithResult(citizenDataOptional.get().getInventory(), resolveStack);
if (ItemStackUtils.isEmpty(remainingItemStack)) {
manager.updateRequestState(request.getId(), RequestState.RESOLVED);
return;
}
}
}
}
assignedRequests.add(request.getId());
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class AbstractWorkOrder method read.
/**
* Read the WorkOrder data from the CompoundNBT.
*
* @param compound NBT Tag compound
* @param manager the workManager calling this method.
*/
@Override
public void read(@NotNull final CompoundNBT compound, final IWorkManager manager) {
id = compound.getInt(TAG_ID);
if (compound.getAllKeys().contains(TAG_TH_PRIORITY)) {
priority = compound.getInt(TAG_TH_PRIORITY);
}
if (compound.getAllKeys().contains(TAG_CLAIMED_BY)) {
final int citizenId = compound.getInt(TAG_CLAIMED_BY);
if (manager.getColony() != null) {
final ICitizenData data = manager.getColony().getCitizenManager().getCivilian(citizenId);
if (data != null && data.getWorkBuilding() != null) {
claimedBy = data.getWorkBuilding().getPosition();
}
}
} else if (compound.getAllKeys().contains(TAG_CLAIMED_BY_BUILDING)) {
claimedBy = BlockPosUtil.read(compound, TAG_CLAIMED_BY_BUILDING);
}
buildingLocation = BlockPosUtil.read(compound, TAG_BUILDING);
iteratorType = compound.getString(TAG_ITERATOR);
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class CommandCitizenKill 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) {
// 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(LanguageHandler.buildChatComponent("com.minecolonies.command.colonyidnotfound", colonyID), true);
return 0;
}
if (!context.getSource().hasPermission(OP_PERM_LEVEL) && !MineColonies.getConfig().getServer().canPlayerUseKillCitizensCommand.get()) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.notenabledinconfig"), 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;
}
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.desc", citizenData.getId(), citizenData.getName()), true);
final BlockPos position = optionalEntityCitizen.get().blockPosition();
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.pos", position.getX(), position.getY(), position.getZ()), true);
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizenkill.success", position.getX(), position.getY(), position.getZ()), true);
optionalEntityCitizen.get().die(CONSOLE_DAMAGE_SOURCE);
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(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;
}
Aggregations