Skip to content

Commit a9624d8

Browse files
Update MDK with new output from mod generator
1 parent 177a1ac commit a9624d8

File tree

4 files changed

+34
-27
lines changed

4 files changed

+34
-27
lines changed

src/main/java/com/example/examplemod/Config.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@
1414

1515
// An example config class. This is not required, but it's a good idea to have one to keep your config organized.
1616
// Demonstrates how to use Neo's config APIs
17-
@EventBusSubscriber(modid = ExampleMod.MODID, bus = EventBusSubscriber.Bus.MOD)
1817
public class Config
1918
{
2019
private static final ModConfigSpec.Builder BUILDER = new ModConfigSpec.Builder();
2120

22-
private static final ModConfigSpec.BooleanValue LOG_DIRT_BLOCK = BUILDER
21+
public static final ModConfigSpec.BooleanValue LOG_DIRT_BLOCK = BUILDER
2322
.comment("Whether to log the dirt block on common setup")
2423
.define("logDirtBlock", true);
2524

26-
private static final ModConfigSpec.IntValue MAGIC_NUMBER = BUILDER
25+
public static final ModConfigSpec.IntValue MAGIC_NUMBER = BUILDER
2726
.comment("A magic number")
2827
.defineInRange("magicNumber", 42, 0, Integer.MAX_VALUE);
2928

@@ -32,32 +31,14 @@ public class Config
3231
.define("magicNumberIntroduction", "The magic number is... ");
3332

3433
// a list of strings that are treated as resource locations for items
35-
private static final ModConfigSpec.ConfigValue<List<? extends String>> ITEM_STRINGS = BUILDER
34+
public static final ModConfigSpec.ConfigValue<List<? extends String>> ITEM_STRINGS = BUILDER
3635
.comment("A list of items to log on common setup.")
37-
.defineListAllowEmpty("items", List.of("minecraft:iron_ingot"), Config::validateItemName);
36+
.defineListAllowEmpty("items", List.of("minecraft:iron_ingot"), () -> "", Config::validateItemName);
3837

3938
static final ModConfigSpec SPEC = BUILDER.build();
4039

41-
public static boolean logDirtBlock;
42-
public static int magicNumber;
43-
public static String magicNumberIntroduction;
44-
public static Set<Item> items;
45-
4640
private static boolean validateItemName(final Object obj)
4741
{
4842
return obj instanceof String itemName && BuiltInRegistries.ITEM.containsKey(ResourceLocation.parse(itemName));
4943
}
50-
51-
@SubscribeEvent
52-
static void onLoad(final ModConfigEvent event)
53-
{
54-
logDirtBlock = LOG_DIRT_BLOCK.get();
55-
magicNumber = MAGIC_NUMBER.get();
56-
magicNumberIntroduction = MAGIC_NUMBER_INTRODUCTION.get();
57-
58-
// convert the list of strings into a set of items
59-
items = ITEM_STRINGS.get().stream()
60-
.map(itemName -> BuiltInRegistries.ITEM.getValue(ResourceLocation.parse(itemName)))
61-
.collect(Collectors.toSet());
62-
}
6344
}

src/main/java/com/example/examplemod/ExampleMod.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ private void commonSetup(final FMLCommonSetupEvent event)
9898
// Some common setup code
9999
LOGGER.info("HELLO FROM COMMON SETUP");
100100

101-
if (Config.logDirtBlock)
101+
if (Config.LOG_DIRT_BLOCK.getAsBoolean())
102102
LOGGER.info("DIRT BLOCK >> {}", BuiltInRegistries.BLOCK.getKey(Blocks.DIRT));
103103

104-
LOGGER.info(Config.magicNumberIntroduction + Config.magicNumber);
104+
LOGGER.info("{}{}", Config.MAGIC_NUMBER_INTRODUCTION.get(), Config.MAGIC_NUMBER.getAsInt());
105105

106-
Config.items.forEach((item) -> LOGGER.info("ITEM >> {}", item.toString()));
106+
Config.ITEM_STRINGS.get().forEach((item) -> LOGGER.info("ITEM >> {}", item));
107107
}
108108

109109
// Add the example block item to the building blocks tab
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.example.examplemod;
2+
3+
import net.neoforged.api.distmarker.Dist;
4+
import net.neoforged.fml.ModContainer;
5+
import net.neoforged.fml.common.Mod;
6+
import net.neoforged.neoforge.client.gui.ConfigurationScreen;
7+
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
8+
9+
// This class will not load on dedicated servers. Accessing client side code from here is safe.
10+
@Mod(value = ExampleMod.MODID, dist = Dist.CLIENT)
11+
public class ExampleModClient {
12+
public ExampleModClient(ModContainer container) {
13+
// Allows NeoForge to create a config screen for this mod's configs.
14+
// The config screen is accessed by going to the Mods screen > clicking on your mod > clicking on config.
15+
// Do not forget to add translations for your config options to the en_us.json file.
16+
container.registerExtensionPoint(IConfigScreenFactory.class, ConfigurationScreen::new);
17+
}
18+
}
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
{
22
"itemGroup.examplemod": "Example Mod Tab",
33
"block.examplemod.example_block": "Example Block",
4-
"item.examplemod.example_item": "Example Item"
4+
"item.examplemod.example_item": "Example Item",
5+
6+
"examplemod.configuration.title": "Example Mod Configs",
7+
"examplemod.configuration.section.examplemod.common.toml": "Example Mod Configs",
8+
"examplemod.configuration.section.examplemod.common.toml.title": "Example Mod Configs",
9+
"examplemod.configuration.items": "Item List",
10+
"examplemod.configuration.logDirtBlock": "Log Dirt Block",
11+
"examplemod.configuration.magicNumberIntroduction": "Magic Number Text",
12+
"examplemod.configuration.magicNumber": "Magic Number"
513
}

0 commit comments

Comments
 (0)