Add support for generic filtering of events.

Please DO NOT use this in performance sensitive environments where you will have tons of things added to the listener list.
If that's the case define sub-classes as they have completely separate lists and will thus be more efficient when firing the event.
This commit is contained in:
LexManos committed 2016-09-17 15:08:23 -07:00
1 parent c58a66a816
commit 1107088acb
6 files changed
+126 -16

No files matched your search

@@ -112,6 +112,20 @@ public class TestCapabilityMod
event.addCapability(new ResourceLocation("TestCapabilityMod:DummyCap"), new Provider(event.getTileEntity()));
}
@SuppressWarnings("rawtypes")
@SubscribeEvent
public void attachEvent(AttachCapabilitiesEvent event) //Test Raw type gets everything still.
{
System.currentTimeMillis();
}
@SubscribeEvent
public void attachTileEntity(AttachCapabilitiesEvent<TileEntity> event)
{
if (!(event.getObject() instanceof TileEntity))
throw new IllegalArgumentException("Generic event handler failed! Exprected Tile Entity got " + event.getObject());
}
// Capabilities SHOULD be interfaces, NOT concrete classes, this allows for
// the most flexibility for the implementors.
public static interface IExampleCapability