56 lines
2 KiB
Java
56 lines
2 KiB
Java
package com.example.examplemod;
|
|
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.init.Blocks;
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
import net.minecraftforge.event.RegistryEvent;
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
import net.minecraftforge.fml.common.Mod;
|
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
|
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
|
|
import net.minecraftforge.fml.javafmlmod.FMLModLoadingContext;
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
// The value here should match an entry in the META-INF/mods.toml file
|
|
@Mod("examplemod")
|
|
public class ExampleMod
|
|
{
|
|
// Directly reference a log4j logger.
|
|
private static final Logger LOGGER = LogManager.getLogger();
|
|
|
|
public ExampleMod() {
|
|
// Register the preInit method for modloading
|
|
FMLModLoadingContext.get().getModEventBus().addListener(this::preInit);
|
|
// Register the init method for modloading
|
|
FMLModLoadingContext.get().getModEventBus().addListener(this::init);
|
|
|
|
// Register ourselves for server, registry and other game events we are interested in
|
|
MinecraftForge.EVENT_BUS.register(this);
|
|
}
|
|
|
|
private void preInit(final FMLPreInitializationEvent event)
|
|
{
|
|
// some preinit code
|
|
LOGGER.info("HELLO FROM PREINIT");
|
|
}
|
|
|
|
private void init(final FMLInitializationEvent event)
|
|
{
|
|
// some example code
|
|
LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
|
|
// register a new block here
|
|
LOGGER.info("HELLO from Register Block");
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public void onServerStarting(FMLServerStartingEvent event) {
|
|
// do something when the server starts
|
|
LOGGER.info("HELLO from server starting");
|
|
}
|
|
}
|