Skip to content

Commit

Permalink
Merge pull request #189 from DancingSnow0517/cloth-config
Browse files Browse the repository at this point in the history
新的配置文件系统
  • Loading branch information
Gu-ZT authored Apr 6, 2024
2 parents 8f2e834 + a8b88e9 commit 19a6e6a
Show file tree
Hide file tree
Showing 17 changed files with 171 additions and 107 deletions.
4 changes: 2 additions & 2 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ dependencies {
// Mixin Extras
implementation(annotationProcessor("io.github.llamalad7:mixinextras-common:${fabric.versions.mixinextras.get()}"))

// Configuration
modCompileOnly fabric.configuration
// cloth config api
modCompileOnly fabric.clothConfig
}

publishing {
Expand Down
6 changes: 3 additions & 3 deletions common/src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import dev.dubhe.anvilcraft.init.ModItems;
import dev.dubhe.anvilcraft.init.ModMenuTypes;
import dev.dubhe.anvilcraft.init.ModNetworks;
import dev.toma.configuration.Configuration;
import dev.toma.configuration.config.format.ConfigFormats;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
Expand All @@ -27,7 +27,7 @@ public class AnvilCraft {
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_NAME);
public static final EventManager EVENT_BUS = new EventManager();
public static AnvilCraftConfig config = Configuration.registerConfig(AnvilCraftConfig.class, ConfigFormats.yaml()).getConfigInstance();
public static AnvilCraftConfig config = AutoConfig.register(AnvilCraftConfig.class, JanksonConfigSerializer::new).getConfig();

public static final AnvilCraftRegistrate REGISTRATE = AnvilCraftRegistrate.create(MOD_ID);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
package dev.dubhe.anvilcraft.config;

import dev.dubhe.anvilcraft.AnvilCraft;
import dev.toma.configuration.Configuration;
import dev.toma.configuration.config.Config;
import dev.toma.configuration.config.Configurable;
import dev.toma.configuration.config.format.ConfigFormats;
import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.Config;
import me.shedaniel.autoconfig.annotation.ConfigEntry;
import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.Comment;

@Config(id = AnvilCraft.MOD_ID)
public class AnvilCraftConfig {

public static AnvilCraftConfig INSTANCE;
@Config(name = AnvilCraft.MOD_ID)
public class AnvilCraftConfig implements ConfigData {

public static void init() {
INSTANCE = Configuration.registerConfig(AnvilCraftConfig.class, ConfigFormats.yaml()).getConfigInstance();
}

@Configurable
@Configurable.Comment("Maximum number of items processed by the anvil at the same time")
@Comment("Maximum number of items processed by the anvil at the same time")
@ConfigEntry.Gui.Tooltip
@ConfigEntry.BoundedDiscrete(max = 64, min = 1)
public int anvilEfficiency = 64;

@Configurable
@Configurable.Comment("Maximum depth a lightning strike can reach")
@Comment("Maximum depth a lightning strike can reach")
@ConfigEntry.Gui.Tooltip
@ConfigEntry.BoundedDiscrete(max = 16, min = 1)
public int lightningStrikeDepth = 2;

@Configurable
@Configurable.Comment("Maximum distance a magnet attracts")
@Comment("Maximum distance a magnet attracts")
@ConfigEntry.Gui.Tooltip
@ConfigEntry.BoundedDiscrete(max = 16, min = 1)
public int magnetAttractsDistance = 5;
@Configurable
@Configurable.Comment("Maximum radius a handheld magnet attracts")

@Comment("Maximum radius a handheld magnet attracts")
@ConfigEntry.Gui.Tooltip
public double magnetItemAttractsRadius = 8;

@Configurable
@Configurable.Comment("Redstone EMP distance generated per block dropped by the anvil")
@Comment("Redstone EMP distance generated per block dropped by the anvil")
@ConfigEntry.Gui.Tooltip
@ConfigEntry.BoundedDiscrete(max = 64, min = 1)
public int redstoneEmpRadius = 6;

@Configurable
@Configurable.Comment("Maximum distance of redstone EMP")
@Comment("Maximum distance of redstone EMP")
@ConfigEntry.Gui.Tooltip
@ConfigEntry.BoundedDiscrete(max = 64, min = 1)
public int redstoneEmpMaxRadius = 24;

@Configurable
@Configurable.Comment("Maximum cooldown time of chute (in ticks)")
@Comment("Maximum cooldown time of chute (in ticks)")
@ConfigEntry.Gui.Tooltip
@ConfigEntry.BoundedDiscrete(max = 64, min = 1)
public int chuteMaxCooldown = 4;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package dev.dubhe.anvilcraft.data.generator.lang;

import com.tterrag.registrate.providers.RegistrateLangProvider;
import dev.dubhe.anvilcraft.AnvilCraft;


public class ConfigScreenLang {
private static final String OPTION_STRING = "text.autoconfig.%s.option.%s";
private static final String OPTION_TOOLTIP_STRING = "text.autoconfig.%s.option.%s.@Tooltip";

public static void init(RegistrateLangProvider provider) {
provider.add("text.autoconfig.anvilcraft.title", "AnvilCraft Config");

provider.add(OPTION_STRING.formatted(AnvilCraft.MOD_ID, "anvilEfficiency"), "Anvil Efficiency");
provider.add(OPTION_TOOLTIP_STRING.formatted(AnvilCraft.MOD_ID, "anvilEfficiency"), "Maximum number of items processed by the anvil at the same time");

provider.add(OPTION_STRING.formatted(AnvilCraft.MOD_ID, "lightningStrikeDepth"), "Lightning Strike Depth");
provider.add(OPTION_TOOLTIP_STRING.formatted(AnvilCraft.MOD_ID, "lightningStrikeDepth"), "Maximum depth a lightning strike can reach");

provider.add(OPTION_STRING.formatted(AnvilCraft.MOD_ID, "magnetAttractsDistance"), "Magnet Attracts Distance");
provider.add(OPTION_TOOLTIP_STRING.formatted(AnvilCraft.MOD_ID, "magnetAttractsDistance"), "Maximum radius a handheld magnet attracts");

provider.add(OPTION_STRING.formatted(AnvilCraft.MOD_ID, "magnetItemAttractsRadius"), "Magnet Item Attracts Radius");
provider.add(OPTION_TOOLTIP_STRING.formatted(AnvilCraft.MOD_ID, "magnetItemAttractsRadius"), "Maximum radius a handheld magnet attracts");

provider.add(OPTION_STRING.formatted(AnvilCraft.MOD_ID, "redstoneEmpRadius"), "Redstone EMP Radius");
provider.add(OPTION_TOOLTIP_STRING.formatted(AnvilCraft.MOD_ID, "redstoneEmpRadius"), "Redstone EMP distance generated per block dropped by the anvil");

provider.add(OPTION_STRING.formatted(AnvilCraft.MOD_ID, "redstoneEmpMaxRadius"), "Redstone EMP Max Radius");
provider.add(OPTION_TOOLTIP_STRING.formatted(AnvilCraft.MOD_ID, "redstoneEmpMaxRadius"), "Maximum distance of redstone EMP");

provider.add(OPTION_STRING.formatted(AnvilCraft.MOD_ID, "chuteMaxCooldown"), "Chute Max Cooldown");
provider.add(OPTION_TOOLTIP_STRING.formatted(AnvilCraft.MOD_ID, "chuteMaxCooldown"), "Maximum distance of chute");
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class LangHandler {
public static void init(RegistrateLangProvider provider) {
AdvancementLang.init(provider);
ConfigurationLang.init(provider);
ConfigScreenLang.init(provider);
ScreenLang.init(provider);

provider.add("item.anvilcraft.amethyst_pickaxe.tooltip", "Stone pickaxe quality, can mine iron ore, not diamonds!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ public static void init(RegistrateLangProvider provider) {
provider.add("screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.additions_slot_description", "Put the Royal Steel Ingot");
provider.add("screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.applies_to", "Amethyst Pickaxe Golden Pickaxe Iron Pickaxe Diamond Pickaxe");
provider.add("screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.base_slot_description", "Put the pickaxe");
provider.add("config.screen.anvilcraft", "AnvilCraft Config");
}
}
8 changes: 4 additions & 4 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ dependencies {

// Development QOL
modCompileOnly fabric.lazydfu
modCompileOnly fabric.modmenu
modImplementation fabric.modmenu

// JEI
modCompileOnlyApi(fabric.jei.common.api) { transitive = false }
Expand All @@ -120,9 +120,9 @@ dependencies {
// Mixin Extras
include(implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:${fabric.versions.mixinextras.get()}")))

// Configuration
modImplementation(fabric.configuration)
include(fabric.configuration)
// cloth config api
modImplementation(fabric.clothConfig)
include(fabric.clothConfig)
}


Expand Down
25 changes: 16 additions & 9 deletions fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
"block.anvilcraft.royal_steel_block": "ʞɔoןᗺ ןǝǝʇS ןɐʎoᴚ",
"block.anvilcraft.smooth_royal_steel_block": "ʞɔoןᗺ ןǝǝʇS ןɐʎoᴚ ɥʇooɯS",
"block.anvilcraft.stamping_platform": "ɯɹoɟʇɐןԀ buıdɯɐʇS",
"config.anvilcraft.option.anvilEfficiency": "ʎɔuǝıɔıɟɟƎןıʌuɐ",
"config.anvilcraft.option.chuteMaxCooldown": "uʍopןooƆxɐWǝʇnɥɔ",
"config.anvilcraft.option.lightningStrikeDepth": "ɥʇdǝᗡǝʞıɹʇSbuıuʇɥbıן",
"config.anvilcraft.option.magnetAttractsDistance": "ǝɔuɐʇsıᗡsʇɔɐɹʇʇⱯʇǝubɐɯ",
"config.anvilcraft.option.magnetItemAttractsRadius": "snıpɐᴚsʇɔɐɹʇʇⱯɯǝʇIʇǝubɐɯ",
"config.anvilcraft.option.redstoneEmpMaxRadius": "snıpɐᴚxɐWdɯƎǝuoʇspǝɹ",
"config.anvilcraft.option.redstoneEmpRadius": "snıpɐᴚdɯƎǝuoʇspǝɹ",
"config.screen.anvilcraft": "bıɟuoƆ ʇɟɐɹƆןıʌuⱯ",
"item.anvilcraft.amethyst_axe": "ǝxⱯ ʇsʎɥʇǝɯⱯ",
"item.anvilcraft.amethyst_hoe": "ǝoH ʇsʎɥʇǝɯⱯ",
"item.anvilcraft.amethyst_pickaxe": "ǝxɐʞɔıԀ ʇsʎɥʇǝɯⱯ",
Expand Down Expand Up @@ -84,5 +76,20 @@
"screen.anvilcraft.royal_steel_upgrade_smithing_template": "ǝʇɐןdɯǝ⟘ buıɥʇıɯS ǝpɐɹbd∩ ןǝǝʇS ןɐʎoᴚ",
"screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.additions_slot_description": "ʇobuI ןǝǝʇS ןɐʎoᴚ ǝɥʇ ʇnԀ",
"screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.applies_to": "ǝxɐʞɔıԀ puoɯɐıᗡ ǝxɐʞɔıԀ uoɹI ǝxɐʞɔıԀ uǝpןo⅁ ǝxɐʞɔıԀ ʇsʎɥʇǝɯⱯ",
"screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.base_slot_description": "ǝxɐʞɔıd ǝɥʇ ʇnԀ"
"screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.base_slot_description": "ǝxɐʞɔıd ǝɥʇ ʇnԀ",
"text.autoconfig.anvilcraft.option.anvilEfficiency": "ʎɔuǝıɔıɟɟƎ ןıʌuⱯ",
"text.autoconfig.anvilcraft.option.anvilEfficiency.@Tooltip": "ǝɯıʇ ǝɯɐs ǝɥʇ ʇɐ ןıʌuɐ ǝɥʇ ʎq pǝssǝɔoɹd sɯǝʇı ɟo ɹǝqɯnu ɯnɯıxɐW",
"text.autoconfig.anvilcraft.option.chuteMaxCooldown": "uʍopןooƆ xɐW ǝʇnɥƆ",
"text.autoconfig.anvilcraft.option.chuteMaxCooldown.@Tooltip": "ǝʇnɥɔ ɟo ǝɔuɐʇsıp ɯnɯıxɐW",
"text.autoconfig.anvilcraft.option.lightningStrikeDepth": "ɥʇdǝᗡ ǝʞıɹʇS buıuʇɥbıꞀ",
"text.autoconfig.anvilcraft.option.lightningStrikeDepth.@Tooltip": "ɥɔɐǝɹ uɐɔ ǝʞıɹʇs buıuʇɥbıן ɐ ɥʇdǝp ɯnɯıxɐW",
"text.autoconfig.anvilcraft.option.magnetAttractsDistance": "ǝɔuɐʇsıᗡ sʇɔɐɹʇʇⱯ ʇǝubɐW",
"text.autoconfig.anvilcraft.option.magnetAttractsDistance.@Tooltip": "sʇɔɐɹʇʇɐ ʇǝubɐɯ pןǝɥpuɐɥ ɐ snıpɐɹ ɯnɯıxɐW",
"text.autoconfig.anvilcraft.option.magnetItemAttractsRadius": "snıpɐᴚ sʇɔɐɹʇʇⱯ ɯǝʇI ʇǝubɐW",
"text.autoconfig.anvilcraft.option.magnetItemAttractsRadius.@Tooltip": "sʇɔɐɹʇʇɐ ʇǝubɐɯ pןǝɥpuɐɥ ɐ snıpɐɹ ɯnɯıxɐW",
"text.autoconfig.anvilcraft.option.redstoneEmpMaxRadius": "snıpɐᴚ xɐW ԀWƎ ǝuoʇspǝᴚ",
"text.autoconfig.anvilcraft.option.redstoneEmpMaxRadius.@Tooltip": "ԀWƎ ǝuoʇspǝɹ ɟo ǝɔuɐʇsıp ɯnɯıxɐW",
"text.autoconfig.anvilcraft.option.redstoneEmpRadius": "snıpɐᴚ ԀWƎ ǝuoʇspǝᴚ",
"text.autoconfig.anvilcraft.option.redstoneEmpRadius.@Tooltip": "ןıʌuɐ ǝɥʇ ʎq pǝddoɹp ʞɔoןq ɹǝd pǝʇɐɹǝuǝb ǝɔuɐʇsıp ԀWƎ ǝuoʇspǝᴚ",
"text.autoconfig.anvilcraft.title": "bıɟuoƆ ʇɟɐɹƆןıʌuⱯ"
}
25 changes: 16 additions & 9 deletions fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
"block.anvilcraft.royal_steel_block": "Royal Steel Block",
"block.anvilcraft.smooth_royal_steel_block": "Smooth Royal Steel Block",
"block.anvilcraft.stamping_platform": "Stamping Platform",
"config.anvilcraft.option.anvilEfficiency": "anvilEfficiency",
"config.anvilcraft.option.chuteMaxCooldown": "chuteMaxCooldown",
"config.anvilcraft.option.lightningStrikeDepth": "lightningStrikeDepth",
"config.anvilcraft.option.magnetAttractsDistance": "magnetAttractsDistance",
"config.anvilcraft.option.magnetItemAttractsRadius": "magnetItemAttractsRadius",
"config.anvilcraft.option.redstoneEmpMaxRadius": "redstoneEmpMaxRadius",
"config.anvilcraft.option.redstoneEmpRadius": "redstoneEmpRadius",
"config.screen.anvilcraft": "AnvilCraft Config",
"item.anvilcraft.amethyst_axe": "Amethyst Axe",
"item.anvilcraft.amethyst_hoe": "Amethyst Hoe",
"item.anvilcraft.amethyst_pickaxe": "Amethyst Pickaxe",
Expand Down Expand Up @@ -84,5 +76,20 @@
"screen.anvilcraft.royal_steel_upgrade_smithing_template": "Royal Steel Upgrade Smithing Template",
"screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.additions_slot_description": "Put the Royal Steel Ingot",
"screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.applies_to": "Amethyst Pickaxe Golden Pickaxe Iron Pickaxe Diamond Pickaxe",
"screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.base_slot_description": "Put the pickaxe"
"screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.base_slot_description": "Put the pickaxe",
"text.autoconfig.anvilcraft.option.anvilEfficiency": "Anvil Efficiency",
"text.autoconfig.anvilcraft.option.anvilEfficiency.@Tooltip": "Maximum number of items processed by the anvil at the same time",
"text.autoconfig.anvilcraft.option.chuteMaxCooldown": "Chute Max Cooldown",
"text.autoconfig.anvilcraft.option.chuteMaxCooldown.@Tooltip": "Maximum distance of chute",
"text.autoconfig.anvilcraft.option.lightningStrikeDepth": "Lightning Strike Depth",
"text.autoconfig.anvilcraft.option.lightningStrikeDepth.@Tooltip": "Maximum depth a lightning strike can reach",
"text.autoconfig.anvilcraft.option.magnetAttractsDistance": "Magnet Attracts Distance",
"text.autoconfig.anvilcraft.option.magnetAttractsDistance.@Tooltip": "Maximum radius a handheld magnet attracts",
"text.autoconfig.anvilcraft.option.magnetItemAttractsRadius": "Magnet Item Attracts Radius",
"text.autoconfig.anvilcraft.option.magnetItemAttractsRadius.@Tooltip": "Maximum radius a handheld magnet attracts",
"text.autoconfig.anvilcraft.option.redstoneEmpMaxRadius": "Redstone EMP Max Radius",
"text.autoconfig.anvilcraft.option.redstoneEmpMaxRadius.@Tooltip": "Maximum distance of redstone EMP",
"text.autoconfig.anvilcraft.option.redstoneEmpRadius": "Redstone EMP Radius",
"text.autoconfig.anvilcraft.option.redstoneEmpRadius.@Tooltip": "Redstone EMP distance generated per block dropped by the anvil",
"text.autoconfig.anvilcraft.title": "AnvilCraft Config"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.dubhe.anvilcraft.integration;

import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import dev.dubhe.anvilcraft.config.AnvilCraftConfig;
import me.shedaniel.autoconfig.AutoConfig;

public class AnvilCraftModMenuApiImpl implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return screen -> AutoConfig.getConfigScreen(AnvilCraftConfig.class, screen).get();
}
}
3 changes: 3 additions & 0 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
],
"fabric-datagen": [
"dev.dubhe.anvilcraft.data.generator.fabric.AnvilCraftDatagen"
],
"modmenu": [
"dev.dubhe.anvilcraft.integration.AnvilCraftModMenuApiImpl"
]
},
"mixins": [
Expand Down
6 changes: 3 additions & 3 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ dependencies {
implementation(annotationProcessor("io.github.llamalad7:mixinextras-common:${this.forge.versions.mixinextras.get()}"))
implementation(include("io.github.llamalad7:mixinextras-forge:${this.forge.versions.mixinextras.get()}"))

// Configuration
modImplementation(forge.configuration)
include(forge.configuration)
// cloth config api
modImplementation(forge.clothConfig)
include(forge.clothConfig)
}

processResources {
Expand Down
Loading

0 comments on commit 19a6e6a

Please sign in to comment.