Package net.minecraftforge.event
Class AttachCapabilitiesEvent<T>
- java.lang.Object
-
- net.minecraftforge.eventbus.api.Event
-
- net.minecraftforge.eventbus.api.GenericEvent<T>
-
- net.minecraftforge.event.AttachCapabilitiesEvent<T>
-
- All Implemented Interfaces:
net.minecraftforge.eventbus.api.IGenericEvent<T>
public class AttachCapabilitiesEvent<T> extends net.minecraftforge.eventbus.api.GenericEvent<T>
Fired whenever an object with Capabilities support {currently TileEntity/Item/Entity) is created. Allowing for the attachment of arbitrary capability providers. Please note that as this is fired for ALL object creations efficient code is recommended. And if possible use one of the sub-classes to filter your intended objects.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<ResourceLocation,ICapabilityProvider>
caps
private java.util.List<java.lang.Runnable>
listeners
private java.util.List<java.lang.Runnable>
listenersView
private T
obj
private java.util.Map<ResourceLocation,ICapabilityProvider>
view
-
Constructor Summary
Constructors Constructor Description AttachCapabilitiesEvent(java.lang.Class<T> type, T obj)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCapability(ResourceLocation key, ICapabilityProvider cap)
Adds a capability to be attached to this object.void
addListener(java.lang.Runnable listener)
Adds a callback that is fired when the attached object is invalidated.java.util.Map<ResourceLocation,ICapabilityProvider>
getCapabilities()
A unmodifiable view of the capabilities that will be attached to this object.java.util.List<java.lang.Runnable>
getListeners()
T
getObject()
Retrieves the object that is being created, Not much state is set.
-
-
-
Field Detail
-
obj
private final T obj
-
caps
private final java.util.Map<ResourceLocation,ICapabilityProvider> caps
-
view
private final java.util.Map<ResourceLocation,ICapabilityProvider> view
-
listeners
private final java.util.List<java.lang.Runnable> listeners
-
listenersView
private final java.util.List<java.lang.Runnable> listenersView
-
-
Method Detail
-
getObject
public T getObject()
Retrieves the object that is being created, Not much state is set.
-
addCapability
public void addCapability(ResourceLocation key, ICapabilityProvider cap)
Adds a capability to be attached to this object. Keys MUST be unique, it is suggested that you set the domain to your mod ID. If the capability is an instance of INBTSerializable, this key will be used when serializing this capability.- Parameters:
key
- The name of owner of this capability provider.cap
- The capability provider
-
getCapabilities
public java.util.Map<ResourceLocation,ICapabilityProvider> getCapabilities()
A unmodifiable view of the capabilities that will be attached to this object.
-
addListener
public void addListener(java.lang.Runnable listener)
Adds a callback that is fired when the attached object is invalidated. Such as a Entity/TileEntity being removed from world. All attached providers should invalidate all of their held capability instances.
-
getListeners
public java.util.List<java.lang.Runnable> getListeners()
-
-