mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 00:37:52 +00:00
Require CapabilityToken subclasses to be anonymous (#10681)
This commit is contained in:
1 parent
8443262e39
commit
e2ff990601
3 files changed
+14
-15
No files matched your search
@@ -10,18 +10,20 @@ import net.minecraftforge.fml.common.asm.CapabilityTokenSubclass;
|
||||
/**
|
||||
* Inspired by {@link com.google.common.reflect.TypeToken TypeToken}, use a subclass to capture
|
||||
* generic types. Then uses {@link CapabilityTokenSubclass a transformer}
|
||||
* to convert that generic into a string returned by {@link #getType}
|
||||
* to convert that generic into a string returned by {@link #getType}.
|
||||
* This allows us to know the generic type, without having a hard reference to the
|
||||
* class.
|
||||
*
|
||||
* Example usage:
|
||||
* <p>Example usage:</p>
|
||||
* <pre>{@code
|
||||
* public static Capability<IDataHolder> DATA_HOLDER_CAPABILITY
|
||||
* public static final Capability<IDataHolder> DATA_HOLDER_CAPABILITY
|
||||
* = CapabilityManager.get(new CapabilityToken<>(){});
|
||||
* }</pre>
|
||||
*
|
||||
*/
|
||||
public abstract class CapabilityToken<T> {
|
||||
protected CapabilityToken() {}
|
||||
|
||||
protected final String getType() {
|
||||
throw new RuntimeException("This will be implemented by a transformer");
|
||||
}
|
||||
|
||||
@@ -11,12 +11,11 @@ import net.minecraftforge.fluids.capability.IFluidHandlerItem;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
/*
|
||||
* References to Forge's built in capabilities.
|
||||
* References to Forge's built in capabilities.
|
||||
* Modders are recommended to use their own CapabilityTokens for 3rd party caps to maintain soft dependencies.
|
||||
* However, since nobody has a soft dependency on Forge, we expose this as API.
|
||||
*/
|
||||
public class ForgeCapabilities
|
||||
{
|
||||
public class ForgeCapabilities {
|
||||
public static final Capability<IEnergyStorage> ENERGY = CapabilityManager.get(new CapabilityToken<>(){});
|
||||
public static final Capability<IFluidHandler> FLUID_HANDLER = CapabilityManager.get(new CapabilityToken<>(){});
|
||||
public static final Capability<IFluidHandlerItem> FLUID_HANDLER_ITEM = CapabilityManager.get(new CapabilityToken<>(){});
|
||||
|
||||
Reference in new issue
Block a user