use of com.minecolonies.coremod.inventory.api.CombinedItemHandler in project minecolonies by Minecolonies.
the class AbstractBuilding method getCapability.
@Nullable
@Override
public <T> T getCapability(@Nonnull final Capability<T> capability, @Nullable final EnumFacing facing) {
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && facing == null) {
final Set<ICapabilityProvider> providers = new HashSet<>();
// Add myself
providers.add(getTileEntity());
// Add additional containers
providers.addAll(getAdditionalCountainers().stream().map(getTileEntity().getWorld()::getTileEntity).filter(entity -> (entity instanceof TileEntityChest) || (entity instanceof TileEntityRack)).collect(Collectors.toSet()));
providers.removeIf(Objects::isNull);
// Map all providers to IItemHandlers.
final Set<IItemHandlerModifiable> modifiables = providers.stream().flatMap(provider -> InventoryUtils.getItemHandlersFromProvider(provider).stream()).filter(handler -> handler instanceof IItemHandlerModifiable).map(handler -> (IItemHandlerModifiable) handler).collect(Collectors.toSet());
return (T) new CombinedItemHandler(getSchematicName(), modifiables.toArray(new IItemHandlerModifiable[modifiables.size()]));
}
return null;
}
Aggregations