From 486d5afa685fa463fe648589a0ba8e0db68b20eb Mon Sep 17 00:00:00 2001 From: cpw Date: Sun, 30 Sep 2018 14:29:03 -0400 Subject: [PATCH] fix up the examplemod for new FML and add a couple of extra bits. --- .../com/example/examplemod/ExampleMod.java | 51 ++++++++++++----- mdk/src/main/resources/META-INF/mods.toml | 57 +++++++++++++++++++ mdk/src/main/resources/mcmod.info | 16 ------ mdk/src/main/resources/pack.mcmeta | 4 +- 4 files changed, 97 insertions(+), 31 deletions(-) create mode 100644 mdk/src/main/resources/META-INF/mods.toml delete mode 100644 mdk/src/main/resources/mcmod.info diff --git a/mdk/src/main/java/com/example/examplemod/ExampleMod.java b/mdk/src/main/java/com/example/examplemod/ExampleMod.java index 42a155b77..329ecabc8 100644 --- a/mdk/src/main/java/com/example/examplemod/ExampleMod.java +++ b/mdk/src/main/java/com/example/examplemod/ExampleMod.java @@ -1,31 +1,56 @@ 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.Mod.EventHandler; 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; -@Mod(modid = ExampleMod.MODID, name = ExampleMod.NAME, version = ExampleMod.VERSION) +// The value here should match an entry in the META-INF/mods.toml file +@Mod("examplemod") public class ExampleMod { - public static final String MODID = "examplemod"; - public static final String NAME = "Example Mod"; - public static final String VERSION = "1.0"; + // Directly reference a log4j logger. + private static final Logger LOGGER = LogManager.getLogger(); - private static Logger logger; + 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); - @EventHandler - public void preInit(FMLPreInitializationEvent event) - { - logger = event.getModLog(); + // Register ourselves for server, registry and other game events we are interested in + MinecraftForge.EVENT_BUS.register(this); } - @EventHandler - public void init(FMLInitializationEvent event) + 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()); + LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName()); + } + + @SubscribeEvent + public void onBlocksRegistry(final RegistryEvent.Register 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"); } } diff --git a/mdk/src/main/resources/META-INF/mods.toml b/mdk/src/main/resources/META-INF/mods.toml new file mode 100644 index 000000000..f012d48cf --- /dev/null +++ b/mdk/src/main/resources/META-INF/mods.toml @@ -0,0 +1,57 @@ +# This is an example mods.toml file. It contains the data relating to the loading mods. +# There are several mandatory fields (#mandatory), and many more that are optional (#optional). +# The overall format is standard TOML format, v0.5.0. +# Note that there are a couple of TOML lists in this file. +# Find more information on toml format here: https://github.com/toml-lang/toml +# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml +modLoader="javafml" #mandatory +# A version range to match for said mod loader - for regular FML @Mod it will be the minecraft version (without the 1.) +loaderVersion="[13,)" #mandatory +# A URL to query for updates for this mod. See the JSON update specification +updateJSONURL="http://myurl.me/" #optional +# A URL to refer people to when problems occur with this mod +issueTrackerURL="http://my.issue.tracker/" #optional +# A URL for the "homepage" for this mod, displayed in the mod UI +displayURL="http://example.com/" #optional +# A file name (in the root of the mod JAR) containing a logo for display +logoFile="examplemod.png" #optional +# A text field displayed in the mod UI +credits="Thanks for this example mod goes to Java" #optional +# A text field displayed in the mod UI +authors="Love, Cheese and small house plants" #optional +# A list of mods - how many allowed here is determined by the individual mod loader +[[mods]] #mandatory +# The modid of the mod +modId="examplemod" #mandatory +# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it +version="1.0" #mandatory + # A display name for the mod +displayName="Example Mod" #mandatory +# The description text for the mod (multi line!) (#mandatory) +description=''' +This is a long form description of the mod. You can write whatever you want here + +Have some lorem ipsum. + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mollis lacinia magna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed sagittis luctus odio eu tempus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Pellentesque volutpat ligula eget lacus auctor sagittis. In hac habitasse platea dictumst. Nunc gravida elit vitae sem vehicula efficitur. Donec mattis ipsum et arcu lobortis, eleifend sagittis sem rutrum. Cras pharetra quam eget posuere fermentum. Sed id tincidunt justo. Lorem ipsum dolor sit amet, consectetur adipiscing elit. +''' + +# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. +[[dependencies.examplemod]] #optional + # the modid of the dependency + modId="forge" #mandatory + # Does this dependency have to exist - if not, ordering below must be specified + mandatory=true #mandatory + # The version range of the dependency + versionRange="[14.23.2.0,)" #mandatory + # An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory + ordering="NONE" + # Side this dependency is applied on - BOTH, CLIENT or SERVER + side="BOTH" +# Here's another dependency +[[dependencies.examplemod]] + modId="minecraft" + mandatory=true + versionRange="[1.13]" + ordering="NONE" + side="BOTH" \ No newline at end of file diff --git a/mdk/src/main/resources/mcmod.info b/mdk/src/main/resources/mcmod.info deleted file mode 100644 index f48066756..000000000 --- a/mdk/src/main/resources/mcmod.info +++ /dev/null @@ -1,16 +0,0 @@ -[ -{ - "modid": "examplemod", - "name": "Example Mod", - "description": "Example placeholder mod.", - "version": "${version}", - "mcversion": "${mcversion}", - "url": "", - "updateUrl": "", - "authorList": ["ExampleDude"], - "credits": "The Forge and FML guys, for making this example", - "logoFile": "", - "screenshots": [], - "dependencies": [] -} -] diff --git a/mdk/src/main/resources/pack.mcmeta b/mdk/src/main/resources/pack.mcmeta index 401826761..42ab49051 100644 --- a/mdk/src/main/resources/pack.mcmeta +++ b/mdk/src/main/resources/pack.mcmeta @@ -1,7 +1,7 @@ { "pack": { "description": "examplemod resources", - "pack_format": 3, - "_comment": "A pack_format of 3 should be used starting with Minecraft 1.11. All resources, including language files, should be lowercase (eg: en_us.lang). A pack_format of 2 will load your mod resources with LegacyV2Adapter, which requires language files to have uppercase letters (eg: en_US.lang)." + "pack_format": 4, + "_comment": "A pack_format of 4 requires json lang files. Note: we require v4 pack meta for all mods." } }