use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse in project minecolonies by Minecolonies.
the class AbstractWarehouseRequestResolver method getWareHousesInColony.
/**
* Use to get the ordered list of all warehouses.
* @param colony the colony in question.
* @return the ordered list.
*/
protected static List<TileEntityWareHouse> getWareHousesInColony(final Colony colony, final BlockPos requesterPosition) {
final List<TileEntityWareHouse> wareHouses = new ArrayList<>();
for (final IBuilding building : colony.getBuildingManager().getBuildings().values()) {
if (building instanceof BuildingWareHouse && building.getTileEntity() != null) {
wareHouses.add((TileEntityWareHouse) building.getTileEntity());
}
}
wareHouses.sort((w1, w2) -> {
final double dist1 = w1.getPosition().distSqr(requesterPosition);
final double dist2 = w2.getPosition().distSqr(requesterPosition);
return Double.compare(dist1, dist2);
});
return wareHouses;
}
use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse in project minecolonies by ldtteam.
the class StationRequestResolver method canResolveForBuilding.
@Override
public boolean canResolveForBuilding(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends IDeliverable> request, @NotNull final AbstractBuilding building) {
if (building instanceof BuildingWareHouse || building.getCitizenForRequest(request.getId()).isPresent() || building.hasModule(WorkerBuildingModule.class) || !building.hasModule(AbstractAssignedCitizenModule.class)) {
return false;
}
boolean foundMatch = false;
for (final AbstractAssignedCitizenModule module : building.getModules(AbstractAssignedCitizenModule.class)) {
for (final ICitizenData citizen : module.getAssignedCitizen()) {
if (citizen.getWorkBuilding() != null && citizen.getWorkBuilding().getCitizenForRequest(request.getId()).isPresent()) {
foundMatch = true;
break;
}
}
}
if (!foundMatch) {
return false;
}
final Predicate<ItemStack> pred = itemStack -> {
if (ItemStackUtils.isEmpty(itemStack) || !request.getRequest().matches(itemStack)) {
return false;
}
if (!request.hasParent()) {
return true;
}
final IRequest<?> requestParent = manager.getRequestForToken(request.getParent());
return !requestParent.getRequestOfType(IDeliverable.class).map(d -> d.matches(itemStack)).orElse(false);
};
return InventoryUtils.getCountFromBuilding(building, pred) > 0;
}
use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse in project minecolonies by ldtteam.
the class AbstractWarehouseRequestResolver method canResolveRequest.
@Override
public boolean canResolveRequest(@NotNull final IRequestManager manager, final IRequest<? extends IDeliverable> requestToCheck) {
if (requestToCheck.getRequester() instanceof BuildingBasedRequester) {
final BuildingBasedRequester requester = ((BuildingBasedRequester) requestToCheck.getRequester());
final Optional<IRequester> building = requester.getBuilding(manager, requestToCheck.getRequester().getId());
if (building.isPresent() && building.get() instanceof BuildingWareHouse) {
return false;
}
}
if (!manager.getColony().getWorld().isClientSide) {
if (!isRequestChainValid(manager, requestToCheck)) {
return false;
}
final Colony colony = (Colony) manager.getColony();
try {
return internalCanResolve(getWareHousesInColony(colony, requestToCheck.getRequester().getLocation().getInDimensionLocation()), requestToCheck);
} catch (Exception e) {
Log.getLogger().error(e);
}
}
return false;
}
Aggregations