use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class BuildingCombatAcademy method getCombatPartner.
/**
* Get the citizen of the combat partner or null if not existing or available.
*
* @param citizen the citizen.
* @return the citizen or null.
*/
public AbstractEntityCitizen getCombatPartner(final AbstractEntityCitizen citizen) {
final ICitizenData data = citizen.getCitizenData();
if (data != null) {
final int citizenId;
if (trainingPartners.containsKey(data.getId())) {
citizenId = trainingPartners.get(data.getId());
} else if (trainingPartners.containsValue(data.getId())) {
citizenId = trainingPartners.inverse().get(data.getId());
} else {
return null;
}
final ICitizenData citizenData = getFirstModuleOccurance(WorkAtHomeBuildingModule.class).getAssignedCitizen().stream().filter(cit -> cit.getId() != data.getId()).filter(cit -> cit.getId() == citizenId).findFirst().orElse(null);
if (citizenData != null) {
return citizenData.getEntity().orElse(null);
}
}
return null;
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class PublicWorkerCraftingProductionResolver method removeRequestFromTaskList.
private void removeRequestFromTaskList(@NotNull final IRequest<? extends PublicCrafting> completedRequest, final IColony colony) {
final ICitizenData holdingCrafter = colony.getCitizenManager().getCitizens().stream().filter(c -> c.getJob() instanceof AbstractJobCrafter && (((AbstractJobCrafter<?, ?>) c.getJob()).getTaskQueue().contains(completedRequest.getId()) || ((AbstractJobCrafter<?, ?>) c.getJob()).getAssignedTasks().contains(completedRequest.getId()))).findFirst().orElse(null);
if (holdingCrafter != null) {
final AbstractJobCrafter<?, ?> job = (AbstractJobCrafter<?, ?>) holdingCrafter.getJob();
job.onTaskDeletion(completedRequest.getId());
}
}
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) {
// TODO: In 1.19 remove this method call as this is purely for backwards compatibility with old class mappings
migrateOldNbt(compound, manager);
id = compound.getInt(TAG_ID);
if (compound.contains(TAG_TH_PRIORITY)) {
priority = compound.getInt(TAG_TH_PRIORITY);
}
if (compound.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.contains(TAG_CLAIMED_BY_BUILDING)) {
claimedBy = BlockPosUtil.read(compound, TAG_CLAIMED_BY_BUILDING);
}
structureName = compound.getString(TAG_STRUCTURE_NAME);
workOrderName = compound.getString(TAG_WO_NAME);
workOrderType = WorkOrderType.values()[compound.getInt(TAG_WO_TYPE)];
location = BlockPosUtil.read(compound, TAG_LOCATION);
rotation = compound.getInt(TAG_ROTATION);
isMirrored = compound.getBoolean(TAG_IS_MIRRORED);
currentLevel = compound.getInt(TAG_CURRENT_LEVEL);
targetLevel = compound.getInt(TAG_TARGET_LEVEL);
amountOfResources = compound.getInt(TAG_AMOUNT_OF_RESOURCES);
iteratorType = compound.getString(TAG_ITERATOR);
cleared = compound.getBoolean(TAG_IS_CLEARED);
requested = compound.getBoolean(TAG_IS_REQUESTED);
}
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;
}
return Lists.newArrayList();
}
Aggregations