Search in sources :

Example 21 with IRequest

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

the class WindowClipBoard method getOpenRequests.

private ImmutableList<IRequest> getOpenRequests() {
    final ArrayList<IRequest> requests = Lists.newArrayList();
    final ColonyView view = ColonyManager.getColonyView(colonyId);
    if (view == null) {
        return ImmutableList.of();
    }
    final IPlayerRequestResolver resolver = view.getRequestManager().getPlayerResolver();
    final IRetryingRequestResolver retryingRequestResolver = view.getRequestManager().getRetryingRequestResolver();
    final Set<IToken> requestTokens = new HashSet<>();
    requestTokens.addAll(resolver.getAllAssignedRequests());
    requestTokens.addAll(retryingRequestResolver.getAllAssignedRequests());
    requests.addAll(requestTokens.stream().map(view.getRequestManager()::getRequestForToken).filter(Objects::nonNull).collect(Collectors.toSet()));
    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) java.util(java.util) Button(com.minecolonies.blockout.controls.Button) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) ItemIcon(com.minecolonies.blockout.controls.ItemIcon) ColonyView(com.minecolonies.coremod.colony.ColonyView) ItemStack(net.minecraft.item.ItemStack) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ColonyManager(com.minecolonies.coremod.colony.ColonyManager) Minecraft(net.minecraft.client.Minecraft) IRetryingRequestResolver(com.minecolonies.api.colony.requestsystem.resolver.retrying.IRetryingRequestResolver) Constants(com.minecolonies.api.util.constant.Constants) RequestState(com.minecolonies.api.colony.requestsystem.request.RequestState) BlockPos(net.minecraft.util.math.BlockPos) ScrollingList(com.minecolonies.blockout.views.ScrollingList) Collectors(java.util.stream.Collectors) UpdateRequestStateMessage(com.minecolonies.coremod.network.messages.UpdateRequestStateMessage) IPlayerRequestResolver(com.minecolonies.api.colony.requestsystem.resolver.player.IPlayerRequestResolver) Nullable(org.jetbrains.annotations.Nullable) GuiScreen(net.minecraft.client.gui.GuiScreen) MineColonies(com.minecolonies.coremod.MineColonies) Image(com.minecolonies.blockout.controls.Image) Label(com.minecolonies.blockout.controls.Label) NotNull(org.jetbrains.annotations.NotNull) ColonyView(com.minecolonies.coremod.colony.ColonyView) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) IPlayerRequestResolver(com.minecolonies.api.colony.requestsystem.resolver.player.IPlayerRequestResolver) BlockPos(net.minecraft.util.math.BlockPos) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) IRetryingRequestResolver(com.minecolonies.api.colony.requestsystem.resolver.retrying.IRetryingRequestResolver)

Example 22 with IRequest

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

the class WindowClipBoard method cancel.

private void cancel(@NotNull final Button button) {
    final int row = resourceList.getListElementIndexByPane(button);
    if (getOpenRequests().size() > row && row >= 0) {
        @NotNull final IRequest request = getOpenRequests().get(row);
        MineColonies.getNetwork().sendToServer(new UpdateRequestStateMessage(colonyId, request.getToken(), RequestState.CANCELLED, null));
    }
}
Also used : UpdateRequestStateMessage(com.minecolonies.coremod.network.messages.UpdateRequestStateMessage) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) NotNull(org.jetbrains.annotations.NotNull)

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