ericl16384

Untitled

Mar 26th, 2021
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.95 KB | None | 0 0
  1. package com.ericl5445.testmod1;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.block.Blocks;
  5. import net.minecraftforge.common.MinecraftForge;
  6. import net.minecraftforge.event.RegistryEvent;
  7. import net.minecraftforge.eventbus.api.SubscribeEvent;
  8. import net.minecraftforge.fml.InterModComms;
  9. import net.minecraftforge.fml.common.Mod;
  10. import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
  11. import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
  12. import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
  13. import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
  14. import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
  15. import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
  16. import org.apache.logging.log4j.LogManager;
  17. import org.apache.logging.log4j.Logger;
  18.  
  19. import java.util.stream.Collectors;
  20.  
  21. // The value here should match an entry in the META-INF/mods.toml file
  22. // This is the mod id, which needs to be unique
  23. // It may only be lowercase, numbers, and underscores
  24. @Mod(TestMod1.MOD_ID)
  25. public class TestMod1 {
  26.     // Directly reference a log4j logger.
  27.     public static final Logger LOGGER = LogManager.getLogger();
  28.  
  29.     // For easy use
  30.     public static final String MOD_ID = "ericl5445_testmod1";
  31.  
  32.     public TestMod1() {
  33.         IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
  34.  
  35.         // Register the setup method for modloading
  36.         bus.addListener(this::setup);
  37.  
  38.         // Register the items to the game
  39.         ItemInit.ITEMS.register(bus);
  40. /*
  41.         // Register the enqueueIMC method for modloading
  42.         FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
  43.         // Register the processIMC method for modloading
  44.         FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
  45.         // Register the doClientStuff method for modloading
  46.         FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
  47.  
  48.         // Register ourselves for server and other game events we are interested in
  49.         MinecraftForge.EVENT_BUS.register(this);
  50. */
  51.     }
  52.  
  53.     private void setup(final FMLCommonSetupEvent event) {
  54. /*
  55.         // some preinit code
  56.         LOGGER.info("HELLO FROM PREINIT");
  57.         LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
  58. */
  59.     }
  60. /*
  61.     private void doClientStuff(final FMLClientSetupEvent event) {
  62.         // do something that can only be done on the client
  63.         LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
  64.     }
  65.  
  66.     private void enqueueIMC(final InterModEnqueueEvent event)
  67.     {
  68.         // some example code to dispatch IMC to another mod
  69.         InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";});
  70.     }
  71.  
  72.     private void processIMC(final InterModProcessEvent event)
  73.     {
  74.         // some example code to receive and process InterModComms from other mods
  75.         LOGGER.info("Got IMC {}", event.getIMCStream().
  76.                 map(m->m.getMessageSupplier().get()).
  77.                 collect(Collectors.toList()));
  78.     }
  79.     // You can use SubscribeEvent and let the Event Bus discover methods to call
  80.     @SubscribeEvent
  81.     public void onServerStarting(FMLServerStartingEvent event) {
  82.         // do something when the server starts
  83.         LOGGER.info("HELLO from server starting");
  84.     }
  85.  
  86.     // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
  87.     // Event bus for receiving Registry Events)
  88.     @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
  89.     public static class RegistryEvents {
  90.         @SubscribeEvent
  91.         public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
  92.             // register a new block here
  93.             LOGGER.info("HELLO from Register Block");
  94.         }
  95.     }
  96. */
  97. }
  98.  
Advertisement
Add Comment
Please, Sign In to add comment