Search in sources :

Example 16 with IRequest

use of com.minecolonies.api.colony.requestsystem.request.IRequest in project minecolonies by Minecolonies.

the class AbstractBuildingDependentRequestResolver method resolve.

@Override
public void resolve(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends R> request) {
    final AbstractBuilding building = getBuilding(manager, request.getToken()).map(r -> (AbstractBuilding) r).get();
    resolveForBuilding(manager, request, building);
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) IRequester(com.minecolonies.api.colony.requestsystem.requester.IRequester) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) IRequestable(com.minecolonies.api.colony.requestsystem.requestable.IRequestable) RequestHandler(com.minecolonies.coremod.colony.requestsystem.management.handlers.RequestHandler) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) BuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester) IBuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.IBuildingBasedRequester) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 17 with IRequest

use of com.minecolonies.api.colony.requestsystem.request.IRequest in project minecolonies by Minecolonies.

the class AbstractBuildingDependentRequestResolver method getBuilding.

@Override
@Nullable
public Optional<IRequester> getBuilding(@NotNull final IRequestManager manager, @NotNull final IToken<?> token) {
    final IRequest request = manager.getRequestForToken(token);
    if (request.getRequester() instanceof BuildingBasedRequester) {
        final BuildingBasedRequester requester = (BuildingBasedRequester) request.getRequester();
        final ILocation requesterLocation = requester.getRequesterLocation();
        if (requesterLocation.equals(getRequesterLocation())) {
            return requester.getBuilding(manager, token);
        }
    }
    return Optional.empty();
}
Also used : BuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester) IBuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.IBuildingBasedRequester) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with IRequest

use of com.minecolonies.api.colony.requestsystem.request.IRequest in project minecolonies by Minecolonies.

the class RequestHandler method reassignRequest.

/**
 * Method used to reassign the request to a resolver that is not in the given blacklist.
 * Cancels the request internally without notify the requester, and attempts a reassign. If the reassignment failed, it is assigned back to the orignal resolver.
 *
 * @param manager                The manager that is reassigning a request.
 * @param request                The request that is being reassigned.
 * @param resolverTokenBlackList The blacklist to which not to assign the request.
 * @return The token of the resolver that has gotten the request assigned, null if none was found.
 *
 * @throws IllegalArgumentException Thrown when something went wrong.
 */
public static IToken<?> reassignRequest(final IStandardRequestManager manager, final IRequest<?> request, final Collection<IToken<?>> resolverTokenBlackList) {
    // Get the current resolver
    IRequestResolver currentResolver = null;
    if (RequestHandler.isAssigned(manager, request.getToken())) {
        currentResolver = ResolverHandler.getResolverForRequest(manager, request);
    }
    IToken<?> parent = null;
    if (request.hasParent()) {
        parent = request.getParent();
    }
    // Cancel the request to restart the search
    processInternalCancellation(manager, request.getToken());
    if (currentResolver != null) {
        if (manager.getRequestResolverRequestAssignmentDataStore().getAssignments().containsKey(currentResolver.getRequesterId())) {
            manager.getRequestResolverRequestAssignmentDataStore().getAssignments().get(currentResolver.getRequesterId()).remove(request.getToken());
            if (manager.getRequestResolverRequestAssignmentDataStore().getAssignments().get(currentResolver.getRequesterId()).isEmpty()) {
                manager.getRequestResolverRequestAssignmentDataStore().getAssignments().remove(currentResolver.getRequesterId());
            }
        }
    }
    manager.updateRequestState(request.getToken(), RequestState.REPORTED);
    IToken<?> resolver = assignRequest(manager, request, resolverTokenBlackList);
    if (parent != null) {
        request.setParent(parent);
        final IRequest parentRequest = RequestHandler.getRequest(manager, parent);
        parentRequest.addChild(request.getToken());
    }
    return resolver;
}
Also used : IRequestResolver(com.minecolonies.api.colony.requestsystem.resolver.IRequestResolver) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest)

Example 19 with IRequest

use of com.minecolonies.api.colony.requestsystem.request.IRequest in project minecolonies by Minecolonies.

the class WindowCitizen method fulfill.

/**
 * On Button click transfert Items and fullfil.
 *
 * @param button the clicked button.
 */
