How to create an Api

UberAffe

New Member
Jul 29, 2019
143
0
0
I have a fairly simple mod that already has a semi dynamic way of registering and dealing with items and their effects based on an Enum.

I know that one sign of a good api is if it is used internally but I am not sure how to go about opening it up/releasing it.

Can someone either explain how I would go about opening up an api/releasing it, or point me at a tutorial?
 

UberAffe

New Member
Jul 29, 2019
143
0
0
A more specific example to my mod:
My mod adds swords that are crafted from Ore blocks(the ones you get with silk touch).
Right now I have them all contained within an enum that also links them to a method controlling their special effects and the swords get registered by looping through that enum, it also is used for registering their recipies.
Basically everything about each kind of sword is determined by the value of it's enum.

I want to make an api that lets someone else add compatibility for mod ores.

Since I have everything dynamically handled based on the information in the enum would I just need to move the file containing the enum and the baseSword class to an API folder and release that? Then they can use EnumHelper to add new values?

Or does the Api just have the basic sword class and an Api class with a single wrapper method that adds to the Enum?

My problem is that I don't know what kind of things need to go into an API for it to properly interact with my code.
 

InfinityRaider

New Member
Jul 29, 2019
1,169
-1
1
Try to have no code in your API, and work with interfaces only, this way the API will always be backwards compatible and it prevents people from coding after code.
 

UberAffe

New Member
Jul 29, 2019
143
0
0
Try to have no code in your API, and work with interfaces only, this way the API will always be backwards compatible and it prevents people from coding after code.
So basically I just need to provide an interface for anything that they might want to extend or have interactions with.

Is that really all there is to it? If it is then damn I have been really overthinking this.
 

InfinityRaider

New Member
Jul 29, 2019
1,169
-1
1
No, you provide an interface with methods. Then you have your own class with implementations for that interface.
For an example you can look at the AgriCraft API:
API base classes: https://github.com/InfinityRaider/A...rc/main/java/com/InfinityRaider/AgriCraft/api
The interface: https://github.com/InfinityRaider/A...om/InfinityRaider/AgriCraft/api/v1/APIv1.java
The implementation: https://github.com/InfinityRaider/A...ityRaider/AgriCraft/apiimpl/v1/APIimplv1.java

So the user of your API would do something like this:
Code:
APIBase apiBase = API.getAPI(1);
if (api.getStatus().isOk() && api.getVersion == 1)  {
   api= (APIv1) apiBase;}

The end user requests a certain version, checks if it is okay and typecasts it. You will have to make sure that you pass the right implementation of your API

EDIT: more information can be found here: http://www.minecraftforum.net/forum...-tutorials/1571434-tutorial-modding-with-apis