Search in sources :

Example 1 with UpdateRequestStateMessage

use of com.minecolonies.coremod.network.messages.UpdateRequestStateMessage 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 2 with UpdateRequestStateMessage

use of com.minecolonies.coremod.network.messages.UpdateRequestStateMessage in project minecolonies by Minecolonies.

the class WindowCitizen method cancel.

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

Example 3 with UpdateRequestStateMessage

use of com.minecolonies.coremod.network.messages.UpdateRequestStateMessage 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

UpdateRequestStateMessage (com.minecolonies.coremod.network.messages.UpdateRequestStateMessage)3 NotNull (org.jetbrains.annotations.NotNull)3 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)2 ImmutableList (com.google.common.collect.ImmutableList)1 IRequestManager (com.minecolonies.api.colony.requestsystem.manager.IRequestManager)1 RequestState (com.minecolonies.api.colony.requestsystem.request.RequestState)1 IDeliverable (com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)1 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)1 InventoryUtils (com.minecolonies.api.util.InventoryUtils)1 LanguageHandler (com.minecolonies.api.util.LanguageHandler)1 Constants (com.minecolonies.api.util.constant.Constants)1 RAWTYPES (com.minecolonies.api.util.constant.Suppression.RAWTYPES)1 Alignment (com.minecolonies.blockout.Alignment)1 Pane (com.minecolonies.blockout.Pane)1 com.minecolonies.blockout.controls (com.minecolonies.blockout.controls)1 Box (com.minecolonies.blockout.views.Box)1 ScrollingList (com.minecolonies.blockout.views.ScrollingList)1 SwitchView (com.minecolonies.blockout.views.SwitchView)1 View (com.minecolonies.blockout.views.View)1 MineColonies (com.minecolonies.coremod.MineColonies)1