use of com.minecolonies.api.colony.requestsystem.requestable.Stack in project minecolonies by Minecolonies.
the class PlacementHandlers method checkForListInInvAndRequest.
/**
* Check the placers inventory for the items in the itemList and remove it of the list if found.
*
* @param placer the placer.
* @param itemList the list to check.
* @return true if need to request.
*/
public static boolean checkForListInInvAndRequest(@NotNull final AbstractEntityAIStructure<?> placer, final List<ItemStack> itemList) {
final List<ItemStack> foundStacks = InventoryUtils.filterItemHandler(new InvWrapper(placer.getWorker().getInventoryCitizen()), itemStack -> itemList.stream().anyMatch(targetStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, targetStack, true, true)));
itemList.removeIf(itemStack -> ItemStackUtils.isEmpty(itemStack) || foundStacks.stream().anyMatch(targetStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, targetStack, true, true)));
for (final ItemStack placedStack : itemList) {
if (ItemStackUtils.isEmpty(placedStack)) {
return true;
}
if (placer.getOwnBuilding().getOpenRequestsOfTypeFiltered(placer.getWorker().getCitizenData(), TypeConstants.DELIVERABLE, (IRequest<? extends IDeliverable> r) -> r.getRequest().matches(placedStack)).isEmpty()) {
final Stack stackRequest = new Stack(placer.getTotalAmount(placedStack));
placer.getWorker().getCitizenData().createRequest(stackRequest);
return true;
}
}
return false;
}
use of com.minecolonies.api.colony.requestsystem.requestable.Stack in project minecolonies by Minecolonies.
the class AbstractEntityAIBasic method checkIfRequestForItemExistOrCreate.
/**
* Check if a stack has been requested already or is in the inventory.
* If not in the inventory and not requested already, create request
*
* @param stack the requested stack.
* @return true if in the inventory, else false.
*/
public boolean checkIfRequestForItemExistOrCreate(@NotNull final ItemStack stack) {
if (InventoryUtils.hasItemInItemHandler(new InvWrapper(worker.getInventoryCitizen()), s -> ItemStackUtils.compareItemStacksIgnoreStackSize(s, stack))) {
return true;
}
if (getOwnBuilding().getOpenRequestsOfTypeFiltered(worker.getCitizenData(), TypeConstants.DELIVERABLE, (IRequest<? extends IDeliverable> r) -> r.getRequest().matches(stack)).isEmpty()) {
final Stack stackRequest = new Stack(stack);
worker.getCitizenData().createRequest(stackRequest);
}
return false;
}
use of com.minecolonies.api.colony.requestsystem.requestable.Stack in project minecolonies by Minecolonies.
the class AbstractEntityAIBasic method checkIfRequestForItemExistOrCreateAsynch.
/**
* Check if a stack has been requested already or is in the inventory.
* If not in the inventory and not requested already, create request
*
* @param stack the requested stack.
* @return true if in the inventory, else false.
*/
public boolean checkIfRequestForItemExistOrCreateAsynch(@NotNull final ItemStack stack) {
if (InventoryUtils.hasItemInItemHandler(new InvWrapper(worker.getInventoryCitizen()), s -> ItemStackUtils.compareItemStacksIgnoreStackSize(s, stack) && s.getCount() >= stack.getCount())) {
return true;
}
if (InventoryUtils.getItemCountInProvider(getOwnBuilding(), itemStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, stack, true, true)) >= stack.getCount() && InventoryUtils.transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler(getOwnBuilding(), itemStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, stack, true, true), stack.getCount(), new InvWrapper(worker.getInventoryCitizen()))) {
return true;
}
if (getOwnBuilding().getOpenRequestsOfTypeFiltered(worker.getCitizenData(), TypeConstants.DELIVERABLE, (IRequest<? extends IDeliverable> r) -> r.getRequest().matches(stack)).isEmpty()) {
final Stack stackRequest = new Stack(stack);
worker.getCitizenData().createRequestAsync(stackRequest);
}
return false;
}
use of com.minecolonies.api.colony.requestsystem.requestable.Stack in project minecolonies by Minecolonies.
the class AbstractEntityAIBasic method lookForRequests.
/**
* Utility method to search for items currently needed.
* Poll this until all items are there.
*/
@NotNull
private AIState lookForRequests() {
if (!this.getOwnBuilding().hasWorkerOpenRequestsFiltered(worker.getCitizenData(), r -> !worker.getCitizenData().isRequestAsync(r.getToken())) && !getOwnBuilding().hasCitizenCompletedRequests(worker.getCitizenData())) {
return IDLE;
}
if (!walkToBuilding() && getOwnBuilding().hasCitizenCompletedRequests(worker.getCitizenData())) {
delay += DELAY_RECHECK;
@SuppressWarnings(RAWTYPES) final ImmutableList<IRequest> completedRequests = getOwnBuilding().getCompletedRequests(worker.getCitizenData());
completedRequests.stream().filter(r -> !(r.canBeDelivered())).forEach(r -> getOwnBuilding().markRequestAsAccepted(worker.getCitizenData(), r.getToken()));
@SuppressWarnings(RAWTYPES) final IRequest firstDeliverableRequest = completedRequests.stream().filter(IRequest::canBeDelivered).findFirst().orElse(null);
if (firstDeliverableRequest != null) {
boolean async = false;
if (worker.getCitizenData().isRequestAsync(firstDeliverableRequest.getToken())) {
async = true;
job.getAsyncRequests().remove(firstDeliverableRequest.getToken());
}
getOwnBuilding().markRequestAsAccepted(worker.getCitizenData(), firstDeliverableRequest.getToken());
final ItemStack deliveredItemStack = firstDeliverableRequest.getDelivery();
final int count = InventoryUtils.getItemCountInItemHandler(new InvWrapper(worker.getInventoryCitizen()), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(deliveredItemStack, stack, true, true));
if (count >= deliveredItemStack.getCount() && getTotalRequiredAmount(deliveredItemStack) <= count) {
return NEEDS_ITEM;
}
// Takes one Stack from the hut if existent
if (InventoryUtils.getItemCountInProvider(getOwnBuilding(), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(deliveredItemStack, stack, true, true)) >= deliveredItemStack.getCount() && InventoryUtils.transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler(getOwnBuilding(), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(deliveredItemStack, stack, true, true), deliveredItemStack.getCount(), new InvWrapper(worker.getInventoryCitizen()))) {
return NEEDS_ITEM;
} else {
// Lets try this again.
if (async) {
worker.getCitizenData().createRequestAsync(firstDeliverableRequest.getRequest());
} else {
worker.getCitizenData().createRequest(firstDeliverableRequest.getRequest());
}
}
}
}
return NEEDS_ITEM;
}
Aggregations