Jump to content

Mod API Light


Tyron

Recommended Posts

Currently interopability between mods is very limited as requires each mod to include some API code before compiling.

I think many mods would require only a small amount of information to be transfered between them to become compatible with each other.

 

As an example, the butterflies in my ButterflyMania mod would only need to know if a particular block is a certain plant, whether it is currently considered food for butterflies and how tall the plant is.

 

It would save a lot of overhead coding, if I just had a simple messaging system or bus that can request such information from a block or item. Similar to existing forge buses or the microsoft windows message system.

 

With such interface it would become very easy for any modder to add compatibility to other mods. It would be like the oredictionary, but for block/item properties instead of recipes.

 

The cost of adding and maintining this code to forge should be comparatively low (= 4-5 new classes below 30 LoC and very few lines of code added to Block.class and Item.class) and the gain for modders pretty high.

 

Example Implementation for blocks (untested pseudo code):

 

// MessageEvent.java:

class MessageEvent {
   public final Class sender;   // Mod Instance
   public final String message;
   public final World world;
   public final BlockPos pos;

   public final Object []params;
}


// MessageResponse.java:

class MessageResponse {
   public final Class responder;  // Mod Instance
   public final Object []params;
}


// in Block.class, which each mod can individually override

public MessageResponse handleMessage(MessageEvent evt) {
   return null;
}



// e.g. in my Butterfly Entity:
double foodblockheight = 0D;

MessageEvent evt = new MessageEvent(ButterflyMania.instance, "foodBlockHeight", worldObj, pos, null);
MessageResponse response = world.getBlockState(pos).getBlock().handleMessage(evt);

if (response != null && response.params.length == 1 && response.params[0] instanceof Double) {
  foodblockheight = (Double)response.params[0];
}

 

I can try to make a pull request if this idea has a chance of getting accepted.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.