// The value here should match an entry in the META-INF/mods.toml file @Mod(ExampleMod.MODID) publicclassExampleMod { // Define mod id in a common place for everything to reference publicstaticfinalStringMODID="examplemod"; // Directly reference a slf4j logger privatestaticfinalLoggerLOGGER= LogUtils.getLogger();
// Register the commonSetup method for modloading modEventBus.addListener(this::commonSetup); // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); }
privatevoidcommonSetup(final FMLCommonSetupEvent event) { // Some common setup code LOGGER.info("HELLO FROM COMMON SETUP"); LOGGER.info("DIRT BLOCK >> {}", ForgeRegistries.BLOCKS.getKey(Blocks.DIRT)); }
// You can use SubscribeEvent and let the Event Bus discover methods to call @SubscribeEvent publicvoidonServerStarting(ServerStartingEvent event) { // Do something when the server starts LOGGER.info("HELLO from server starting"); }
// You can use EventBusSubscriber to automatically register all static methods in the class annotated with @SubscribeEvent @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD) publicstaticclassClientModEvents { @SubscribeEvent publicstaticvoidonClientSetup(FMLClientSetupEvent event) { // Some client setup code LOGGER.info("HELLO FROM CLIENT SETUP"); LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName()); } } }