Class CapabilityDispatcher
- java.lang.Object
-
- net.minecraftforge.common.capabilities.CapabilityDispatcher
-
- All Implemented Interfaces:
ICapabilityProvider
,INBTSerializable<CompoundNBT>
@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault public final class CapabilityDispatcher extends java.lang.Object implements INBTSerializable<CompoundNBT>, ICapabilityProvider
A high-speed implementation of a capability delegator. This is used to wrap the results of the AttachCapabilitiesEvent. It is HIGHLY recommended that you DO NOT use this approach unless you MUST delegate to multiple providers instead just implement y our handlers using normal if statements. Internally the handlers are baked into arrays for fast iteration. The ResourceLocations will be used for the NBT Key when serializing.
-
-
Field Summary
Fields Modifier and Type Field Description private ICapabilityProvider[]
caps
private java.util.List<java.lang.Runnable>
listeners
private java.lang.String[]
names
private INBTSerializable<INBT>[]
writers
-
Constructor Summary
Constructors Constructor Description CapabilityDispatcher(java.util.Map<ResourceLocation,ICapabilityProvider> list, java.util.List<java.lang.Runnable> listeners)
CapabilityDispatcher(java.util.Map<ResourceLocation,ICapabilityProvider> list, java.util.List<java.lang.Runnable> listeners, ICapabilityProvider parent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
areCompatible(CapabilityDispatcher other)
void
deserializeNBT(CompoundNBT nbt)
<T> LazyOptional<T>
getCapability(Capability<T> cap, Direction side)
Retrieves the Optional handler for the capability requested on the specific side.void
invalidate()
CompoundNBT
serializeNBT()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.minecraftforge.common.capabilities.ICapabilityProvider
getCapability
-
-
-
-
Field Detail
-
caps
private ICapabilityProvider[] caps
-
writers
private INBTSerializable<INBT>[] writers
-
names
private java.lang.String[] names
-
listeners
private final java.util.List<java.lang.Runnable> listeners
-
-
Constructor Detail
-
CapabilityDispatcher
public CapabilityDispatcher(java.util.Map<ResourceLocation,ICapabilityProvider> list, java.util.List<java.lang.Runnable> listeners)
-
CapabilityDispatcher
public CapabilityDispatcher(java.util.Map<ResourceLocation,ICapabilityProvider> list, java.util.List<java.lang.Runnable> listeners, @Nullable ICapabilityProvider parent)
-
-
Method Detail
-
getCapability
public <T> LazyOptional<T> getCapability(Capability<T> cap, @Nullable Direction side)
Description copied from interface:ICapabilityProvider
Retrieves the Optional handler for the capability requested on the specific side. The return value CAN be the same for multiple faces. Modders are encouraged to cache this value, using the listener capabilities of the Optional to be notified if the requested capability get lost.- Specified by:
getCapability
in interfaceICapabilityProvider
- Returns:
- The requested an optional holding the requested capability.
-
serializeNBT
public CompoundNBT serializeNBT()
- Specified by:
serializeNBT
in interfaceINBTSerializable<CompoundNBT>
-
deserializeNBT
public void deserializeNBT(CompoundNBT nbt)
- Specified by:
deserializeNBT
in interfaceINBTSerializable<CompoundNBT>
-
areCompatible
public boolean areCompatible(@Nullable CapabilityDispatcher other)
-
invalidate
public void invalidate()
-
-