use of com.minecolonies.coremod.colony.jobs.AbstractJobCrafter in project minecolonies by Minecolonies.
the class AbstractCraftingBuildingModule method getPendingRequestQueue.
/**
* Get a list of all recipeStorages of the pending requests in the crafters queues.
* @return the list.
*/
private List<Tuple<IRecipeStorage, Integer>> getPendingRequestQueue() {
final List<Tuple<IRecipeStorage, Integer>> recipes = new ArrayList<>();
for (final ICitizenData citizen : building.getAllAssignedCitizen()) {
if (citizen.getJob() instanceof AbstractJobCrafter) {
final List<IToken<?>> assignedTasks = new ArrayList<>(citizen.getJob(AbstractJobCrafter.class).getAssignedTasks());
assignedTasks.addAll(citizen.getJob(AbstractJobCrafter.class).getTaskQueue());
for (final IToken<?> taskToken : assignedTasks) {
final IRequest<? extends PublicCrafting> request = (IRequest<? extends PublicCrafting>) building.getColony().getRequestManager().getRequestForToken(taskToken);
final IRecipeStorage recipeStorage = IColonyManager.getInstance().getRecipeManager().getRecipes().get(request.getRequest().getRecipeID());
if (holdsRecipe(request.getRequest().getRecipeID()) && recipeStorage != null) {
recipes.add(new Tuple<>(recipeStorage, request.getRequest().getCount()));
}
}
}
}
return recipes;
}
use of com.minecolonies.coremod.colony.jobs.AbstractJobCrafter 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.coremod.colony.jobs.AbstractJobCrafter in project minecolonies by ldtteam.
the class AbstractCraftingBuildingModule method getPendingRequestQueue.
/**
* Get a list of all recipeStorages of the pending requests in the crafters queues.
* @return the list.
*/
private List<Tuple<IRecipeStorage, Integer>> getPendingRequestQueue() {
final List<Tuple<IRecipeStorage, Integer>> recipes = new ArrayList<>();
for (final ICitizenData citizen : building.getAllAssignedCitizen()) {
if (citizen.getJob() instanceof AbstractJobCrafter) {
final List<IToken<?>> assignedTasks = new ArrayList<>(citizen.getJob(AbstractJobCrafter.class).getAssignedTasks());
assignedTasks.addAll(citizen.getJob(AbstractJobCrafter.class).getTaskQueue());
for (final IToken<?> taskToken : assignedTasks) {
final IRequest<? extends PublicCrafting> request = (IRequest<? extends PublicCrafting>) building.getColony().getRequestManager().getRequestForToken(taskToken);
final IRecipeStorage recipeStorage = IColonyManager.getInstance().getRecipeManager().getRecipes().get(request.getRequest().getRecipeID());
if (holdsRecipe(request.getRequest().getRecipeID()) && recipeStorage != null) {
recipes.add(new Tuple<>(recipeStorage, request.getRequest().getCount()));
}
}
}
}
return recipes;
}
use of com.minecolonies.coremod.colony.jobs.AbstractJobCrafter in project minecolonies by Minecolonies.
the class PublicWorkerCraftingProductionResolver method onAssignedToThisResolverForBuilding.
@Override
protected void onAssignedToThisResolverForBuilding(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends PublicCrafting> request, final boolean simulation, @NotNull final AbstractBuilding building) {
if (manager.getColony().getWorld().isClientSide) {
return;
}
final ICitizenData freeCrafter = building.getModuleMatching(CraftingWorkerBuildingModule.class, m -> m.getJobEntry() == getJobEntry()).getAssignedCitizen().stream().filter(c -> c.getJob() instanceof AbstractJobCrafter).min(Comparator.comparing((ICitizenData c) -> ((AbstractJobCrafter<?, ?>) c.getJob()).getTaskQueue().size() + ((AbstractJobCrafter<?, ?>) c.getJob()).getAssignedTasks().size())).orElse(null);
if (freeCrafter == null) {
onAssignedRequestBeingCancelled(manager, request);
return;
}
final AbstractJobCrafter<?, ?> job = (AbstractJobCrafter<?, ?>) freeCrafter.getJob();
job.onTaskBeingScheduled(request.getId());
}
use of com.minecolonies.coremod.colony.jobs.AbstractJobCrafter in project minecolonies by Minecolonies.
the class PublicWorkerCraftingProductionResolver method resolveForBuilding.
@Override
public void resolveForBuilding(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends PublicCrafting> request, @NotNull final AbstractBuilding building) {
if (manager.getColony().getWorld().isClientSide) {
return;
}
final ICitizenData freeCrafter = building.getModuleMatching(CraftingWorkerBuildingModule.class, m -> m.getJobEntry() == getJobEntry()).getAssignedCitizen().stream().filter(c -> c.getJob() instanceof AbstractJobCrafter && ((AbstractJobCrafter<?, ?>) c.getJob()).getAssignedTasks().contains(request.getId())).findFirst().orElse(null);
if (freeCrafter == null) {
onAssignedRequestBeingCancelled(manager, request);
return;
}
final AbstractJobCrafter<?, ?> job = (AbstractJobCrafter<?, ?>) freeCrafter.getJob();
job.onTaskBeingResolved(request.getId());
}
Aggregations