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