Advertisement
Guest User

Untitled

a guest
Jan 15th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. package com.example.examplemod;
  2.  
  3. import net.minecraftforge.fml.common.Mod;
  4. import net.minecraftforge.fml.common.Mod.EventHandler;
  5. import net.minecraftforge.fml.common.event.FMLInitializationEvent;
  6. import net.minecraftforge.fml.common.event.FMLInterModComms;
  7.  
  8. import java.util.function.Function;
  9.  
  10. @Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION)
  11. public class ExampleMod
  12. {
  13.     public static final String MODID = "examplemod";
  14.     public static final String VERSION = "1.0";
  15.    
  16.     @EventHandler
  17.     public void init(FMLInitializationEvent event)
  18.     {
  19.         FMLInterModComms.sendFunctionMessage("modWithApi", "requestAPI", "com.example.examplemod.ExampleMod$FunctionCallback");
  20.     }
  21.  
  22.     static ApiInterface modInterface;
  23.  
  24.     public static class FunctionCallback implements Function<ApiInterface, Void> {
  25.  
  26.         @Override
  27.         public Void apply(ApiInterface apiInterface) {
  28.             modInterface = apiInterface;
  29.             return null;
  30.         }
  31.     }
  32.  
  33.     // in YOUR mod
  34.     public interface ApiInterface {
  35.  
  36.  
  37.  
  38.     }
  39.  
  40.     @Mod(modid = "modWithApi")
  41.     public static class MyMod {
  42.  
  43.         @EventHandler
  44.         public void modComms(FMLInterModComms.IMCEvent event) {
  45.             for (FMLInterModComms.IMCMessage message : event.getMessages()) {
  46.                 if (message.isFunctionMessage()) {
  47.                     message.getFunctionValue(ApiInterface.class, Void.class).get().apply(new MyImpl());
  48.                 }
  49.             }
  50.         }
  51.  
  52.     }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement