82 lines
3.5 KiB
Java
82 lines
3.5 KiB
Java
package dev.micle.xptools.config;
|
|
|
|
import dev.micle.xptools.XpTools;
|
|
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;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
@Mod.EventBusSubscriber(modid = XpTools.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() {
|
|
XpTools.getFMLJavaModLoadingContext().registerConfig(ModConfig.Type.CLIENT, CLIENT_SPEC);
|
|
XpTools.getFMLJavaModLoadingContext().registerConfig(ModConfig.Type.COMMON, COMMON_SPEC);
|
|
XpTools.getFMLJavaModLoadingContext().registerConfig(ModConfig.Type.SERVER, SERVER_SPEC);
|
|
}
|
|
|
|
public static class Client {
|
|
Client(ForgeConfigSpec.Builder builder) {}
|
|
}
|
|
|
|
public static class Common {
|
|
Common(ForgeConfigSpec.Builder builder) {}
|
|
}
|
|
|
|
public static class Server {
|
|
public static ForgeConfigSpec.BooleanValue blockBreakDefaultNoXp;
|
|
private static ForgeConfigSpec.ConfigValue<List<? extends String>> blockBreakOverridesRaw;
|
|
public static List<OverrideItem> blockBreakOverrideItems;
|
|
|
|
Server(ForgeConfigSpec.Builder builder) {
|
|
builder.comment("Settings for block breaking").push("block_breaking");
|
|
blockBreakDefaultNoXp = builder
|
|
.comment("Should all blocks drop 0 XP by default?")
|
|
.comment("(This makes multipliers not have any effect)")
|
|
.define("blockBreakXpDisabled", false);
|
|
blockBreakOverridesRaw = builder
|
|
.comment("List of all overrides. Format: '[block_id/tag],[multi/val],[min],[max]'")
|
|
.comment("Examples:")
|
|
.comment("'minecraft:dirt,val,2,2' - Makes minecraft's dirt blocks drop 2 XP")
|
|
.comment("'#forge:ores,multi,1,2' - Applies an XP multiplier between 1-2 to all blocks tagged forge:ores")
|
|
.define("blockBreakOverrides", new ArrayList<>());
|
|
builder.pop();
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void onServerConfigReload(ModConfigEvent event) {
|
|
if (event.getConfig().getSpec() == SERVER_SPEC) {
|
|
blockBreakOverrideItems = new ArrayList<>();
|
|
for (String s : blockBreakOverridesRaw.get()) {
|
|
blockBreakOverrideItems.add(new OverrideItem(s));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|