use of com.minecolonies.coremod.colony.requestsystem.resolvers.StationRequestResolver in project minecolonies by Minecolonies.
the class QuarryModule method createResolvers.
@Override
public List<IRequestResolver<?>> createResolvers() {
final ImmutableList.Builder<IRequestResolver<?>> builder = ImmutableList.builder();
builder.add(new StationRequestResolver(building.getRequester().getLocation(), building.getColony().getRequestManager().getFactoryController().getNewInstance(TypeConstants.ITOKEN)));
return builder.build();
}
use of com.minecolonies.coremod.colony.requestsystem.resolvers.StationRequestResolver 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.
*
* @return the next state to go to.
*/
@NotNull
private IAIState lookForRequests() {
if (!this.building.hasOpenSyncRequest(worker.getCitizenData()) && !building.hasCitizenCompletedRequests(worker.getCitizenData())) {
return afterRequestPickUp();
}
if (building.hasCitizenCompletedRequests(worker.getCitizenData())) {
final Collection<IRequest<?>> completedRequests = building.getCompletedRequests(worker.getCitizenData());
final List<IRequest<?>> deliverableRequests = new ArrayList<>();
for (final IRequest<?> req : completedRequests) {
if (!req.canBeDelivered()) {
building.markRequestAsAccepted(worker.getCitizenData(), req.getId());
} else {
deliverableRequests.add(req);
}
}
if (!deliverableRequests.isEmpty()) {
final IRequest<?> firstDeliverableRequest = deliverableRequests.get(0);
final IRequestResolver<?> resolver = building.getColony().getRequestManager().getResolverForRequest(firstDeliverableRequest.getId());
final ILocation pickupLocation = resolver instanceof StationRequestResolver ? resolver.getLocation() : building.getLocation();
if (walkToBlock(pickupLocation.getInDimensionLocation()) || !WorldUtil.isBlockLoaded(world, pickupLocation.getInDimensionLocation())) {
return NEEDS_ITEM;
}
final TileEntity blockEntity = world.getBlockEntity(pickupLocation.getInDimensionLocation());
if (blockEntity == null) {
return NEEDS_ITEM;
}
boolean async = false;
if (worker.getCitizenData().isRequestAsync(firstDeliverableRequest.getId())) {
async = true;
job.getAsyncRequests().remove(firstDeliverableRequest.getId());
}
building.markRequestAsAccepted(worker.getCitizenData(), firstDeliverableRequest.getId());
final List<IItemHandler> validHandlers = Lists.newArrayList();
validHandlers.add(worker.getItemHandlerCitizen());
validHandlers.addAll(InventoryUtils.getItemHandlersFromProvider(blockEntity));
// Check if we either have the requested Items in our inventory or if they are in the building.
if (InventoryUtils.areAllItemsInItemHandlerList(firstDeliverableRequest.getDeliveries(), validHandlers)) {
final List<ItemStack> niceToHave = itemsNiceToHave();
final List<ItemStack> contained = InventoryUtils.getContainedFromItemHandler(firstDeliverableRequest.getDeliveries(), worker.getItemHandlerCitizen());
InventoryUtils.moveItemStacksWithPossibleSwap(worker.getItemHandlerCitizen(), InventoryUtils.getItemHandlersFromProvider(blockEntity), firstDeliverableRequest.getDeliveries(), itemStack -> contained.stream().anyMatch(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, stack)) || niceToHave.stream().anyMatch(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, stack)));
return NEEDS_ITEM;
} else {
// Lets try this again.
if (async) {
worker.getCitizenData().createRequestAsync(firstDeliverableRequest.getRequest());
} else {
worker.getCitizenData().createRequest(firstDeliverableRequest.getRequest());
}
}
}
} else {
walkToBuilding();
}
return NEEDS_ITEM;
}
use of com.minecolonies.coremod.colony.requestsystem.resolvers.StationRequestResolver in project minecolonies by ldtteam.
the class StationRequestResolverFactory method deserialize.
@NotNull
@Override
public StationRequestResolver deserialize(IFactoryController controller, @NotNull PacketBuffer buffer) throws Throwable {
final IToken<?> token = controller.deserialize(buffer);
final ILocation location = controller.deserialize(buffer);
return new StationRequestResolver(location, token);
}
Aggregations