Skip to content

Commit

Permalink
localizations & config
Browse files Browse the repository at this point in the history
  • Loading branch information
KrLite committed Feb 25, 2024
1 parent f54bb44 commit 074348f
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 284 deletions.
14 changes: 12 additions & 2 deletions src/main/java/dm/earth/cabricality/Cabricality.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
import dm.earth.cabricality.content.entries.CabfSounds;
import dm.earth.cabricality.content.trading.data.recipe.Trading;
import dm.earth.cabricality.lib.util.ConfettiUtil;
import dm.earth.cabricality.lib.util.log.CabfLogger;
import dm.earth.cabricality.listener.DeployerCuttingRecipeHandler;
import dm.earth.cabricality.listener.UseEntityListener;
import dm.earth.cabricality.network.CabfReceiver;
import dm.earth.cabricality.tweak.BlockTagTweaks;
import dm.earth.cabricality.tweak.ItemTagTweaks;
import io.github.fabricators_of_create.porting_lib.util.EnvExecutor;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.ConfigHolder;
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
Expand Down Expand Up @@ -143,9 +145,17 @@ private static void initClientAssets() {
RRPCallback.AFTER_VANILLA.register(list -> list.add(RRPs.CLIENT_RESOURCES));
}

public static final ConfigHolder<CabfConfig> CONFIG_HOLDER;
public static final CabfConfig CONFIG;

static {
AutoConfig.register(CabfConfig.class, Toml4jConfigSerializer::new);
CONFIG_HOLDER = AutoConfig.getConfigHolder(CabfConfig.class);
CONFIG = CONFIG_HOLDER.get();
}

