Updated config.
This commit is contained in:
@ -1,51 +0,0 @@
|
||||
package dev.micle.geologistpicktweaks;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.config.ModConfigEvent;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
// 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 Forge's config APIs
|
||||
@Mod.EventBusSubscriber(modid = Geologistpicktweaks.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public class Config {
|
||||
private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
|
||||
|
||||
private static final ForgeConfigSpec.BooleanValue LOG_DIRT_BLOCK = BUILDER.comment("Whether to log the dirt block on common setup").define("logDirtBlock", true);
|
||||
|
||||
private static final ForgeConfigSpec.IntValue MAGIC_NUMBER = BUILDER.comment("A magic number").defineInRange("magicNumber", 42, 0, Integer.MAX_VALUE);
|
||||
|
||||
public static final ForgeConfigSpec.ConfigValue<String> MAGIC_NUMBER_INTRODUCTION = BUILDER.comment("What you want the introduction message to be for the magic number").define("magicNumberIntroduction", "The magic number is... ");
|
||||
|
||||
// a list of strings that are treated as resource locations for items
|
||||
private static final ForgeConfigSpec.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 ForgeConfigSpec 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 final String itemName && ForgeRegistries.ITEMS.containsKey(new ResourceLocation(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 -> ForgeRegistries.ITEMS.getValue(new ResourceLocation(itemName))).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package dev.micle.geologistpicktweaks.config;
|
||||
|
||||
import dev.micle.geologistpicktweaks.GeologistPickTweaks;
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
import net.minecraftforge.fml.event.config.ModConfigEvent;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = GeologistPickTweaks.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public final class Config {
|
||||
public static final Client CLIENT;
|
||||
public static final ForgeConfigSpec CLIENT_SPEC;
|
||||
public static final Common COMMON;
|
||||
public static final ForgeConfigSpec COMMON_SPEC;
|
||||
public static final Server SERVER;
|
||||
public static final ForgeConfigSpec SERVER_SPEC;
|
||||
|
||||
static {
|
||||
Pair<Client, ForgeConfigSpec> clientSpecPair = new ForgeConfigSpec.Builder().configure(Client::new);
|
||||
CLIENT = clientSpecPair.getLeft();
|
||||
CLIENT_SPEC = clientSpecPair.getRight();
|
||||
|
||||
Pair<Common, ForgeConfigSpec> commonSpecPair = new ForgeConfigSpec.Builder().configure(Common::new);
|
||||
COMMON = commonSpecPair.getLeft();
|
||||
COMMON_SPEC = commonSpecPair.getRight();
|
||||
|
||||
Pair<Server, ForgeConfigSpec> serverSpecPair = new ForgeConfigSpec.Builder().configure(Server::new);
|
||||
SERVER = serverSpecPair.getLeft();
|
||||
SERVER_SPEC = serverSpecPair.getRight();
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
GeologistPickTweaks.getFMLJavaModLoadingContext().registerConfig(ModConfig.Type.CLIENT, CLIENT_SPEC);
|
||||
GeologistPickTweaks.getFMLJavaModLoadingContext().registerConfig(ModConfig.Type.COMMON, COMMON_SPEC);
|
||||
GeologistPickTweaks.getFMLJavaModLoadingContext().registerConfig(ModConfig.Type.SERVER, SERVER_SPEC);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onConfigReloadEvent(ModConfigEvent event) {
|
||||
if (event.getConfig().getSpec() == CLIENT_SPEC) {
|
||||
Client.onConfigReload();
|
||||
} else if (event.getConfig().getSpec() == COMMON_SPEC) {
|
||||
Common.onConfigReload();
|
||||
} else if (event.getConfig().getSpec() == SERVER_SPEC) {
|
||||
Server.onConfigReload();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Client {
|
||||
Client(ForgeConfigSpec.Builder builder) {}
|
||||
|
||||
private static void onConfigReload() {}
|
||||
}
|
||||
|
||||
public static class Common {
|
||||
Common(ForgeConfigSpec.Builder builder) {}
|
||||
|
||||
private static void onConfigReload() {}
|
||||
}
|
||||
|
||||
public static class Server {
|
||||
Server(ForgeConfigSpec.Builder builder) {}
|
||||
|
||||
private static void onConfigReload() {}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package dev.micle.geologistpicktweaks.proxy;
|
||||
|
||||
import dev.micle.geologistpicktweaks.GeologistPickTweaks;
|
||||
import dev.micle.geologistpicktweaks.config.Config;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
Reference in New Issue
Block a user