Entrypoint
Abstract
Here we register our entrypoint to fabric.mod.json
"entrypoints": {
"dashloader": [
"you.yourmod.compat.dashloader.DashLoaderCompatibility"
]
},
This is our implementation of the Entrypoint
public class DashLoaderCompatibility implements DashEntrypoint/* (1)! */{
/* (2)! */
@Override
public void onDashLoaderInit(CacheFactory factory) {
factory.addDashObject(DashMyObject.class)/* (3)! */;
factory.addModule(new MyModule())/* (4)! */;
/* (5)! */
factory.addMissingHandler(MyGoofyObject.class, (goofyObject, registryWriter) -> {
if (goofyObject instanceof LessGoofyableObject m) {
return new DashMyObject(m.innerCoolness);
} else {
return null;
}
})
}
}
- We implement DashEntrypoint to get access to the methods
- This method gets run once every time DashLoader initializes (once every session).
- Here we register our custom DashObject to DashLoader.
- Here we can register a custom module to DashLoader.
- We can add a custom MissingHandler to the DashRegistry which is a fallback function if the registry cannot find a DashObject.
Real world example
DashLoader has a Fabric API Entrypoint for registering DashObjects, Modules and Missing Handlers.
You simply create a class which implements DashEntrypoint
and add it to your fabric.mod.json under the dashloader
key
"entrypoints": {
"dashloader": [
"you.yourmod.compat.dashloader.DashLoaderCompatibility"
]
},
public class DashLoaderCompatibility implements DashEntrypoint {
@Override
public void onDashLoaderInit(CacheFactory factory) {
}
}
Adding DashObjects
After you have made your DashObject you need to tell DashLoader about it. You do this by calling addDashObject
in CacheFactory
@Override
public void onDashLoaderInit(CacheFactory factory) {
factory.addDashObject(DashMyObject.class);
}
Adding Modules
If you want to add a custom module, you need to tell DashLoader about it by calling addModule
in CacheFactory
@Override
public void onDashLoaderInit(CacheFactory factory) {
factory.addModule(new MyModule());
}
MissingHandlers
When a DashLoader registry fails to find a DashObject for a given Object it will resort to its last option, MissingHandler
s.
These are functions which check if the object is one of a fallbackable kind and map it to a bruhDashObject else it will return null
and let the other MissingHandlers find a use for it, if the registry runs out of MissingHandlers before its found a non-null returning handler, it will throw an exception saying that it was unable to add the object to the registry.
@Override
public void onDashLoaderInit(CacheFactory factory) {
factory.addMissingHandler(
MyGoofyObject.class/* (1)! */,
(goofyObject, registryWriter) -> {
if (goofyObject instanceof LessGoofyableObject m) {
return new DashMyObject(m.innerCoolness)/* (2)! */;
} else {
return null/* (3)! */;
}
}
);
}
- This is the class the registry will be matching towards. If it finds that the object is of that class or one of its sub types it will call this function in hopes of getting a DashObject out of it.
- We have found a LessGoofyableObject! Which in this example has the same fields as MyObject, so we create a DashMyObject and everything is awesome!
- Returning null lets the Registry go on trying to find a way to serialize the object another way.