private void fulfill(@NotNull final Button button) {
    final int row = resourceList.getListElementIndexByPane(button);
    if (getOpenRequestTreeOfCitizen().size() > row && row >= 0) {
        @NotNull final IRequest tRequest = getOpenRequestTreeOfCitizen().get(row).getRequest();
        if (!(tRequest.getRequest() instanceof IDeliverable)) {
            return;
        }
        @NotNull final IRequest<? extends IDeliverable> request = (IRequest<? extends IDeliverable>) tRequest;
        final Predicate<ItemStack> requestPredicate = stack -> request.getRequest().matches(stack);
        final int amount = request.getRequest().getCount();
        final int count = InventoryUtils.getItemCountInItemHandler(new InvWrapper(inventory), requestPredicate);
        if (!isCreative && count <= 0) {
            return;
        }
        // The itemStack size should not be greater than itemStack.getMaxStackSize, We send 1 instead
        // and use quantity for the size
        @NotNull final ItemStack itemStack;
        if (isCreative) {
            itemStack = request.getDisplayStacks().stream().findFirst().orElse(ItemStack.EMPTY);
        } else {
            itemStack = inventory.getStackInSlot(InventoryUtils.findFirstSlotInItemHandlerWith(new InvWrapper(inventory), requestPredicate));
        }
        MineColonies.getNetwork().sendToServer(new TransferItemsToCitizenRequestMessage(citizen, itemStack, isCreative ? amount : Math.min(amount, count), citizen.getColonyId()));
        MineColonies.getNetwork().sendToServer(new UpdateRequestStateMessage(citizen.getColonyId(), request.getToken(), RequestState.OVERRULED, itemStack));
    }
    button.disable();
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) SwitchView(com.minecolonies.blockout.views.SwitchView) ExperienceUtils(com.minecolonies.coremod.util.ExperienceUtils) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) ColonyView(com.minecolonies.coremod.colony.ColonyView) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) CitizenData(com.minecolonies.coremod.colony.CitizenData) Gui(net.minecraft.client.gui.Gui) ImmutableList(com.google.common.collect.ImmutableList) ColonyManager(com.minecolonies.coremod.colony.ColonyManager) Minecraft(net.minecraft.client.Minecraft) RAWTYPES(com.minecolonies.api.util.constant.Suppression.RAWTYPES) Constants(com.minecolonies.api.util.constant.Constants) com.minecolonies.blockout.controls(com.minecolonies.blockout.controls) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) LanguageHandler(com.minecolonies.api.util.LanguageHandler) Predicate(java.util.function.Predicate) RequestState(com.minecolonies.api.colony.requestsystem.request.RequestState) TransferItemsToCitizenRequestMessage(com.minecolonies.coremod.network.messages.TransferItemsToCitizenRequestMessage) BlockPos(net.minecraft.util.math.BlockPos) Pane(com.minecolonies.blockout.Pane) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ScrollingList(com.minecolonies.blockout.views.ScrollingList) CitizenDataView(com.minecolonies.coremod.colony.CitizenDataView) Alignment(com.minecolonies.blockout.Alignment) UpdateRequestStateMessage(com.minecolonies.coremod.network.messages.UpdateRequestStateMessage) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) GuiScreen(net.minecraft.client.gui.GuiScreen) List(java.util.List) FMLClientHandler(net.minecraftforge.fml.client.FMLClientHandler) MineColonies(com.minecolonies.coremod.MineColonies) InventoryUtils(com.minecolonies.api.util.InventoryUtils) View(com.minecolonies.blockout.views.View) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) Box(com.minecolonies.blockout.views.Box) OpenInventoryMessage(com.minecolonies.coremod.network.messages.OpenInventoryMessage) UpdateRequestStateMessage(com.minecolonies.coremod.network.messages.UpdateRequestStateMessage) TransferItemsToCitizenRequestMessage(com.minecolonies.coremod.network.messages.TransferItemsToCitizenRequestMessage) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) ItemStack(net.minecraft.item.ItemStack) NotNull(org.jetbrains.annotations.NotNull) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)

Example 20 with IRequest

use of com.minecolonies.api.colony.requestsystem.request.IRequest in project minecolonies by Minecolonies.

