public class CapabilitiesHelper
extends java.lang.Object
Unfortunately this doesn't even slightly work when using a test framework like JUnit, as
CapabilityManager#register(Class, IStorage, Callable)
doesn't return the registered Capability
instances, and we don't load classes with forge's class loaders in JUnit. This class provides two useful methods to
compensate: registerCapability(Class)
and registerCapability(CheckedStorage, Callable)
, both of
which returns the registered capability.
This is NOT designed for mods wishing to add compatibility for buildcraft capability instances: those should still go
via the forge-recommended CapabilityInject
route, or refer to the various fields in buildcraft api classes
containing the capability instances.
Modifier and Type | Class and Description |
---|---|
static class |
CapabilitiesHelper.CheckedStorage<T>
A type of
Capability.IStorage that contains the class that it would store. |
static class |
CapabilitiesHelper.ThrowingStorage<T>
A type of
CapabilitiesHelper.CheckedStorage that throws an UnsupportedOperationException from both the read and
write methods. |
static class |
CapabilitiesHelper.VoidStorage<T> |
Constructor and Description |
---|
CapabilitiesHelper() |
Modifier and Type | Method and Description |
---|---|
static <T> net.minecraftforge.common.capabilities.Capability<T> |
ensureRegistration(net.minecraftforge.common.capabilities.Capability<T> cap,
java.lang.Class<T> clazz)
Deprecated.
|
static <T> net.minecraftforge.common.capabilities.Capability<T> |
registerCapability(CapabilitiesHelper.CheckedStorage<T> storage,
java.util.concurrent.Callable<T> factory)
Registers a given type with the
CapabilityManager , but also returns the capability instance. |
static <T> net.minecraftforge.common.capabilities.Capability<T> |
registerCapability(java.lang.Class<T> clazz)
Registers a given type with
registerCapability(CheckedStorage, Callable) , but with a
CapabilitiesHelper.ThrowingStorage and a factory that throws an UnsupportedOperationException instead of creating a
new capability instance. |
@Nonnull public static <T> net.minecraftforge.common.capabilities.Capability<T> registerCapability(java.lang.Class<T> clazz)
registerCapability(CheckedStorage, Callable)
, but with a
CapabilitiesHelper.ThrowingStorage
and a factory that throws an UnsupportedOperationException
instead of creating a
new capability instance.clazz
- The type that all instances must derive from.Capability
@Nonnull public static <T> net.minecraftforge.common.capabilities.Capability<T> registerCapability(CapabilitiesHelper.CheckedStorage<T> storage, java.util.concurrent.Callable<T> factory)
CapabilityManager
, but also returns the capability instance.storage
- The storage for the capability. This must extend CapabilitiesHelper.CheckedStorage
in order to allow the
internal mechanisms to ensure that nothing went wrong during our meddling into forge.factory
- The factory for the capability.Capability
@Nonnull @Deprecated public static <T> net.minecraftforge.common.capabilities.Capability<T> ensureRegistration(net.minecraftforge.common.capabilities.Capability<T> cap, java.lang.Class<T> clazz)
registerCapability(Class)
or other methods over this one: this will be removed at some point in
the future. Most likely before beta.