2013-11-17 18:21:24 -06:00
|
|
|
package com.example.examplemod;
|
|
|
|
|
|
2022-03-01 14:59:27 -06:00
|
|
|
import com.mojang.logging.LogUtils;
|
2021-07-17 00:08:49 -05:00
|
|
|
import net.minecraft.world.level.block.Block;
|
|
|
|
|
import net.minecraft.world.level.block.Blocks;
|
2018-09-30 14:29:03 -04:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
|
import net.minecraftforge.event.RegistryEvent;
|
|
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
2019-01-14 22:42:53 -05:00
|
|
|
import net.minecraftforge.fml.InterModComms;
|
2014-09-22 22:01:24 -07:00
|
|
|
import net.minecraftforge.fml.common.Mod;
|
2019-01-14 22:42:53 -05:00
|
|
|
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
|
|
|
|
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
|
|
|
|
|
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
|
2021-11-30 16:20:48 -08:00
|
|
|
import net.minecraftforge.event.server.ServerStartingEvent;
|
2019-02-13 22:13:59 -05:00
|
|
|
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
2022-03-01 14:59:27 -06:00
|
|
|
import org.slf4j.Logger;
|
2013-11-17 18:21:24 -06:00
|
|
|
|
2019-01-14 22:42:53 -05:00
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
2018-09-30 14:29:03 -04:00
|
|
|
// The value here should match an entry in the META-INF/mods.toml file
|
|
|
|
|
@Mod("examplemod")
|
2013-11-17 18:21:24 -06:00
|
|
|
public class ExampleMod
|
|
|
|
|
{
|
2022-03-01 14:59:27 -06:00
|
|
|
// Directly reference a slf4j logger
|
|
|
|
|
private static final Logger LOGGER = LogUtils.getLogger();
|
2018-01-12 23:54:29 -08:00
|
|
|
|
2022-03-01 14:59:27 -06:00
|
|
|
public ExampleMod()
|
|
|
|
|
{
|
2019-01-14 22:42:53 -05:00
|
|
|
// Register the setup method for modloading
|
2019-02-13 22:13:59 -05:00
|
|
|
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
|
2019-01-14 22:42:53 -05:00
|
|
|
// Register the enqueueIMC method for modloading
|
2019-02-13 22:13:59 -05:00
|
|
|
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
|
2019-01-14 22:42:53 -05:00
|
|
|
// Register the processIMC method for modloading
|
2019-02-13 22:13:59 -05:00
|
|
|
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
|
2018-01-12 23:54:29 -08:00
|
|
|
|
2019-02-15 21:53:52 -05:00
|
|
|
// Register ourselves for server and other game events we are interested in
|
2018-09-30 14:29:03 -04:00
|
|
|
MinecraftForge.EVENT_BUS.register(this);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 22:42:53 -05:00
|
|
|
private void setup(final FMLCommonSetupEvent event)
|
2018-01-12 23:54:29 -08:00
|
|
|
{
|
2018-09-30 14:29:03 -04:00
|
|
|
// some preinit code
|
|
|
|
|
LOGGER.info("HELLO FROM PREINIT");
|
2019-01-14 22:42:53 -05:00
|
|
|
LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void enqueueIMC(final InterModEnqueueEvent event)
|
2013-11-17 18:21:24 -06:00
|
|
|
{
|
2022-03-01 14:59:27 -06:00
|
|
|
// Some example code to dispatch IMC to another mod
|
2019-02-15 21:53:52 -05:00
|
|
|
InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";});
|
2018-09-30 14:29:03 -04:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 22:42:53 -05:00
|
|
|
private void processIMC(final InterModProcessEvent event)
|
|
|
|
|
{
|
2022-03-01 14:59:27 -06:00
|
|
|
// Some example code to receive and process InterModComms from other mods
|
2019-02-16 17:42:30 -05:00
|
|
|
LOGGER.info("Got IMC {}", event.getIMCStream().
|
2021-07-17 00:08:49 -05:00
|
|
|
map(m->m.messageSupplier().get()).
|
2019-01-14 22:42:53 -05:00
|
|
|
collect(Collectors.toList()));
|
|
|
|
|
}
|
2022-03-01 14:59:27 -06:00
|
|
|
|
2019-01-14 22:42:53 -05:00
|
|
|
// You can use SubscribeEvent and let the Event Bus discover methods to call
|
2018-09-30 14:29:03 -04:00
|
|
|
@SubscribeEvent
|
2022-03-01 14:59:27 -06:00
|
|
|
public void onServerStarting(ServerStartingEvent event)
|
|
|
|
|
{
|
|
|
|
|
// Do something when the server starts
|
2019-02-13 22:13:59 -05:00
|
|
|
LOGGER.info("HELLO from server starting");
|
2018-09-30 14:29:03 -04:00
|
|
|
}
|
|
|
|
|
|
2019-02-15 21:53:52 -05:00
|
|
|
// You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
|
|
|
|
|
// Event bus for receiving Registry Events)
|
2022-03-01 14:59:27 -06:00
|
|
|
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
|
|
|
|
|
public static class RegistryEvents
|
|
|
|
|
{
|
2019-01-14 22:42:53 -05:00
|
|
|
@SubscribeEvent
|
2022-03-01 14:59:27 -06:00
|
|
|
public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent)
|
|
|
|
|
{
|
|
|
|
|
// Register a new block here
|
2019-02-13 22:13:59 -05:00
|
|
|
LOGGER.info("HELLO from Register Block");
|
2019-01-14 22:42:53 -05:00
|
|
|
}
|
2013-11-17 18:21:24 -06:00
|
|
|
}
|
|
|
|
|
}
|