Search in sources :

Example 6 with PublicCrafting

use of com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting 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());
}
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 PublicCrafting

use of com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting 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 8 with PublicCrafting

use of com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting 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)

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