MattiDragon / TlaApi

An abstraction layer over recipe viewer apis for minecraft
https://modrinth.com/project/tla-api
MIT License
5 stars 1 forks source link
fabricmc-mod minecraft-mod

TLA Api

Badge showing the amount of downloads on modrinth Badge showing the amount of downloads on curseforge Badge linking to issues on github Badge linking to support on discord

TLA api is an abstraction layer over recipe viewer apis for minecraft. It allows mod developers to write their recipe viewer integration once and have it work with multiple recipe viewers. Currently supported recipe viewers are: EMI, REI and JEI

Usage

Gradle

TLA api is available on jitpack. Add the following to your build.gradle to use it:

repositories {
    maven {
        url "https://jitpack.io"
    }
}

dependencies {
    modImplementation "com.github.mattidragon:TlaApi:${tla_api_version}"
    include "com.github.mattidragon:TlaApi:${tla_api_version}"
}

Entrypoint

To use the api you need to implement the TlaApiPlugin interface and add your implementation to the tla-api entrypoint. Note that the entire api is client side only. If you are using split source sets, you need to implement the api in the client source set.

public class MyTlaPlugin implements TlaApiPlugin {
    @Override
    public void register(PluginContext context) {
        // Register your api here
    }
}
{
  "entrypoints": {
    "tla-api": [
      "my.package.MyTlaPlugin"
    ]
  }
}

Registering Content

Once you've set up your entrypoint you can begin registering content. The entire api is documented using javadocs, so you can use your IDE to explore the api. The api design is mostly based on EMIs, but I've had to make some changes to accommodate REI and JEI.

Things to Consider

While the TLA api abstracts everything, you will still need to verify yourself that your code works with all> recipe viewers. For example, you still need to translate all of your tags for EMI. Some widgets might also render slightly differently.

A useful thing to look for while using the api are the following annotations. They help with explaining how the api should be used.

Questions

Q: Does this allow mods that only support one viewer to work on both?

A: No. This api just makes it easier for mod developers to support all recipe viewers.

Q: Why is this api client side only?

A: EMIs entire api is client side only. REI has a server side api, but it doesn't contain any features that TLA uses.

Q: Are there any examples?

A: Yes, you can find the test mod here. It does a few things you wouldn't normally do, but generally does a good job of showing off the api.