use of com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting 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.api.colony.requestsystem.requestable.crafting.PublicCrafting 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.api.colony.requestsystem.requestable.crafting.PublicCrafting in project minecolonies by ldtteam.
the class AbstractEntityAICrafting method getRecipe.
/**
* Query the IRecipeStorage of the first request in the queue.
*
* @return the next state to go to.
*/
protected IAIState getRecipe() {
final IRequest<? extends PublicCrafting> currentTask = job.getCurrentTask();
if (currentTask == null) {
return START_WORKING;
}
final ICraftingBuildingModule module = getOwnBuilding().getCraftingModuleForRecipe(currentTask.getRequest().getRecipeID());
if (module == null) {
job.finishRequest(false);
incrementActionsDone(getActionRewardForCraftingSuccess());
return START_WORKING;
}
currentRecipeStorage = module.getFirstFulfillableRecipe(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, currentTask.getRequest().getStack()), 1, false);
if (currentRecipeStorage == null) {
job.finishRequest(false);
incrementActionsDone(getActionRewardForCraftingSuccess());
return START_WORKING;
}
currentRequest = currentTask;
job.setMaxCraftingCount(currentRequest.getRequest().getCount());
final int currentCount = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, currentRecipeStorage.getPrimaryOutput()));
final int inProgressCount = getExtendedCount(currentRecipeStorage.getPrimaryOutput());
final int countPerIteration = currentRecipeStorage.getPrimaryOutput().getCount();
final int doneOpsCount = currentCount / countPerIteration;
final int progressOpsCount = inProgressCount / countPerIteration;
final int remainingOpsCount = currentRequest.getRequest().getCount() - doneOpsCount - progressOpsCount;
final List<ItemStorage> input = currentRecipeStorage.getCleanedInput();
for (final ItemStorage inputStorage : input) {
final ItemStack container = inputStorage.getItem().getContainerItem(inputStorage.getItemStack());
final int remaining;
if (!currentRecipeStorage.getCraftingToolsAndSecondaryOutputs().isEmpty() && ItemStackUtils.compareItemStackListIgnoreStackSize(currentRecipeStorage.getCraftingToolsAndSecondaryOutputs(), inputStorage.getItemStack(), false, true)) {
remaining = inputStorage.getAmount();
} else if (!ItemStackUtils.isEmpty(container) && ItemStackUtils.compareItemStacksIgnoreStackSize(inputStorage.getItemStack(), container, false, true)) {
remaining = inputStorage.getAmount();
} else {
remaining = inputStorage.getAmount() * remainingOpsCount;
}
if (InventoryUtils.getCountFromBuilding(getOwnBuilding(), itemStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, inputStorage.getItemStack(), false, true)) + InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), itemStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, inputStorage.getItemStack(), false, true)) + getExtendedCount(inputStorage.getItemStack()) < remaining) {
job.finishRequest(false);
incrementActionsDone(getActionRewardForCraftingSuccess());
return START_WORKING;
}
}
job.setCraftCounter(doneOpsCount);
return QUERY_ITEMS;
}
use of com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting in project minecolonies by Minecolonies.
the class AbstractEntityAICrafting method getRecipe.
/**
* Query the IRecipeStorage of the first request in the queue.
*
* @return the next state to go to.
*/
protected IAIState getRecipe() {
final IRequest<? extends PublicCrafting> currentTask = job.getCurrentTask();
if (currentTask == null) {
return START_WORKING;
}
final ICraftingBuildingModule module = getOwnBuilding().getCraftingModuleForRecipe(currentTask.getRequest().getRecipeID());
if (module == null) {
job.finishRequest(false);
incrementActionsDone(getActionRewardForCraftingSuccess());
return START_WORKING;
}
currentRecipeStorage = module.getFirstFulfillableRecipe(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, currentTask.getRequest().getStack()), 1, false);
if (currentRecipeStorage == null) {
job.finishRequest(false);
incrementActionsDone(getActionRewardForCraftingSuccess());
return START_WORKING;
}
currentRequest = currentTask;
job.setMaxCraftingCount(currentRequest.getRequest().getCount());
final int currentCount = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, currentRecipeStorage.getPrimaryOutput()));
final int inProgressCount = getExtendedCount(currentRecipeStorage.getPrimaryOutput());
final int countPerIteration = currentRecipeStorage.getPrimaryOutput().getCount();
final int doneOpsCount = currentCount / countPerIteration;
final int progressOpsCount = inProgressCount / countPerIteration;
final int remainingOpsCount = currentRequest.getRequest().getCount() - doneOpsCount - progressOpsCount;
final List<ItemStorage> input = currentRecipeStorage.getCleanedInput();
for (final ItemStorage inputStorage : input) {
final ItemStack container = inputStorage.getItem().getContainerItem(inputStorage.getItemStack());
final int remaining;
if (!currentRecipeStorage.getCraftingToolsAndSecondaryOutputs().isEmpty() && ItemStackUtils.compareItemStackListIgnoreStackSize(currentRecipeStorage.getCraftingToolsAndSecondaryOutputs(), inputStorage.getItemStack(), false, true)) {
remaining = inputStorage.getAmount();
} else if (!ItemStackUtils.isEmpty(container) && ItemStackUtils.compareItemStacksIgnoreStackSize(inputStorage.getItemStack(), container, false, true)) {
remaining = inputStorage.getAmount();
} else {
remaining = inputStorage.getAmount() * remainingOpsCount;
}
if (InventoryUtils.getCountFromBuilding(getOwnBuilding(), itemStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, inputStorage.getItemStack(), false, true)) + InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), itemStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, inputStorage.getItemStack(), false, true)) + getExtendedCount(inputStorage.getItemStack()) < remaining) {
job.finishRequest(false);
incrementActionsDone(getActionRewardForCraftingSuccess());
return START_WORKING;
}
}
job.setCraftCounter(doneOpsCount);
return QUERY_ITEMS;
}
use of com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting 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());
}
Aggregations