From b496094ed4155595811d9e84a37e197c12ae65c6 Mon Sep 17 00:00:00 2001 From: "neoforge-mdk-automation[bot]" <173375039+neoforge-mdk-automation[bot]@users.noreply.github.com> Date: Thu, 12 Jun 2025 21:29:15 +0800 Subject: Update MDK with new output from mod generator (#2) Co-authored-by: NeoForge MDK Automation <173375039+neoforge-mdk-automation[bot]@users.noreply.github.com> --- src/main/java/com/example/examplemod/Config.java | 27 ++++------------------ .../java/com/example/examplemod/ExampleMod.java | 6 ++--- .../com/example/examplemod/ExampleModClient.java | 18 +++++++++++++++ 3 files changed, 25 insertions(+), 26 deletions(-) create mode 100644 src/main/java/com/example/examplemod/ExampleModClient.java (limited to 'src/main/java/com/example') 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> ITEM_STRINGS = BUILDER + public static final ModConfigSpec.ConfigValue> 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 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 -- cgit v1.2.3