Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions src/main/java/com/example/examplemod/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@

// 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);

Expand All @@ -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);

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.getValue(ResourceLocation.parse(itemName)))
.collect(Collectors.toSet());
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/example/examplemod/ExampleMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ private void commonSetup(final FMLCommonSetupEvent event)
// Some common setup code
LOGGER.info("HELLO FROM COMMON SETUP");

if (Config.logDirtBlock)
if (Config.LOG_DIRT_BLOCK.get())
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.get());

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
Expand Down