Java Code Examples for net.minecraftforge.common.util.LazyOptional#empty()

The following examples show how to use net.minecraftforge.common.util.LazyOptional#empty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CapabilityDispatcher.java    From patchwork-api with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(Capability<T> cap, @Nullable Direction side) {
	for (ICapabilityProvider provider : providers) {
		LazyOptional<T> ret = provider.getCapability(cap, side);

		//noinspection ConstantConditions
		if (ret == null) {
			throw new RuntimeException(
					String.format(
							"Provider %s.getCapability() returned null; return LazyOptional.empty() instead!",
							provider.getClass().getTypeName()
					)
			);
		}

		if (ret.isPresent()) {
			return ret;
		}
	}

	return LazyOptional.empty();
}
 
Example 2
Source File: CapabilityCache.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
private LazyOptional<?> requestCapability(Capability<?> capability, Direction to) {
    TileEntity tile = world.getTileEntity(pos.offset(to));
    Direction inverse = to == null ? null : to.getOpposite();
    if (tile != null) {
        return tile.getCapability(capability, inverse);
    }
    return LazyOptional.empty();
}
 
Example 3
Source File: CapabilityProvider.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
@Nonnull
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
	final CapabilityDispatcher disp = getCapabilities();
	return !valid || disp == null ? LazyOptional.empty() : disp.getCapability(cap, side);
}
 
Example 4
Source File: Capability.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public @Nonnull <R> LazyOptional<R> orEmpty(Capability<R> toCheck, LazyOptional<T> inst) {
	return this == toCheck ? inst.cast() : LazyOptional.empty();
}
 
Example 5
Source File: CapabilityEnergyProvider.java    From MiningGadgets with MIT License 4 votes vote down vote up
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
    return cap == CapabilityEnergy.ENERGY ? capability.cast() : LazyOptional.empty();
}