mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 19:15:32 +00:00
Added Capability.cast, to allow avoiding unchecked casts in ICapabilityProvider.getCapability
This commit is contained in:
1 parent
a4d5760539
commit
08663587d4
13 files changed
+33
-20
No files matched your search
@@ -92,6 +92,17 @@ public class Capability<T>
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this inside ICapabilityProvider.getCapability to avoid unchecked cast warnings.
|
||||
* Example: return SOME_CAPABILITY.cast(instance);
|
||||
* Use with caution;
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <R> R cast(T instance)
|
||||
{
|
||||
return (R)instance;
|
||||
}
|
||||
|
||||
// INTERNAL
|
||||
private final String name;
|
||||
private final IStorage<T> storage;
|
||||
|
||||
@@ -47,12 +47,11 @@ public class CapabilityAnimation
|
||||
return capability == ANIMATION_CAPABILITY;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
|
||||
{
|
||||
if(capability == ANIMATION_CAPABILITY)
|
||||
{
|
||||
return (T)asm;
|
||||
return ANIMATION_CAPABILITY.cast(asm);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user