Search in sources :

Example 1 with PublicCrafting

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;
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) PublicCrafting(com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) Tuple(net.minecraft.util.Tuple) AbstractJobCrafter(com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)

Example 2 with PublicCrafting

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;
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) PublicCrafting(com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) Tuple(net.minecraft.util.Tuple) AbstractJobCrafter(com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)

Example 3 with PublicCrafting

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;
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) AbstractJobCrafter(com.minecolonies.coremod.colony.jobs.AbstractJobCrafter) ItemStack(net.minecraft.item.ItemStack) AbstractAdvancedPathNavigate(com.minecolonies.api.entity.pathfinding.AbstractAdvancedPathNavigate) LootContext(net.minecraft.loot.LootContext) Tuple(com.minecolonies.api.util.Tuple) ImmutableList(com.google.common.collect.ImmutableList) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) CraftingWorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.CraftingWorkerBuildingModule) Hand(net.minecraft.util.Hand) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) Log(com.minecolonies.api.util.Log) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack) RecipeStorage(com.minecolonies.api.crafting.RecipeStorage) Predicate(java.util.function.Predicate) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule) RequestState(com.minecolonies.api.colony.requestsystem.request.RequestState) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) LootParameters(net.minecraft.loot.LootParameters) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) DamageSource(net.minecraft.util.DamageSource) FakePlayerFactory(net.minecraftforge.common.util.FakePlayerFactory) DEFAULT_SPEED(com.minecolonies.api.util.constant.Constants.DEFAULT_SPEED) List(java.util.List) PublicCrafting(com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting) InventoryUtils(com.minecolonies.api.util.InventoryUtils) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) FakePlayer(net.minecraftforge.common.util.FakePlayer) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule) ItemStack(net.minecraft.item.ItemStack) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 4 with PublicCrafting

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;
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) AbstractJobCrafter(com.minecolonies.coremod.colony.jobs.AbstractJobCrafter) ItemStack(net.minecraft.item.ItemStack) AbstractAdvancedPathNavigate(com.minecolonies.api.entity.pathfinding.AbstractAdvancedPathNavigate) LootContext(net.minecraft.loot.LootContext) Tuple(com.minecolonies.api.util.Tuple) ImmutableList(com.google.common.collect.ImmutableList) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) CraftingWorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.CraftingWorkerBuildingModule) Hand(net.minecraft.util.Hand) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack) RecipeStorage(com.minecolonies.api.crafting.RecipeStorage) Predicate(java.util.function.Predicate) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule) RequestState(com.minecolonies.api.colony.requestsystem.request.RequestState) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) LootParameters(net.minecraft.loot.LootParameters) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) DamageSource(net.minecraft.util.DamageSource) FakePlayerFactory(net.minecraftforge.common.util.FakePlayerFactory) DEFAULT_SPEED(com.minecolonies.api.util.constant.Constants.DEFAULT_SPEED) List(java.util.List) PublicCrafting(com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting) InventoryUtils(com.minecolonies.api.util.InventoryUtils) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) FakePlayer(net.minecraftforge.common.util.FakePlayer) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule) ItemStack(net.minecraft.item.ItemStack) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 5 with PublicCrafting

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());
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) AbstractDeliverymanRequestable.getDefaultDeliveryPriority(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.AbstractDeliverymanRequestable.getDefaultDeliveryPriority) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) ICitizenData(com.minecolonies.api.colony.ICitizenData) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent) AbstractJobCrafter(com.minecolonies.coremod.colony.jobs.AbstractJobCrafter) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) Lists(com.google.common.collect.Lists) CraftingWorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.CraftingWorkerBuildingModule) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) Delivery(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.Delivery) IRequester(com.minecolonies.api.colony.requestsystem.requester.IRequester) Colony(com.minecolonies.coremod.colony.Colony) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) WorkerBuildingModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView) AbstractCraftingProductionResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.core.AbstractCraftingProductionResolver) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) PublicCrafting(com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting) IColony(com.minecolonies.api.colony.IColony) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) ICitizenData(com.minecolonies.api.colony.ICitizenData) CraftingWorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.CraftingWorkerBuildingModule) AbstractJobCrafter(com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)

Aggregations

IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)8 PublicCrafting (com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting)8 AbstractJobCrafter (com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)8 ICitizenData (com.minecolonies.api.colony.ICitizenData)6 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)6 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)6 CraftingWorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.CraftingWorkerBuildingModule)6 List (java.util.List)6 ItemStack (net.minecraft.item.ItemStack)6 NotNull (org.jetbrains.annotations.NotNull)6 Lists (com.google.common.collect.Lists)4 IColony (com.minecolonies.api.colony.IColony)4 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)4 JobEntry (com.minecolonies.api.colony.jobs.registry.JobEntry)4 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)4 IRequestManager (com.minecolonies.api.colony.requestsystem.manager.IRequestManager)4 AbstractDeliverymanRequestable.getDefaultDeliveryPriority (com.minecolonies.api.colony.requestsystem.requestable.deliveryman.AbstractDeliverymanRequestable.getDefaultDeliveryPriority)4 Delivery (com.minecolonies.api.colony.requestsystem.requestable.deliveryman.Delivery)4 IRequester (com.minecolonies.api.colony.requestsystem.requester.IRequester)4 Colony (com.minecolonies.coremod.colony.Colony)4