Skip to content

Mod Integration for Developers

TheIllusiveC4 edited this page Mar 9, 2021 · 3 revisions

Diet uses InterModComms (IMC) provided by Forge in order to facilitate basic compatibility between itself and food mods.

Due to the use of function currying and wrapper objects, some of the syntax is a little verbose and un-intuitive but the main benefit is that mods can implement integration with zero dependency on Diet itself. This guide is written to help illustrate compatibility steps to mitigate any confusion on its usage.

Methods

Diet currently provides one main method - "item".

"item" - This is used for item overrides. This can be used for dictating ingredients of composite foods or providing correct food values for dynamic foods.

  • Message Type: Tuple<Item, BiFunction<PlayerEntity, ItemStack, Triple<List<ItemStack>, Integer, Float>>>

Walkthrough

First, developers need to setup a listener for the InterModEnqueue event which is posted on the Mod event bus.

public ExampleMod() {
  FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueue);
}

private void enqueue(final InterModEnqueueEvent evt) {

  if (ModList.get().isLoaded("diet")) {
    // Send your IMC messages here
  }
}

To send the message, developers need to call the InterModComms#sendTo method with the appropriate arguments.

InterModComms.sendTo("mod_id", "method", () -> thing);

For example, if developers wanted to send an item override, it would look like this:

InterModComms.sendTo("diet", "item",
        () -> new Tuple<Item, BiFunction<PlayerEntity, ItemStack, Triple<List<ItemStack>, Integer, Float>>>(
            item,
            (player, stack) -> new ImmutableTriple<>(Collections.singletonList(stack), 1, 0.1f));

And that's really it. Just send the appropriate message with the right message type and Diet will handle the processing without any dependencies needed on the developer's end.

Examples

Comments? Concerns?

Diet is a new mod and so the API and integration methods are currently experimental. If you have concerns or suggestions about improvements, please open an issue on the issue tracker and I'll be in touch to begin a discussion.

Clone this wiki locally