summaryrefslogtreecommitdiff
path: root/src/main/java/com/example/examplemod/ExampleMod.java
diff options
context:
space:
mode:
authorPaint_Ninja <PaintNinja@users.noreply.github.com>2023-06-27 12:57:20 +0100
committerGitHub <noreply@github.com>2023-06-27 13:57:20 +0200
commit6d6d2a37322c9918b30e0d114e8dff2d8fb111a5 (patch)
tree0274aac1d7f4263043b8c7a182bba25e62bdb663 /src/main/java/com/example/examplemod/ExampleMod.java
parent7e52cbf56aad127bd5e543cda9138041c00bcd04 (diff)
Add example usage for configs to the MDK (#9596)
Demonstrates proper usage of different config value types, validation, transformation/parsing, load/reload handling and direct field access.
Diffstat (limited to 'src/main/java/com/example/examplemod/ExampleMod.java')
-rw-r--r--src/main/java/com/example/examplemod/ExampleMod.java13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/main/java/com/example/examplemod/ExampleMod.java b/src/main/java/com/example/examplemod/ExampleMod.java
index d345370..990fd63 100644
--- a/src/main/java/com/example/examplemod/ExampleMod.java
+++ b/src/main/java/com/example/examplemod/ExampleMod.java
@@ -18,7 +18,9 @@ import net.minecraftforge.event.BuildCreativeModeTabContentsEvent;
import net.minecraftforge.event.server.ServerStartingEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
+import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
+import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@@ -78,13 +80,22 @@ public class ExampleMod
// Register the item to a creative tab
modEventBus.addListener(this::addCreative);
+
+ // Register our mod's ForgeConfigSpec so that Forge can create and load the config file for us
+ ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, Config.SPEC);
}
private void commonSetup(final FMLCommonSetupEvent event)
{
// Some common setup code
LOGGER.info("HELLO FROM COMMON SETUP");
- LOGGER.info("DIRT BLOCK >> {}", ForgeRegistries.BLOCKS.getKey(Blocks.DIRT));
+
+ if (Config.logDirtBlock)
+ LOGGER.info("DIRT BLOCK >> {}", ForgeRegistries.BLOCKS.getKey(Blocks.DIRT));
+
+ LOGGER.info(Config.magicNumberIntroduction + Config.magicNumber);
+
+ Config.items.forEach((item) -> LOGGER.info("ITEM >> {}", item.toString()));
}
// Add the example block item to the building blocks tab