@Override
public void onInitialize() {
CabfConfig.override();
ConfettiUtil.startLoading();

CabfReceiver.registerServer();
Expand Down
20 changes: 8 additions & 12 deletions src/main/java/dm/earth/cabricality/client/CabricalityClient.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
package dm.earth.cabricality.client;

import java.util.Arrays;

import dm.earth.cabricality.Cabricality;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
import net.minecraft.client.gui.RotatingCubeMapRenderer;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;
import dm.earth.cabricality.client.listener.ColorRegistryListener;
import dm.earth.cabricality.config.key.CabfKeyBinds;
import dm.earth.cabricality.content.alchemist.core.Substrate;
Expand All @@ -18,14 +9,19 @@
import dm.earth.cabricality.content.trading.util.ProfessionDebugHelper;
import dm.earth.cabricality.lib.util.PushUtil;
import dm.earth.cabricality.lib.util.ScreenUtil;
import dm.earth.cabricality.lib.util.SoundUtil;
import dm.earth.cabricality.network.CabfReceiver;
import dm.earth.cabricality.tweak.cutting.WoodCuttingEntry;
import dm.earth.cabricality.tweak.ore_processing.OreProcessingEntry;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
import net.minecraft.block.Block;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.RotatingCubeMapRenderer;
import net.minecraft.client.render.RenderLayer;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;

public class CabricalityClient implements ClientModInitializer {
public static String ID = Cabricality.ID + "Client";
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/dm/earth/cabricality/command/DebugCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
public class DebugCommand implements Command<ServerCommandSource> {
@Override
public int run(CommandContext<ServerCommandSource> context) {
CabfConfig.debugInfo(!CabfConfig.debugInfo());
Cabricality.CONFIG.debugInfoEnabled = !Cabricality.CONFIG.debugInfoEnabled;
Cabricality.CONFIG_HOLDER.save();

context.getSource().sendFeedback(
() -> Cabricality.genTranslatableText("command", "debug", CabfConfig.debugInfo() ? "enabled" : "disabled")
() -> Cabricality.genTranslatableText("command", "debug", Cabricality.CONFIG.debugInfoEnabled ? "enabled" : "disabled")
.formatted(Formatting.GRAY, Formatting.ITALIC),
false
);
Expand All @@ -27,7 +28,7 @@ public int run(CommandContext<ServerCommandSource> context) {
player,
Cabricality.genTranslatableText(
"command", "debug_info",
CabfConfig.debugInfo() ? "enabled" : "disabled"
Cabricality.CONFIG.debugInfoEnabled ? "enabled" : "disabled"
)
));
}
Expand Down
62 changes: 9 additions & 53 deletions src/main/java/dm/earth/cabricality/config/CabfConfig.java
Original file line number Diff line number Diff line change
@@ -1,56 +1,12 @@
package dm.earth.cabricality.config;

import net.fabricmc.loader.api.FabricLoader;
import net.krlite.pierced.annotation.Silent;
import net.krlite.pierced.annotation.Table;
import net.krlite.pierced.config.Pierced;

import java.io.File;

public class CabfConfig extends Pierced {
private static @Silent final File FILE = FabricLoader.getInstance().getConfigDir().resolve("cabricality.toml").toFile();
private static @Silent final CabfConfig INSTANCE = new CabfConfig();

private CabfConfig() {
super(CabfConfig.class, FILE);
load();
}

public static void override() {
INSTANCE.save();
}

private boolean includeVersionInWindowTitle = false;

public static boolean includeVersionInWindowTitle() {
return INSTANCE.includeVersionInWindowTitle;
}

public static void includeVersionInWindowTitle(boolean includeVersionInGameTitle) {
INSTANCE.includeVersionInWindowTitle = includeVersionInGameTitle;
INSTANCE.save();
}

private boolean fadeScreenBackground = true;

public static boolean fadeScreenBackground() {
return INSTANCE.fadeScreenBackground;
}

public static void fadeScreenBackground(boolean fadeScreenBackground) {
INSTANCE.fadeScreenBackground = fadeScreenBackground;
INSTANCE.save();
}

@Table("debug")
private boolean debugInfo = false;

public static boolean debugInfo() {
return INSTANCE.debugInfo;
}

public static void debugInfo(boolean debugInfo) {
INSTANCE.debugInfo = debugInfo;
INSTANCE.save();
}
import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.Config;
import me.shedaniel.autoconfig.annotation.ConfigEntry;

@Config(name = "cabricality")
public class CabfConfig implements ConfigData {
@ConfigEntry.Gui.Tooltip
public boolean includesVersionInWindowTitle = false;
public boolean debugInfoEnabled = false;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dm.earth.cabricality.config.key;

import dm.earth.cabricality.Cabricality;
import dm.earth.cabricality.config.modmenu.CabfConfigScreen;
import com.mojang.blaze3d.platform.InputUtil;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import dm.earth.cabricality.config.CabfConfig;
import me.shedaniel.autoconfig.AutoConfig;

public class CabfModMenuIntegration implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return parent -> new CabfConfigScreen(parent).build();
return parent -> AutoConfig.getConfigScreen(CabfConfig.class, parent).get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class CabfDebugger {
private static final String PREFIX = "[" + Cabricality.NAME + "/DEBUG] ";

public static void debug(@NotNull String message) {
if (CabfConfig.debugInfo() || FabricLoader.getInstance().isDevelopmentEnvironment())
if (Cabricality.CONFIG.debugInfoEnabled || FabricLoader.getInstance().isDevelopmentEnvironment())
LOGGER.info("[" + Cabricality.NAME + "/DEBUG] " + message);
}
}
17 changes: 8 additions & 9 deletions src/main/java/dm/earth/cabricality/lib/util/log/CabfLogger.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dm.earth.cabricality.lib.util.log;

import dm.earth.cabricality.Cabricality;
import dm.earth.cabricality.config.CabfConfig;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -15,42 +14,42 @@ public static void message(@NotNull String message) {
}

public static void info(@NotNull String message) {
if (CabfConfig.debugInfo())
if (Cabricality.CONFIG.debugInfoEnabled)
LOGGER.info(PREFIX + message);
}

public static void warn(@NotNull String message) {
if (CabfConfig.debugInfo())
if (Cabricality.CONFIG.debugInfoEnabled)
LOGGER.warn(PREFIX + message);
}

public static void error(@NotNull String message) {
if (CabfConfig.debugInfo())
if (Cabricality.CONFIG.debugInfoEnabled)
LOGGER.error(PREFIX + message);
}

public static void error(@NotNull String message, @NotNull Throwable throwable) {
if (CabfConfig.debugInfo())
if (Cabricality.CONFIG.debugInfoEnabled)
LOGGER.error(PREFIX + message, throwable);
}

public static void debug(@NotNull String message) {
if (CabfConfig.debugInfo())
if (Cabricality.CONFIG.debugInfoEnabled)
LOGGER.debug(PREFIX + message);
}

public static void debug(@NotNull String message, @NotNull Throwable throwable) {
if (CabfConfig.debugInfo())
if (Cabricality.CONFIG.debugInfoEnabled)
LOGGER.debug(PREFIX + message, throwable);
}

public static void trace(@NotNull String message) {
if (CabfConfig.debugInfo())
if (Cabricality.CONFIG.debugInfoEnabled)
LOGGER.trace(PREFIX + message);
}

public static void trace(@NotNull String message, @NotNull Throwable throwable) {
if (CabfConfig.debugInfo())
if (Cabricality.CONFIG.debugInfoEnabled)
LOGGER.trace(PREFIX + message, throwable);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private void modifyWindowTitle(CallbackInfoReturnable<String> cir) {
ModContainer container = FabricLoader.getInstance().getModContainer(Cabricality.ID).orElseThrow();
cir.setReturnValue(
container.getMetadata().getName() + (
CabfConfig.includeVersionInWindowTitle()
Cabricality.CONFIG.includesVersionInWindowTitle
? (" " + container.getMetadata().getVersion().getFriendlyString())
: ""
)
Expand Down
Loading

0 comments on commit 074348f

Please sign in to comment.