use of com.minecolonies.api.colony.requestsystem.manager.IRequestManager in project minecolonies by Minecolonies.
the class DeliveryRequestResolver method attemptResolve.
@Nullable
@Override
public List<IToken<?>> attemptResolve(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends Delivery> request) {
if (manager.getColony().getWorld().isRemote) {
return null;
}
final Colony colony = (Colony) manager.getColony();
// We can do an instant get here, since we are already filtering on anything that has no entity.
final CitizenData freeDeliveryMan = colony.getCitizenManager().getCitizens().stream().filter(citizenData -> citizenData.getCitizenEntity().map(entityCitizen -> request.getRequest().getTarget().isReachableFromLocation(entityCitizen.getLocation())).orElse(false)).filter(c -> c.getJob() instanceof JobDeliveryman).min(Comparator.comparing((CitizenData c) -> ((JobDeliveryman) c.getJob()).getTaskQueue().size()).thenComparing(Comparator.comparing(c -> {
BlockPos targetPos = request.getRequest().getTarget().getInDimensionLocation();
// We can do an instant get here, since we are already filtering on anything that has no entity.
BlockPos entityLocation = c.getCitizenEntity().get().getLocation().getInDimensionLocation();
return BlockPosUtil.getDistanceSquared(targetPos, entityLocation);
}))).orElse(null);
if (freeDeliveryMan == null) {
return null;
}
final JobDeliveryman job = (JobDeliveryman) freeDeliveryMan.getJob();
job.addRequest(request.getToken());
return Lists.newArrayList();
}
use of com.minecolonies.api.colony.requestsystem.manager.IRequestManager in project minecolonies by Minecolonies.
the class DeliveryRequestResolver method canResolve.
@Override
public boolean canResolve(@NotNull final IRequestManager manager, final IRequest<? extends Delivery> requestToCheck) {
if (manager.getColony().getWorld().isRemote) {
return false;
}
final Colony colony = (Colony) manager.getColony();
final CitizenData freeDeliveryMan = colony.getCitizenManager().getCitizens().stream().filter(citizenData -> citizenData.getCitizenEntity().map(entityCitizen -> requestToCheck.getRequest().getTarget().isReachableFromLocation(entityCitizen.getLocation())).orElse(false)).filter(c -> c.getJob() instanceof JobDeliveryman).findFirst().orElse(null);
return freeDeliveryMan != null;
}
use of com.minecolonies.api.colony.requestsystem.manager.IRequestManager in project minecolonies by Minecolonies.
the class AbstractBuilding method getRequiredItemsAndAmount.
/**
* Override this method if you want to keep an amount of items in inventory.
* When the inventory is full, everything get's dumped into the building chest.
* But you can use this method to hold some stacks back.
*
* @return a list of objects which should be kept.
*/
public Map<Predicate<ItemStack>, Integer> getRequiredItemsAndAmount() {
final Map<Predicate<ItemStack>, Integer> toKeep = new HashMap<>();
toKeep.putAll(keepX);
final IRequestManager manager = colony.getRequestManager();
toKeep.put(stack -> this.getOpenRequestsByCitizen().values().stream().anyMatch(list -> list.stream().anyMatch(token -> manager.getRequestForToken(token).getRequest() instanceof IDeliverable && ((IDeliverable) manager.getRequestForToken(token).getRequest()).matches(stack))), Integer.MAX_VALUE);
return toKeep;
}
use of com.minecolonies.api.colony.requestsystem.manager.IRequestManager in project minecolonies by Minecolonies.
the class WarehouseRequestResolver method canResolve.
@Override
public boolean canResolve(@NotNull final IRequestManager manager, final IRequest<? extends IDeliverable> requestToCheck) {
if (!manager.getColony().getWorld().isRemote) {
final Colony colony = (Colony) manager.getColony();
final Set<TileEntityWareHouse> wareHouses = getWareHousesInColony(colony);
wareHouses.removeIf(Objects::isNull);
try {
return wareHouses.stream().anyMatch(wareHouse -> wareHouse.hasMatchinItemStackInWarehouse(itemStack -> requestToCheck.getRequest().matches(itemStack)));
} catch (Exception e) {
Log.getLogger().error(e);
}
}
return false;
}
use of com.minecolonies.api.colony.requestsystem.manager.IRequestManager in project minecolonies by Minecolonies.
the class AbstractBuildingDependentRequestResolver method resolve.
@Override
public void resolve(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends R> request) {
final AbstractBuilding building = getBuilding(manager, request.getToken()).map(r -> (AbstractBuilding) r).get();
resolveForBuilding(manager, request, building);
}
Aggregations