Search in sources :

Example 6 with AbstractJobCrafter

use of com.minecolonies.coremod.colony.jobs.AbstractJobCrafter in project minecolonies by ldtteam.

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());
}
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)

Example 7 with AbstractJobCrafter

use of com.minecolonies.coremod.colony.jobs.AbstractJobCrafter in project minecolonies by ldtteam.

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)

Example 8 with AbstractJobCrafter

use of com.minecolonies.coremod.colony.jobs.AbstractJobCrafter in project minecolonies by ldtteam.

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());
    }
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData) AbstractJobCrafter(com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)

Aggregations

ICitizenData (com.minecolonies.api.colony.ICitizenData)8 AbstractJobCrafter (com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)8 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)6 PublicCrafting (com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting)6 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)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 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)4 CraftingWorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.CraftingWorkerBuildingModule)4 WorkerBuildingModuleView (com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView)4 AbstractCraftingProductionResolver (com.minecolonies.coremod.colony.requestsystem.resolvers.core.AbstractCraftingProductionResolver)4 Comparator (java.util.Comparator)4