the class WindowCitizen method getOpenRequestsOfCitizen.

@SuppressWarnings(RAWTYPES)
private ImmutableList<IRequest> getOpenRequestsOfCitizen() {
    final ArrayList<IRequest> requests = new ArrayList<>();
    if (citizen.getWorkBuilding() != null) {
        requests.addAll(getOpenRequestsOfCitizenFromBuilding(citizen.getWorkBuilding()));
    }
    if (citizen.getHomeBuilding() != null && !citizen.getHomeBuilding().equals(citizen.getWorkBuilding())) {
        requests.addAll(getOpenRequestsOfCitizenFromBuilding(citizen.getHomeBuilding()));
    }
    final BlockPos playerPos = Minecraft.getMinecraft().player.getPosition();
    requests.sort(Comparator.comparing((IRequest request) -> request.getRequester().getDeliveryLocation().getInDimensionLocation().getDistance(playerPos.getX(), playerPos.getY(), playerPos.getZ())).thenComparingInt(request -> request.getToken().hashCode()));
    return ImmutableList.copyOf(requests);
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) SwitchView(com.minecolonies.blockout.views.SwitchView) ExperienceUtils(com.minecolonies.coremod.util.ExperienceUtils) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) ColonyView(com.minecolonies.coremod.colony.ColonyView) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) CitizenData(com.minecolonies.coremod.colony.CitizenData) Gui(net.minecraft.client.gui.Gui) ImmutableList(com.google.common.collect.ImmutableList) ColonyManager(com.minecolonies.coremod.colony.ColonyManager) Minecraft(net.minecraft.client.Minecraft) RAWTYPES(com.minecolonies.api.util.constant.Suppression.RAWTYPES) Constants(com.minecolonies.api.util.constant.Constants) com.minecolonies.blockout.controls(com.minecolonies.blockout.controls) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) LanguageHandler(com.minecolonies.api.util.LanguageHandler) Predicate(java.util.function.Predicate) RequestState(com.minecolonies.api.colony.requestsystem.request.RequestState) TransferItemsToCitizenRequestMessage(com.minecolonies.coremod.network.messages.TransferItemsToCitizenRequestMessage) BlockPos(net.minecraft.util.math.BlockPos) Pane(com.minecolonies.blockout.Pane) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ScrollingList(com.minecolonies.blockout.views.ScrollingList) CitizenDataView(com.minecolonies.coremod.colony.CitizenDataView) Alignment(com.minecolonies.blockout.Alignment) UpdateRequestStateMessage(com.minecolonies.coremod.network.messages.UpdateRequestStateMessage) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) GuiScreen(net.minecraft.client.gui.GuiScreen) List(java.util.List) FMLClientHandler(net.minecraftforge.fml.client.FMLClientHandler) MineColonies(com.minecolonies.coremod.MineColonies) InventoryUtils(com.minecolonies.api.util.InventoryUtils) View(com.minecolonies.blockout.views.View) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) Box(com.minecolonies.blockout.views.Box) OpenInventoryMessage(com.minecolonies.coremod.network.messages.OpenInventoryMessage) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest)

Aggregations

IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)22 NotNull (org.jetbrains.annotations.NotNull)13 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)11 Nullable (org.jetbrains.annotations.Nullable)11 BlockPos (net.minecraft.util.math.BlockPos)10 List (java.util.List)9 ItemStack (net.minecraft.item.ItemStack)9 ImmutableList (com.google.common.collect.ImmutableList)8 TypeToken (com.google.common.reflect.TypeToken)7 Lists (com.google.common.collect.Lists)6 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)6 IRequestManager (com.minecolonies.api.colony.requestsystem.manager.IRequestManager)6 IDeliverable (com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)6 MineColonies (com.minecolonies.coremod.MineColonies)6 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)6 RequestState (com.minecolonies.api.colony.requestsystem.request.RequestState)5 RAWTYPES (com.minecolonies.api.util.constant.Suppression.RAWTYPES)5 TypeConstants (com.minecolonies.api.util.constant.TypeConstants)5 ArrayList (java.util.ArrayList)5 Delivery (com.minecolonies.api.colony.requestsystem.requestable.Delivery)4