summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorneoforge-mdk-automation[bot] <173375039+neoforge-mdk-automation[bot]@users.noreply.github.com>2025-06-12 21:29:15 +0800
committerGitHub <noreply@github.com>2025-06-12 21:29:15 +0800
commitb496094ed4155595811d9e84a37e197c12ae65c6 (patch)
tree8c105abcfe4232a25e68d6161a7dec5cec43efa6 /src
parent90dd7a64391827525d792268c99cfc5a0e86c2e9 (diff)
Update MDK with new output from mod generator (#2)
Co-authored-by: NeoForge MDK Automation <173375039+neoforge-mdk-automation[bot]@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/example/examplemod/Config.java27
-rw-r--r--src/main/java/com/example/examplemod/ExampleMod.java6
-rw-r--r--src/main/java/com/example/examplemod/ExampleModClient.java18
-rw-r--r--src/main/resources/assets/examplemod/lang/en_us.json10
-rw-r--r--src/main/templates/META-INF/neoforge.mods.toml1
5 files changed, 35 insertions, 27 deletions
diff --git a/src/main/java/com/example/examplemod/Config.java b/src/main/java/com/example/examplemod/Config.java
index d70d1eb..6f8636d 100644
--- a/src/main/java/com/example/examplemod/Config.java
+++ b/src/main/java/com/example/examplemod/Config.java
@@ -14,16 +14,15 @@ import net.neoforged.neoforge.common.ModConfigSpec;
// An example config class. This is not required, but it's a good idea to have one to keep your config organized.
// Demonstrates how to use Neo's config APIs
-@EventBusSubscriber(modid = ExampleMod.MODID, bus = EventBusSubscriber.Bus.MOD)
public class Config
{
private static final ModConfigSpec.Builder BUILDER = new ModConfigSpec.Builder();
- private static final ModConfigSpec.BooleanValue LOG_DIRT_BLOCK = BUILDER
+ public static final ModConfigSpec.BooleanValue LOG_DIRT_BLOCK = BUILDER
.comment("Whether to log the dirt block on common setup")
.define("logDirtBlock", true);
- private static final ModConfigSpec.IntValue MAGIC_NUMBER = BUILDER
+ public static final ModConfigSpec.IntValue MAGIC_NUMBER = BUILDER
.comment("A magic number")
.defineInRange("magicNumber", 42, 0, Integer.MAX_VALUE);
@@ -32,32 +31,14 @@ public class Config
.define("magicNumberIntroduction", "The magic number is... ");
// a list of strings that are treated as resource locations for items
- private static final ModConfigSpec.ConfigValue<List<? extends String>> ITEM_STRINGS = BUILDER
+ public static final ModConfigSpec.ConfigValue<List<? extends String>> ITEM_STRINGS = BUILDER
.comment("A list of items to log on common setup.")
- .defineListAllowEmpty("items", List.of("minecraft:iron_ingot"), Config::validateItemName);
+ .defineListAllowEmpty("items", List.of("minecraft:iron_ingot"), () -> "", Config::validateItemName);
static final ModConfigSpec SPEC = BUILDER.build();
- public static boolean logDirtBlock;
- public static int magicNumber;
- public static String magicNumberIntroduction;
- public static Set<Item> items;
-
private static boolean validateItemName(final Object obj)
{
return obj instanceof String itemName && BuiltInRegistries.ITEM.containsKey(ResourceLocation.parse(itemName));
}
-
- @SubscribeEvent
- static void onLoad(final ModConfigEvent event)
- {
- logDirtBlock = LOG_DIRT_BLOCK.get();
- magicNumber = MAGIC_NUMBER.get();
- magicNumberIntroduction = MAGIC_NUMBER_INTRODUCTION.get();
-
- // convert the list of strings into a set of items
- items = ITEM_STRINGS.get().stream()
- .map(itemName -> BuiltInRegistries.ITEM.get(ResourceLocation.parse(itemName)))
- .collect(Collectors.toSet());
- }
}
diff --git a/src/main/java/com/example/examplemod/ExampleMod.java b/src/main/java/com/example/examplemod/ExampleMod.java
index 835a48d..5e5a0c1 100644
--- a/src/main/java/com/example/examplemod/ExampleMod.java
+++ b/src/main/java/com/example/examplemod/ExampleMod.java
@@ -98,12 +98,12 @@ public class ExampleMod
// Some common setup code
LOGGER.info("HELLO FROM COMMON SETUP");
- if (Config.logDirtBlock)
+ if (Config.LOG_DIRT_BLOCK.getAsBoolean())
LOGGER.info("DIRT BLOCK >> {}", BuiltInRegistries.BLOCK.getKey(Blocks.DIRT));
- LOGGER.info(Config.magicNumberIntroduction + Config.magicNumber);
+ LOGGER.info("{}{}", Config.MAGIC_NUMBER_INTRODUCTION.get(), Config.MAGIC_NUMBER.getAsInt());
- Config.items.forEach((item) -> LOGGER.info("ITEM >> {}", item.toString()));
+ Config.ITEM_STRINGS.get().forEach((item) -> LOGGER.info("ITEM >> {}", item));
}
// Add the example block item to the building blocks tab
diff --git a/src/main/java/com/example/examplemod/ExampleModClient.java b/src/main/java/com/example/examplemod/ExampleModClient.java
new file mode 100644
index 0000000..3079631
--- /dev/null
+++ b/src/main/java/com/example/examplemod/ExampleModClient.java
@@ -0,0 +1,18 @@
+package com.example.examplemod;
+
+import net.neoforged.api.distmarker.Dist;
+import net.neoforged.fml.ModContainer;
+import net.neoforged.fml.common.Mod;
+import net.neoforged.neoforge.client.gui.ConfigurationScreen;
+import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
+
+// This class will not load on dedicated servers. Accessing client side code from here is safe.
+@Mod(value = ExampleMod.MODID, dist = Dist.CLIENT)
+public class ExampleModClient {
+ public ExampleModClient(ModContainer container) {
+ // Allows NeoForge to create a config screen for this mod's configs.
+ // The config screen is accessed by going to the Mods screen > clicking on your mod > clicking on config.
+ // Do not forget to add translations for your config options to the en_us.json file.
+ container.registerExtensionPoint(IConfigScreenFactory.class, ConfigurationScreen::new);
+ }
+} \ No newline at end of file
diff --git a/src/main/resources/assets/examplemod/lang/en_us.json b/src/main/resources/assets/examplemod/lang/en_us.json
index 3b34651..4f93bf6 100644
--- a/src/main/resources/assets/examplemod/lang/en_us.json
+++ b/src/main/resources/assets/examplemod/lang/en_us.json
@@ -1,5 +1,13 @@
{
"itemGroup.examplemod": "Example Mod Tab",
"block.examplemod.example_block": "Example Block",
- "item.examplemod.example_item": "Example Item"
+ "item.examplemod.example_item": "Example Item",
+
+ "examplemod.configuration.title": "Example Mod Configs",
+ "examplemod.configuration.section.examplemod.common.toml": "Example Mod Configs",
+ "examplemod.configuration.section.examplemod.common.toml.title": "Example Mod Configs",
+ "examplemod.configuration.items": "Item List",
+ "examplemod.configuration.logDirtBlock": "Log Dirt Block",
+ "examplemod.configuration.magicNumberIntroduction": "Magic Number Text",
+ "examplemod.configuration.magicNumber": "Magic Number"
}
diff --git a/src/main/templates/META-INF/neoforge.mods.toml b/src/main/templates/META-INF/neoforge.mods.toml
index 1b9f6e9..bb66c4c 100644
--- a/src/main/templates/META-INF/neoforge.mods.toml
+++ b/src/main/templates/META-INF/neoforge.mods.toml
@@ -3,6 +3,7 @@
# 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