add entrypoints.md file
This commit is contained in:
parent
bce61eea21
commit
bb8a418c81
|
@ -1 +0,0 @@
|
|||
# ClientExtension
|
90
exts/entrypoints.md
Normal file
90
exts/entrypoints.md
Normal file
|
@ -0,0 +1,90 @@
|
|||
# Entrypoints
|
||||
Entrypoints are a specific type of extension that allows mods to inject code that will run as the game is starting up. They can be thought of as like the `main()` function in a full Program, and are primarily used for adding things to registries, declaring callbacks and events, and other tasks your mod needs to do once during startup.
|
||||
|
||||
## `MainExtension`
|
||||
The `MainExtension` entrypoint contains the core of your mod's initialization code. `MainExtension` will run during the startup sequence on both the server and the client, and thus should be populated with things like registrations (i.e. of blocks, items, entities) and events that are triggered on both the server and client side.
|
||||
The first step to creating a MainExtension entrypoint is to create a class. This should usually be in the root package of your mod, but does not have to be. For this example, we will create a class called `ExampleInit` that implements the interface `MainExtension`:
|
||||
```java
|
||||
package com.example.examplemod;
|
||||
|
||||
public class ExampleInit implements MainExtension {
|
||||
...
|
||||
}
|
||||
```
|
||||
Once this class is created, add it under the `[frog.extensions]` table in your `frog.mod.toml` file with the key `init`:
|
||||
```toml
|
||||
[frog.extensions]
|
||||
...
|
||||
init = "com/example/examplemod/ExampleInit"
|
||||
...
|
||||
```
|
||||
The interface `MainExtension` contains one method, called `onInit`. It takes one `ModProperties` object and returns `void`. We will implement this method by adding a Logger and printing a message:
|
||||
```java
|
||||
package com.example.examplemod;
|
||||
|
||||
import dev.frogmc.frogloader.api.mod.ModProperties;
|
||||
import dev.frogmc.froglib.entrypoints.MainExtension;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public final Logger LOGGER = LoggerFactory.getLogger("ExampleMod");
|
||||
|
||||
public class ExampleInit implements MainExtension {
|
||||
@Override
|
||||
public void onInit(ModProperties mod) {
|
||||
LOGGER.info("ribbit world");
|
||||
}
|
||||
}
|
||||
```
|
||||
Now, when we launch the game with the example mod installed, we will see that message sent when our mod is initialized.
|
||||
|
||||
## `ClientExtension`
|
||||
The `ClientExtension` is very similar to the `MainExtension` in its function as an entrypoint, except it will only run if the mod is installed on the client. This is primarily used for modifying the behavior of rendering, like through custom models or renderers, as well as keybinds and other interactions that are only processed on the client side. To create a ClientExtension entrypoint, the process is very similar; first, we will create a class implementing the interface `ClientExtension`. This class should be annotated with the `@ClientOnly` annotation so that it is only loaded into the classpath on the client. Usually it should be placed in a package specifically for client-related classes.
|
||||
```java
|
||||
package com.example.examplemod.client;
|
||||
|
||||
import dev.frogmc.frogloader.api.mod.ModProperties;
|
||||
import dev.frogmc.frogloader.api.env.ClientOnly;
|
||||
import dev.frogmc.froglib.entrypoints.ClientExtension;
|
||||
|
||||
@ClientOnly
|
||||
public class ExampleClientInit implements ClientExtension {
|
||||
@Override
|
||||
public void onClientInit(ModProperties mod) {
|
||||
...
|
||||
}
|
||||
}
|
||||
```
|
||||
This should also be included in the `[frog.extensions]` table in your `frog.mod.toml`, under the key `client`:
|
||||
```toml
|
||||
[frog.extensions]
|
||||
...
|
||||
client = "com/example/examplemod/client/ExampleClientInit"
|
||||
...
|
||||
```
|
||||
## `ServerExtension`
|
||||
`ServerExtension` is very similar to `ClientExtension` in implementation, except it runs only on the dedicated server. It does **not** run on the internal server. To create a ServerExtension entrypoint, create a class implementing `ServerExtension` annotated with `@ServerOnly`.
|
||||
```java
|
||||
package com.example.examplemod.server;
|
||||
|
||||
import dev.frogmc.frogloader.api.mod.ModProperties;
|
||||
import dev.frogmc.frogloader.api.env.ServerOnly;
|
||||
import dev.frogmc.froglib.entrypoints.ServerExtension;
|
||||
|
||||
@ServerOnly
|
||||
public class ExampleServerInit implements ServerExtension {
|
||||
@Override
|
||||
public void onServerInit(ModProperties mod) {
|
||||
...
|
||||
}
|
||||
}
|
||||
```
|
||||
Add this to the `[frog.extensions] table in your `frog.mod.toml` file, under the key `server`:
|
||||
```toml
|
||||
[frog.extensions]
|
||||
...
|
||||
server = "com/example/examplemod/server/ExampleServerInit"
|
||||
...
|
||||
```
|
||||
|
|
@ -1 +0,0 @@
|
|||
# MainEntrypoint
|
|
@ -1 +0,0 @@
|
|||
# ServerExtension
|
12
spec/fmt.md
12
spec/fmt.md
|
@ -25,7 +25,8 @@ The `[frog.dependencies]` table contains information about this mod's dependenci
|
|||
##### Mod
|
||||
The Mod inline table contains information referencing a mod other than your own. It contains the following fields:
|
||||
- `id`: the other mods namespace id. Should be alphanumeric without spaces and all lowercase, unless the source mod isn't.
|
||||
- `versions`: the range of versions of the other mod that your mod requires. Should be a SemVer version, or a range of SemVer versions (see [this](https://github.com/npm/node-semver#ranges) for a more detailed specification on SemVer ranges). If any version is acceptable, can also be set to `*`. In the `provides` array, this must be an exact version.
|
||||
- `versions`: the range of versions of the other mod that your mod requires. Should be a SemVer version, or a range of SemVer versions (see [this](https://github.com/npm/node-semver#ranges) for a more detailed specification on SemVer ranges). If any version is acceptable, can also be set to `*`. **Use only in `depends`, `breaks`, and `suggests` arrays!**
|
||||
- `version`: a single version of another mod. Should be a SemVer version. **Use only in `provides` array!**
|
||||
- `name`: the formatted name of the required mod. Optional.
|
||||
- `link`: a link to the download page of the mod. Mods from certain sites may be able to be handled specially by frog loader. Optional.
|
||||
|
||||
|
@ -34,9 +35,9 @@ The `[frog.extensions]` table contains information on definitions that modify th
|
|||
- `mixin`: reference to a `.mixins.json` file contained within the `src/resources` folder. See [Mixin](/exts/mixin).
|
||||
- `accesswidener`: reference to a `.accesswidener` file contained within the `src/resources` folder. See [AccessWidener](/exts/aw).
|
||||
- `prelaunch`: reference to a PreLaunch class on the classpath, separated by forward slashes. See [PreLaunch](/exts/prelaunch).
|
||||
- `init`: reference to a MainExtension entrypoint on the classpath, separated by forward slashes. See [MainExtension](/exts/main).
|
||||
- `client`: reference to a ClientExtension entrypoint on the classpath, separated by forward slashes. See [ClientExtension](/exts/client).
|
||||
- `server`: reference to a ServerExtension entrypoint on the classpath, separated by forward slashes. See [ServerExtension](/exts/server).
|
||||
- `init`: reference to a MainExtension entrypoint on the classpath, separated by forward slashes. See [MainExtension](/exts/entrypoints#MainExtension).
|
||||
- `client`: reference to a ClientExtension entrypoint on the classpath, separated by forward slashes. See [ClientExtension](/exts/entrypoints#ClientExtension).
|
||||
- `server`: reference to a ServerExtension entrypoint on the classpath, separated by forward slashes. See [ServerExtension](/exts/entrypoints#ServerExtension).
|
||||
|
||||
#### Internal Keys
|
||||
The `included_jars` and `phytotelma.generated` keys are inserted by the [Phytotelma](/contributing/tools#phytotelma) tool and should not be edited manually.
|
||||
|
@ -74,6 +75,9 @@ provides = [
|
|||
mixin = "example_mod.mixins.json"
|
||||
accesswidener = "example_mod.accesswidener"
|
||||
prelaunch = "com/example/frog/PreLaunch"
|
||||
init = "com/example/frog/FrogInit"
|
||||
client = "com/example/frog/client/FrogClientInit"
|
||||
server = "com/example/frog/server/FrogServerInit"
|
||||
|
||||
included_jars = [
|
||||
{ id = "mod_id", path = "META-INF/jars/mod.jar" }
|
||||
|
|
Loading…
Reference in a new issue