I thought it would be nice to have it. target version : forge-1.12-14.21.1.2426
Premise After downloading the MDK, the project setup has been completed.
Below source code
CommonProxy.java
package examplemod.proxy;
import examplemod.ExampleMod;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
/***
*Loads items, blocks, and tools common to clients and servers.
*
* @author youname
*
*/
@Mod.EventBusSubscriber
public class CommonProxy {
public void preInit(FMLPreInitializationEvent event) {
ExampleMod.logger.info("CommonProxy.preInit");
}
public void init(FMLInitializationEvent event) {
ExampleMod.logger.info("CommonProxy.init");
}
public void postInit(FMLPostInitializationEvent event) {
ExampleMod.logger.info("CommonProxy.postInit");
}
@SubscribeEvent
public static void registerBlocks(RegistryEvent.Register<Block> event) {
ExampleMod.logger.info("CommonProxy.registerBlocks");
}
/***
*Load the item you want to add with the mod.<br>
*Of course, you have to define the item class yourself.
*
* @param event
*/
@SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> event) {
ExampleMod.logger.info("CommonProxy.registerItems");
}
}
ClientProxy.java
package examplemod.proxy;
import examplemod.ExampleMod;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
/***
*Load resources on the client side.
*
* @author youname
*
*/
@Mod.EventBusSubscriber(Side.CLIENT)
public class ClientProxy extends CommonProxy {
@Override
public void preInit(FMLPreInitializationEvent event) {
super.preInit(event);
ExampleMod.logger.info("ClientProxy.preInit");
}
/***
*Loads a block or item model (a file that defines what the texture should be used and the orientation of the texture).<br>
*
* @param event
*/
@SubscribeEvent
public static void registerModels(ModelRegistryEvent event) {
ExampleMod.logger.info("ClientProxy.registerModels");
}
}
ServerProxy.java
package examplemod.proxy;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.relauncher.Side;
/***
*Processing performed on the server side.
*
* @author youname
*
*/
@Mod.EventBusSubscriber(Side.SERVER)
public class ServerProxy extends CommonProxy {
}
ExampleMod.java
package examplemod;
import org.apache.logging.log4j.Logger;
import examplemod.proxy.CommonProxy;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
/***
*In the body of the mod,@By declaring a mod, it will be recognized as the main body.<br>
*The modid string is mcmod.If it is not the same as the modid of info, mcmod.Since info is not read, it is necessary to match the setting value.<br>
*Register blocks and items in Minecraft in this class.<br>
*
* @author myname
* @version forge-1.12-14.21.1.2426
*/
@Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION)
public class ExampleMod {
//Used for mod identification and resource domain names
public static final String MODID = "examplemod";
//Mod version
public static final String VERSION = "0.0.1";
//Proxy (reading process) package hierarchy
public static final String CLIENT_PROXY = "examplemod.proxy.ClientProxy";
public static final String SERVER_PROXY = "examplemod.proxy.ServerProxy";
//Identifies the server, client and holds the instance
@SidedProxy(clientSide = CLIENT_PROXY, serverSide = SERVER_PROXY)
public static CommonProxy proxy;
//I don't understand the necessity
@Mod.Instance
public static ExampleMod instance;
//Used for log output
public static Logger logger;
/***
*It is called first in the method of the mod body.<br>
*Completes things that affect subsequent processing, such as variable initialization.
*
* @param event
*/
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
logger = event.getModLog();
proxy.preInit(event);
}
/***
*Called after preinit.<br>
*So to speak, it is the main method that can be said to be the main body of this mod.<br>
*Anyway, the main thing is handled here.
*
* @param event
*/
@Mod.EventHandler
public void init(FMLInitializationEvent event) {
proxy.init(event);
}
/***
*Called after init. In other words, it is called last in the mod body.<br>
*We will do clean things such as releasing resources and deleting unnecessary data.
*
* @param event
*/
@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event) {
proxy.postInit(event);
}
}
The code is available on Github.
Github Github