Allow changing client config in settings
Client config is no longer stored in TBM_Config.toml.
This commit is contained in:
parent
aac4f9b6aa
commit
c0fddb6955
5 changed files with 87 additions and 86 deletions
|
@ -0,0 +1,66 @@
|
||||||
|
package com.burnedkirby.TurnBasedMinecraft.client;
|
||||||
|
|
||||||
|
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
|
||||||
|
import net.neoforged.neoforge.common.ModConfigSpec;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ClientConfig {
|
||||||
|
public final ModConfigSpec.ConfigValue<List<? extends String>> battleMusicList;
|
||||||
|
public final ModConfigSpec.ConfigValue<List<? extends String>> sillyMusicList;
|
||||||
|
|
||||||
|
public final ModConfigSpec.IntValue sillyMusicThreshold;
|
||||||
|
public final ModConfigSpec.BooleanValue volumeAffectedByMusicVolume;
|
||||||
|
public final ModConfigSpec.DoubleValue musicVolume;
|
||||||
|
|
||||||
|
public static final ClientConfig CLIENT;
|
||||||
|
|
||||||
|
public static final ModConfigSpec CLIENT_SPEC;
|
||||||
|
|
||||||
|
ClientConfig(ModConfigSpec.Builder builder) {
|
||||||
|
builder.push("music");
|
||||||
|
|
||||||
|
List<String> battleMusicList = new ArrayList<String>(8);
|
||||||
|
battleMusicList.add("monster");
|
||||||
|
battleMusicList.add("animal");
|
||||||
|
battleMusicList.add("boss");
|
||||||
|
battleMusicList.add("player");
|
||||||
|
this.battleMusicList = builder
|
||||||
|
.comment("What categories of mobs that play \"battle\" music")
|
||||||
|
.translation(TurnBasedMinecraftMod.MODID + ".clientconfig.battle_music_list")
|
||||||
|
.defineList("battleMusicList", battleMusicList, (v) -> v instanceof String);
|
||||||
|
|
||||||
|
List<String> sillyMusicList = new ArrayList<String>(4);
|
||||||
|
sillyMusicList.add("passive");
|
||||||
|
this.sillyMusicList = builder
|
||||||
|
.comment("What categories of mobs that play \"silly\" music")
|
||||||
|
.translation(TurnBasedMinecraftMod.MODID + ".clientconfig.silly_music_list")
|
||||||
|
.defineList("sillyMusicList", sillyMusicList, (v) -> true);
|
||||||
|
|
||||||
|
this.sillyMusicThreshold = builder
|
||||||
|
.comment("Minimum percentage of silly entities in battle to use silly music")
|
||||||
|
.translation(TurnBasedMinecraftMod.MODID + ".clientconfig.silly_percentage")
|
||||||
|
.defineInRange("sillyMusicThreshold", 40, 0, 100);
|
||||||
|
|
||||||
|
this.volumeAffectedByMusicVolume = builder
|
||||||
|
.comment("If \"true\", music volume will be affected by global Music volume setting")
|
||||||
|
.translation(TurnBasedMinecraftMod.MODID + ".clientconfig.volume_affected_by_volume")
|
||||||
|
.define("volumeAffectedByMusicVolume", true);
|
||||||
|
|
||||||
|
this.musicVolume = builder
|
||||||
|
.comment("Volume of battle/silly music as a percentage between 0.0 and 1.0")
|
||||||
|
.translation(TurnBasedMinecraftMod.MODID + ".clientconfig.music_volume")
|
||||||
|
.defineInRange("musicVolume", 0.8, 0.0, 1.0);
|
||||||
|
|
||||||
|
builder.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
Pair<ClientConfig, ModConfigSpec> pair = new ModConfigSpec.Builder().configure(ClientConfig::new);
|
||||||
|
CLIENT = pair.getKey();
|
||||||
|
CLIENT_SPEC = pair.getValue();
|
||||||
|
}
|
||||||
|
}
|
|
@ -94,13 +94,21 @@ public class ClientProxy extends CommonProxy {
|
||||||
@Override
|
@Override
|
||||||
public void playBattleMusic() {
|
public void playBattleMusic() {
|
||||||
Options gs = Minecraft.getInstance().options;
|
Options gs = Minecraft.getInstance().options;
|
||||||
battleMusic.playBattle(gs.getSoundSourceVolume(SoundSource.MUSIC) * gs.getSoundSourceVolume(SoundSource.MASTER));
|
if (ClientConfig.CLIENT.volumeAffectedByMusicVolume.get()) {
|
||||||
|
battleMusic.playBattle(gs.getSoundSourceVolume(SoundSource.MUSIC) * gs.getSoundSourceVolume(SoundSource.MASTER) * ClientConfig.CLIENT.musicVolume.get().floatValue());
|
||||||
|
} else {
|
||||||
|
battleMusic.playBattle(gs.getSoundSourceVolume(SoundSource.MASTER) * ClientConfig.CLIENT.musicVolume.get().floatValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void playSillyMusic() {
|
public void playSillyMusic() {
|
||||||
Options gs = Minecraft.getInstance().options;
|
Options gs = Minecraft.getInstance().options;
|
||||||
battleMusic.playSilly(gs.getSoundSourceVolume(SoundSource.MUSIC) * gs.getSoundSourceVolume(SoundSource.MASTER));
|
if (ClientConfig.CLIENT.volumeAffectedByMusicVolume.get()) {
|
||||||
|
battleMusic.playSilly(gs.getSoundSourceVolume(SoundSource.MUSIC) * gs.getSoundSourceVolume(SoundSource.MASTER) * ClientConfig.CLIENT.musicVolume.get().floatValue());
|
||||||
|
} else {
|
||||||
|
battleMusic.playSilly(gs.getSoundSourceVolume(SoundSource.MASTER) * ClientConfig.CLIENT.musicVolume.get().floatValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -116,9 +124,9 @@ public class ClientProxy extends CommonProxy {
|
||||||
if (localBattle == null) {
|
if (localBattle == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (type == null || type.isEmpty() || getConfig().isBattleMusicType(type)) {
|
if (type == null || type.isEmpty() || ClientConfig.CLIENT.battleMusicList.get().contains(type)) {
|
||||||
++battleMusicCount;
|
++battleMusicCount;
|
||||||
} else if (getConfig().isSillyMusicType(type)) {
|
} else if (ClientConfig.CLIENT.sillyMusicList.get().contains(type)) {
|
||||||
++sillyMusicCount;
|
++sillyMusicCount;
|
||||||
} else {
|
} else {
|
||||||
++battleMusicCount;
|
++battleMusicCount;
|
||||||
|
@ -132,9 +140,9 @@ public class ClientProxy extends CommonProxy {
|
||||||
battleMusicCount = 0;
|
battleMusicCount = 0;
|
||||||
sillyMusicCount = 0;
|
sillyMusicCount = 0;
|
||||||
return;
|
return;
|
||||||
} else if (type == null || type.isEmpty() || getConfig().isBattleMusicType(type)) {
|
} else if (type == null || type.isEmpty() || ClientConfig.CLIENT.battleMusicList.get().contains(type)) {
|
||||||
--battleMusicCount;
|
--battleMusicCount;
|
||||||
} else if (getConfig().isSillyMusicType(type)) {
|
} else if (ClientConfig.CLIENT.sillyMusicList.get().contains(type)) {
|
||||||
--sillyMusicCount;
|
--sillyMusicCount;
|
||||||
} else {
|
} else {
|
||||||
--battleMusicCount;
|
--battleMusicCount;
|
||||||
|
@ -185,7 +193,7 @@ public class ClientProxy extends CommonProxy {
|
||||||
percentage = 100.0f * (float) sillyMusicCount / (float) (sillyMusicCount + battleMusicCount);
|
percentage = 100.0f * (float) sillyMusicCount / (float) (sillyMusicCount + battleMusicCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (percentage >= (float) getConfig().getSillyMusicThreshold()) {
|
if (percentage >= (float) ClientConfig.CLIENT.sillyMusicThreshold.get()) {
|
||||||
if (battleMusic.isPlaying()) {
|
if (battleMusic.isPlaying()) {
|
||||||
if (!battleMusic.isPlayingSilly() && battleMusic.hasSillyMusic()) {
|
if (!battleMusic.isPlayingSilly() && battleMusic.hasSillyMusic()) {
|
||||||
stopMusic(false);
|
stopMusic(false);
|
||||||
|
|
|
@ -37,10 +37,7 @@ public class Config
|
||||||
private int fleeBadProbability = 35;
|
private int fleeBadProbability = 35;
|
||||||
private int minimumHitPercentage = 4;
|
private int minimumHitPercentage = 4;
|
||||||
private int maxInBattle = 8;
|
private int maxInBattle = 8;
|
||||||
private Set<String> musicBattleTypes;
|
|
||||||
private Set<String> musicSillyTypes;
|
|
||||||
private boolean freezeCombatantsInBattle = false;
|
private boolean freezeCombatantsInBattle = false;
|
||||||
private int sillyMusicThreshold = 40;
|
|
||||||
private int configVersion = 0;
|
private int configVersion = 0;
|
||||||
private Set<Integer> battleIgnoringPlayers = null;
|
private Set<Integer> battleIgnoringPlayers = null;
|
||||||
private boolean onlyOPsSelfDisableTB = true;
|
private boolean onlyOPsSelfDisableTB = true;
|
||||||
|
@ -63,8 +60,6 @@ public class Config
|
||||||
customEntityInfoMap = new HashMap<String, EntityInfo>();
|
customEntityInfoMap = new HashMap<String, EntityInfo>();
|
||||||
ignoreBattleTypes = new HashSet<String>();
|
ignoreBattleTypes = new HashSet<String>();
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
musicBattleTypes = new HashSet<String>();
|
|
||||||
musicSillyTypes = new HashSet<String>();
|
|
||||||
battleIgnoringPlayers = new HashSet<Integer>();
|
battleIgnoringPlayers = new HashSet<Integer>();
|
||||||
possibleIgnoreHurtDamageSources = new HashSet<String>();
|
possibleIgnoreHurtDamageSources = new HashSet<String>();
|
||||||
ignoreHurtDamageSources = new HashSet<String>();
|
ignoreHurtDamageSources = new HashSet<String>();
|
||||||
|
@ -156,56 +151,6 @@ public class Config
|
||||||
{
|
{
|
||||||
CommentedFileConfig conf = getConfigObj(configFile);
|
CommentedFileConfig conf = getConfigObj(configFile);
|
||||||
|
|
||||||
// client config
|
|
||||||
try {
|
|
||||||
Collection<String> battle_music_categories = conf.get("client_config.battle_music");
|
|
||||||
if (battle_music_categories != null) {
|
|
||||||
for (String category : battle_music_categories) {
|
|
||||||
musicBattleTypes.add(category);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
musicBattleTypes.add("monster");
|
|
||||||
musicBattleTypes.add("animal");
|
|
||||||
musicBattleTypes.add("boss");
|
|
||||||
musicBattleTypes.add("player");
|
|
||||||
logNotFound("client_config.battle_music");
|
|
||||||
}
|
|
||||||
} catch (ClassCastException e) {
|
|
||||||
musicBattleTypes.add("monster");
|
|
||||||
musicBattleTypes.add("animal");
|
|
||||||
musicBattleTypes.add("boss");
|
|
||||||
musicBattleTypes.add("player");
|
|
||||||
logTOMLInvalidValue("client_config.battle_music");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
Collection<String> silly_music_categories = conf.get("client_config.silly_music");
|
|
||||||
if (silly_music_categories != null) {
|
|
||||||
for (String category : silly_music_categories) {
|
|
||||||
musicSillyTypes.add(category);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
musicSillyTypes.add("passive");
|
|
||||||
logNotFound("client_config.silly_music");
|
|
||||||
}
|
|
||||||
} catch (ClassCastException e) {
|
|
||||||
musicSillyTypes.add("passive");
|
|
||||||
logTOMLInvalidValue("client_config.silly_music");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
OptionalInt silly_music_threshold = conf.getOptionalInt("client_config.silly_music_threshold");
|
|
||||||
if(silly_music_threshold.isPresent()) {
|
|
||||||
this.sillyMusicThreshold = silly_music_threshold.getAsInt();
|
|
||||||
} else {
|
|
||||||
this.sillyMusicThreshold = 40;
|
|
||||||
logNotFound("client_config.silly_music_threshold", "40");
|
|
||||||
}
|
|
||||||
} catch (ClassCastException e) {
|
|
||||||
this.sillyMusicThreshold = 40;
|
|
||||||
logTOMLInvalidValue("client_config.silly_music_threshold", "40");
|
|
||||||
}
|
|
||||||
|
|
||||||
// server_config
|
// server_config
|
||||||
try {
|
try {
|
||||||
OptionalInt leave_battle_cooldown = conf.getOptionalInt("server_config.leave_battle_cooldown");
|
OptionalInt leave_battle_cooldown = conf.getOptionalInt("server_config.leave_battle_cooldown");
|
||||||
|
@ -1328,16 +1273,6 @@ public class Config
|
||||||
this.maxInBattle = maxInBattle;
|
this.maxInBattle = maxInBattle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBattleMusicType(String type)
|
|
||||||
{
|
|
||||||
return musicBattleTypes.contains(type.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSillyMusicType(String type)
|
|
||||||
{
|
|
||||||
return musicSillyTypes.contains(type.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isFreezeCombatantsEnabled()
|
public boolean isFreezeCombatantsEnabled()
|
||||||
{
|
{
|
||||||
return freezeCombatantsInBattle;
|
return freezeCombatantsInBattle;
|
||||||
|
@ -1347,11 +1282,6 @@ public class Config
|
||||||
freezeCombatantsInBattle = enabled;
|
freezeCombatantsInBattle = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSillyMusicThreshold()
|
|
||||||
{
|
|
||||||
return sillyMusicThreshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getConfigVersion()
|
public int getConfigVersion()
|
||||||
{
|
{
|
||||||
return configVersion;
|
return configVersion;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.burnedkirby.TurnBasedMinecraft.common;
|
package com.burnedkirby.TurnBasedMinecraft.common;
|
||||||
|
|
||||||
import ca.weblite.objc.Client;
|
import ca.weblite.objc.Client;
|
||||||
|
import com.burnedkirby.TurnBasedMinecraft.client.ClientConfig;
|
||||||
import com.burnedkirby.TurnBasedMinecraft.client.ClientProxy;
|
import com.burnedkirby.TurnBasedMinecraft.client.ClientProxy;
|
||||||
import com.burnedkirby.TurnBasedMinecraft.common.networking.*;
|
import com.burnedkirby.TurnBasedMinecraft.common.networking.*;
|
||||||
import com.mojang.brigadier.LiteralMessage;
|
import com.mojang.brigadier.LiteralMessage;
|
||||||
|
@ -21,6 +22,9 @@ import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.neoforged.bus.api.IEventBus;
|
import net.neoforged.bus.api.IEventBus;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
import net.neoforged.fml.ModLoadingContext;
|
||||||
|
import net.neoforged.fml.config.ModConfig;
|
||||||
|
import net.neoforged.fml.event.config.ModConfigEvent;
|
||||||
import net.neoforged.fml.loading.FMLEnvironment;
|
import net.neoforged.fml.loading.FMLEnvironment;
|
||||||
import net.neoforged.neoforge.common.NeoForge;
|
import net.neoforged.neoforge.common.NeoForge;
|
||||||
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
||||||
|
@ -67,6 +71,7 @@ public class TurnBasedMinecraftMod {
|
||||||
eventBus.addListener(this::secondInitServer);
|
eventBus.addListener(this::secondInitServer);
|
||||||
eventBus.addListener(this::registerNetwork);
|
eventBus.addListener(this::registerNetwork);
|
||||||
NeoForge.EVENT_BUS.register(this);
|
NeoForge.EVENT_BUS.register(this);
|
||||||
|
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ClientConfig.CLIENT_SPEC);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerNetwork(final RegisterPayloadHandlerEvent event) {
|
private void registerNetwork(final RegisterPayloadHandlerEvent event) {
|
||||||
|
|
|
@ -6,16 +6,8 @@ version = 10
|
||||||
# "false"!
|
# "false"!
|
||||||
do_not_overwrite = false
|
do_not_overwrite = false
|
||||||
|
|
||||||
[client_config]
|
|
||||||
|
|
||||||
# What categories play this type of music (battle_music). Unknown categories will default to this type.
|
|
||||||
battle_music = ["monster", "animal", "boss", "player"]
|
|
||||||
# What categories play this type of music (silly_music).
|
|
||||||
silly_music = ["passive"]
|
|
||||||
|
|
||||||
# Minimum percentage of silly entities in battle to use silly music.
|
|
||||||
silly_music_threshold = 40
|
|
||||||
|
|
||||||
|
# Note that client config is no longer stored here but rather in the settings.
|
||||||
|
|
||||||
[server_config]
|
[server_config]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue