Skip to content

Commit

Permalink
Opt-in to Neo's config gui to allow modifying our configs when the ga…
Browse files Browse the repository at this point in the history
…me is running (#5794)
  • Loading branch information
pupnewfster committed Aug 1, 2024
1 parent 0601185 commit 8ab6c52
Show file tree
Hide file tree
Showing 36 changed files with 571 additions and 82 deletions.
14 changes: 11 additions & 3 deletions src/additions/java/mekanism/additions/client/AdditionsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import mekanism.additions.client.voice.VoiceClient;
import mekanism.additions.common.MekanismAdditions;
import mekanism.additions.common.config.MekanismAdditionsConfig;
import mekanism.common.Mekanism;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.client.gui.ConfigurationScreen;
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;

@Mod(value = MekanismAdditions.MODID, dist = Dist.CLIENT)
public class AdditionsClient {

private AdditionsClient() {
}

private static VoiceClient voiceClient;

public AdditionsClient(ModContainer container) {
container.registerExtensionPoint(IConfigScreenFactory.class, ConfigurationScreen::new);
}

public static void reset() {
if (voiceClient != null) {
voiceClient.disconnect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ public class AdditionsClientConfig extends BaseMekanismConfig {

AdditionsClientConfig() {
ModConfigSpec.Builder builder = new ModConfigSpec.Builder();
builder.comment("Mekanism Additions Client Config. This config only exists on the client.").push("additions-client");
AdditionsConfigTranslations.CLIENT_TOP_LEVEL.applyToBuilder(builder).push("additions-client");

voiceKeyIsToggle = CachedBooleanValue.wrap(this, builder.comment("If the voice server is enabled and voiceKeyIsToggle is also enabled, the voice key will "
+ "act as a toggle instead of requiring to be held while talking.")
voiceKeyIsToggle = CachedBooleanValue.wrap(this, AdditionsConfigTranslations.CLIENT_VOICE_KEY_TOGGLE.applyToBuilder(builder)
.define("voiceKeyIsToggle", false));
builder.pop();
configSpec = builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import mekanism.additions.common.config.AdditionsConfigTranslations.BabySpawnTranslations;
import mekanism.additions.common.entity.baby.BabyType;
import mekanism.additions.common.registries.AdditionsEntityTypes;
import mekanism.api.functions.ConstantPredicates;
Expand Down Expand Up @@ -37,22 +38,22 @@ public class AdditionsConfig extends BaseMekanismConfig {

AdditionsConfig() {
ModConfigSpec.Builder builder = new ModConfigSpec.Builder();
builder.comment("Mekanism Additions Config. This config is synced between server and client.").push("additions");
AdditionsConfigTranslations.SERVER_TOP_LEVEL.applyToBuilder(builder).push("additions");

obsidianTNTDelay = CachedIntValue.wrap(this, builder.comment("Fuse time for Obsidian TNT.")
obsidianTNTDelay = CachedIntValue.wrap(this, AdditionsConfigTranslations.SERVER_OBSIDIAN_DELAY.applyToBuilder(builder)
.defineInRange("obsidianTNTDelay", 5 * SharedConstants.TICKS_PER_SECOND, 0, Integer.MAX_VALUE));
obsidianTNTBlastRadius = CachedFloatValue.wrap(this, builder.comment("Radius of the explosion of Obsidian TNT.")
obsidianTNTBlastRadius = CachedFloatValue.wrap(this, AdditionsConfigTranslations.SERVER_OBSIDIAN_RADIUS.applyToBuilder(builder)
.defineInRange("obsidianTNTBlastRadius", 12, 0.1, 1_000));

babyArrowDamageMultiplier = CachedDoubleValue.wrap(this, builder.comment("Damage multiplier of arrows shot by baby mobs.")
.defineInRange("babyArrowDamageMultiplier", 0.25, 0.1, 10));

voiceServerEnabled = CachedBooleanValue.wrap(this, builder.comment("Enables the voice server for Walkie Talkies.").worldRestart()
.define("voiceServerEnabled", false));
voicePort = CachedIntValue.wrap(this, builder.comment("TCP port for the Voice server to listen on.")
voiceServerEnabled = CachedBooleanValue.wrap(this, AdditionsConfigTranslations.SERVER_VOICE_ENABLED.applyToBuilder(builder)
.worldRestart() .define("voiceServerEnabled", false));
voicePort = CachedIntValue.wrap(this, AdditionsConfigTranslations.SERVER_VOICE_PORT.applyToBuilder(builder)
.defineInRange("VoicePort", 36_123, 1, 65_535));

builder.comment("Config options regarding spawning of entities.").push("spawning");
babyArrowDamageMultiplier = CachedDoubleValue.wrap(this, AdditionsConfigTranslations.SERVER_BABY_ARROW_DAMAGE.applyToBuilder(builder)
.defineInRange("babyArrowDamageMultiplier", 0.25, 0.1, 10));

AdditionsConfigTranslations.SERVER_BABY_SPAWNING.applyToBuilder(builder).push("spawning");
addBabyTypeConfig(BabyType.BOGGED, builder, AdditionsEntityTypes.BABY_BOGGED, EntityType.BOGGED);
addBabyTypeConfig(BabyType.CREEPER, builder, AdditionsEntityTypes.BABY_CREEPER, EntityType.CREEPER);
addBabyTypeConfig(BabyType.ENDERMAN, builder, AdditionsEntityTypes.BABY_ENDERMAN, EntityType.ENDERMAN);
Expand Down Expand Up @@ -103,28 +104,30 @@ public static class SpawnConfig {
private SpawnConfig(IMekanismConfig config, ModConfigSpec.Builder builder, String name, Holder<EntityType<?>> entityType, EntityType<?> parentType) {
this.entityType = entityType;
this.parentType = parentType;
builder.comment("Config options regarding " + name + ".").push(name.replace(" ", "-"));
this.shouldSpawn = CachedBooleanValue.wrap(config, builder.comment("Enable the spawning of " + name + ". Think baby zombies.")
BabySpawnTranslations translations = BabySpawnTranslations.create(name);

translations.topLevel().applyToBuilder(builder).push(name.replace(" ", "-"));
this.shouldSpawn = CachedBooleanValue.wrap(config, translations.shouldSpawn().applyToBuilder(builder)
.worldRestart()
.define("shouldSpawn", true));
this.weightPercentage = CachedDoubleValue.wrap(config, builder.comment("The multiplier for weight of " + name + " spawns, compared to the adult mob.")
this.weightPercentage = CachedDoubleValue.wrap(config, translations.weight().applyToBuilder(builder)
.worldRestart()
.defineInRange("weightPercentage", 0.05, 0, 100));
this.minSizePercentage = CachedDoubleValue.wrap(config, builder.comment("The multiplier for minimum group size of " + name + " spawns, compared to the adult mob.")
this.minSizePercentage = CachedDoubleValue.wrap(config, translations.minSize().applyToBuilder(builder)
.worldRestart()
.defineInRange("minSizePercentage", 0.5, 0, 100));
this.maxSizePercentage = CachedDoubleValue.wrap(config, builder.comment("The multiplier for maximum group size of " + name + " spawns, compared to the adult mob.")
this.maxSizePercentage = CachedDoubleValue.wrap(config, translations.maxSize().applyToBuilder(builder)
.worldRestart()
.defineInRange("maxSizePercentage", 0.5, 0, 100));
this.spawnCostPerEntityPercentage = CachedDoubleValue.wrap(config, builder.comment("The multiplier for spawn cost per entity of " + name + " spawns, compared to the adult mob.")
this.spawnCostPerEntityPercentage = CachedDoubleValue.wrap(config, translations.costPerEntity().applyToBuilder(builder)
.worldRestart()
.defineInRange("spawnCostPerEntityPercentage", 1D, 0, 100));
this.maxSpawnCostPercentage = CachedDoubleValue.wrap(config, builder.comment("The multiplier for max spawn cost of " + name + " spawns, compared to the adult mob.")
this.maxSpawnCostPercentage = CachedDoubleValue.wrap(config, translations.maxCost().applyToBuilder(builder)
.worldRestart()
.defineInRange("maxSpawnCostPercentage", 1D, 0, 100));
this.biomeBlackList = CachedResourceLocationListValue.define(config, builder.comment("The list of biome ids that " + name + " will not spawn in even if the normal mob variant can spawn.")
this.biomeBlackList = CachedResourceLocationListValue.define(config, translations.biomeBlacklist().applyToBuilder(builder)
.worldRestart(), "biomeBlackList", ConstantPredicates.alwaysTrue());
this.structureBlackList = CachedResourceLocationListValue.define(config, builder.comment("The list of structure ids that " + name + " will not spawn in even if the normal mob variant can spawn.")
this.structureBlackList = CachedResourceLocationListValue.define(config, translations.structureBlacklist().applyToBuilder(builder)
.worldRestart(), "structureBlackList", BuiltInRegistries.STRUCTURE_TYPE::containsKey);
builder.pop();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package mekanism.additions.common.config;

import mekanism.additions.common.MekanismAdditions;
import mekanism.common.config.IConfigTranslation;
import net.minecraft.Util;
import org.jetbrains.annotations.NotNull;

public enum AdditionsConfigTranslations implements IConfigTranslation {
CLIENT_TOP_LEVEL("client", "Mekanism Additions Client Config. This config only exists on the client"),

CLIENT_VOICE_KEY_TOGGLE("client.voice_key_is_toggle", "If the voice server is enabled and voiceKeyIsToggle is also enabled, the voice key will "
+ "act as a toggle instead of requiring to be held while talking."),

SERVER_TOP_LEVEL("server", "Mekanism Additions Config. This config is synced between server and client."),

SERVER_OBSIDIAN_DELAY("server.obsidian_tnt.delay", "Fuse time for Obsidian TNT."),
SERVER_OBSIDIAN_RADIUS("server.obsidian_tnt.radius", "Radius of the explosion of Obsidian TNT."),

SERVER_VOICE_ENABLED("server.voice.enabled", "Enables the voice server for Walkie Talkies."),
SERVER_VOICE_PORT("server.voice.port", "TCP port for the Voice server to listen on."),

SERVER_BABY_ARROW_DAMAGE("server.baby.arrow_damage_multiplier", "Damage multiplier of arrows shot by baby mobs."),
SERVER_BABY_SPAWNING("server.baby.spawning", "Config options regarding spawning of entities."),

;

private final String key;
private final String translation;

AdditionsConfigTranslations(String path, String translation) {
this.key = Util.makeDescriptionId("configuration", MekanismAdditions.rl(path));
this.translation = translation;
}

@NotNull
@Override
public String getTranslationKey() {
return key;
}

@Override
public String translation() {
return translation;
}

public record BabySpawnTranslations(
IConfigTranslation topLevel,
IConfigTranslation shouldSpawn,
IConfigTranslation weight,
IConfigTranslation minSize,
IConfigTranslation maxSize,
IConfigTranslation costPerEntity,
IConfigTranslation maxCost,
IConfigTranslation biomeBlacklist,
IConfigTranslation structureBlacklist
) {

private static String getKey(String name, String path) {
name = name.replace(" ", "_");
return Util.makeDescriptionId("configuration", MekanismAdditions.rl("server.baby.spawning." + name + "." + path));
}

public static BabySpawnTranslations create(String name) {
return new BabySpawnTranslations(
new ConfigTranslation(getKey(name, "top_level"), "Config options regarding " + name + "."),
new ConfigTranslation(getKey(name, "should_spawn"), "Enable the spawning of " + name + ". Think baby zombies."),
new ConfigTranslation(getKey(name, "weight"), "The multiplier for weight of " + name + " spawns, compared to the adult mob."),
new ConfigTranslation(getKey(name, "min_size"), "The multiplier for minimum group size of " + name + " spawns, compared to the adult mob."),
new ConfigTranslation(getKey(name, "max_size"), "The multiplier for maximum group size of " + name + " spawns, compared to the adult mob."),
new ConfigTranslation(getKey(name, "cost_per_entity"), "The multiplier for spawn cost per entity of " + name + " spawns, compared to the adult mob."),
new ConfigTranslation(getKey(name, "max_cost"), "The multiplier for max spawn cost of " + name + " spawns, compared to the adult mob."),
new ConfigTranslation(getKey(name, "biome_blacklist"), "The list of biome ids that " + name + " will not spawn in even if the normal mob variant can spawn."),
new ConfigTranslation(getKey(name, "structure_blacklist"), "The list of structure ids that " + name + " will not spawn in even if the normal mob variant can spawn.")
);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import mekanism.additions.common.AdditionsTags;
import mekanism.additions.common.MekanismAdditions;
import mekanism.additions.common.advancements.AdditionsAdvancements;
import mekanism.additions.common.config.AdditionsConfigTranslations;
import mekanism.additions.common.config.AdditionsConfigTranslations.BabySpawnTranslations;
import mekanism.additions.common.entity.baby.BabyType;
import mekanism.additions.common.item.ItemBalloon;
import mekanism.additions.common.registries.AdditionsBlocks;
import mekanism.additions.common.registries.AdditionsEntityTypes;
Expand All @@ -25,6 +28,7 @@ public AdditionsLangProvider(PackOutput output) {

@Override
protected void addTranslations() {
addConfigs();
addTags();
addItems();
addBlocks();
Expand All @@ -35,6 +39,15 @@ protected void addTranslations() {
addAliases(AdditionsAliases.values());
}

private void addConfigs() {
addConfigs(AdditionsConfigTranslations.values());
for (BabyType type : BabyType.values()) {
BabySpawnTranslations translations = BabySpawnTranslations.create("baby " + type.getSerializedName().replace('_', ' '));
addConfigs(translations.topLevel(), translations.shouldSpawn(), translations.weight(), translations.minSize(), translations.maxSize(),
translations.costPerEntity(), translations.maxCost(), translations.biomeBlacklist(), translations.structureBlacklist());
}
}

private void addTags() {
addTag(AdditionsTags.Items.BALLOONS, "Balloons");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import mekanism.client.lang.BaseLanguageProvider;
import mekanism.defense.common.DefenseLang;
import mekanism.defense.common.MekanismDefense;
import mekanism.defense.common.config.DefenseConfigTranslations;
import net.minecraft.data.PackOutput;

public class DefenseLangProvider extends BaseLanguageProvider {
Expand All @@ -13,6 +14,7 @@ public DefenseLangProvider(PackOutput output) {

@Override
protected void addTranslations() {
addConfigs(DefenseConfigTranslations.values());
addMisc();
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8ab6c52

Please sign in to comment.