Files
Baubles-Expanded/src/main/java/baubles/common/BaublesConfig.java
T

175 lines
8.4 KiB
Java
Raw Normal View History

2021-11-21 23:28:57 -05:00
package baubles.common;
import java.util.ArrayList;
2026-04-29 19:48:32 +02:00
import java.util.HashMap;
2026-05-15 11:47:40 +02:00
import java.util.LinkedHashSet;
2026-04-29 19:48:32 +02:00
import java.util.Map;
2021-11-21 23:28:57 -05:00
import baubles.api.expanded.BaubleExpandedSlots;
import net.minecraftforge.common.config.Configuration;
public class BaublesConfig {
public static boolean hideDebugItem = true;
2023-01-29 00:05:42 -05:00
public static int[] soulBoundEnchantments = new int[] {};
2026-03-02 12:17:18 -05:00
public static int maxColumns = 4;
2025-09-14 14:35:31 -04:00
public static boolean useOldGuiButton = false;
public static boolean useOldGuiRendering = false;
2021-11-21 23:28:57 -05:00
public static boolean showUnusedSlots = false;
public static boolean manualSlotSelection = false;
public static boolean displayTooltipOnHover = true;
2026-04-29 19:48:32 +02:00
public static String[] slotStackLimitOverrides = new String[] {};
2026-05-15 11:47:40 +02:00
public static String[] slotUniversalOverrides = new String[] {};
2026-04-29 19:48:32 +02:00
private static final Map<String, Integer> stackLimitsByType = new HashMap<>();
2026-05-15 11:47:40 +02:00
private static final ArrayList<String> universalOverrideTypes = new ArrayList<>();
2021-11-21 23:28:57 -05:00
public static String[] overrideSlotTypes = new String[] {
BaubleExpandedSlots.amuletType,
BaubleExpandedSlots.ringType,
BaubleExpandedSlots.ringType,
BaubleExpandedSlots.beltType
};
static final String categoryDebug = "debug";
2023-01-29 00:05:42 -05:00
static final String categoryGeneral = "general";
2021-11-21 23:28:57 -05:00
static final String categoryMenu = "menu";
2025-09-14 14:35:31 -04:00
static final String categoryClient = "client";
2021-11-21 23:28:57 -05:00
static final String categoryOverride = "override";
public static void loadConfig(Configuration config) {
ArrayList<String> currentlyRegisteredTypes = BaubleExpandedSlots.getCurrentlyRegisteredTypes();
String[] currentSlotAssignments = BaubleExpandedSlots.getCurrentSlotAssignments();
//categoryDebug
2021-11-22 16:53:06 -05:00
hideDebugItem = config.getBoolean("hideDebugItem", categoryDebug, hideDebugItem, "Hides the Bauble debug item from the creative menu.\n");
2021-11-21 23:28:57 -05:00
2023-01-29 00:05:42 -05:00
//categoryGeneral
soulBoundEnchantments = config.get(categoryGeneral, "soulBoundEnchantments", soulBoundEnchantments,
"IDs of enchantments that should be treated as soul bound when on items in a bauble slot."
).getIntList();
2025-09-14 14:35:31 -04:00
//categoryClient
useOldGuiButton = config.getBoolean("useOldGuiButton", categoryClient, useOldGuiButton, "Use the old Baubles Button texture and location instead.\n");
2026-03-07 23:30:28 -05:00
useOldGuiRendering = config.getBoolean("useOldRendering", categoryClient, useOldGuiRendering, "Display the old Bauble GUI instead of the new sidebar.\nUsing old rendering with more than 20 slots works, but results in visual oddities and is not supported.\n");
maxColumns = config.getInt("maxColumns", categoryClient, 4, 1, Integer.MAX_VALUE, "Maximum number of columns shown in the baubles inventory.\n"
2026-03-02 12:17:18 -05:00
);
2025-09-14 14:35:31 -04:00
2021-11-21 23:28:57 -05:00
//categoryMenu
showUnusedSlots = config.getBoolean("showUnusedSlots", categoryMenu, showUnusedSlots, "Display unused Bauble slots.\n");
2023-01-29 00:05:42 -05:00
manualSlotSelection = config.getBoolean("manualSlotSelection", categoryMenu, manualSlotSelection,
"Manually override slot assignments.\n!Bauble slot types must be configured manually with this option enabled!\n"
);
displayTooltipOnHover = config.getBoolean("displayTooltipOnHover", categoryMenu, displayTooltipOnHover,
"When hovering the mouse over a bauble slot, display a tooltip with the bauble type and if a held item can be equipped in that slot.\n"
);
2021-11-21 23:28:57 -05:00
//categoryOverride
2023-01-29 00:05:42 -05:00
config.getStringList("defualtSlotTypes", categoryOverride, new String[] {},
"Baubles and its addons assigned the folowing types to the bauble slots.\n!This config option automatically changes to reflect what Baubles and its addons assigned each time the game is launched!"
);
2021-11-21 23:28:57 -05:00
config.getCategory(categoryOverride).get("defualtSlotTypes").set(currentSlotAssignments);
overrideSlotTypes = config.getStringList("slotTypeOverrides", categoryOverride, overrideSlotTypes,
2026-03-07 23:30:28 -05:00
"Slot assignments to use if manualSlotSelection is enabled.\n!Adding, moving, or removing slots of the "
+ BaubleExpandedSlots.amuletType + ", " + BaubleExpandedSlots.ringType + ", or " + BaubleExpandedSlots.beltType +
" types will reduce compatibility with mods made for original Baubles versions!\n",
2025-09-14 14:35:31 -04:00
currentlyRegisteredTypes.toArray(new String[0])
2021-11-21 23:28:57 -05:00
);
2026-04-29 19:48:32 +02:00
slotStackLimitOverrides = config.getStringList("slotStackLimitOverrides", categoryOverride, slotStackLimitOverrides,
"Per-slot-type stack limits in the format \"type=limit\" (example: heartcanister_red=10).\n"
+ "Unspecified types default to a stack limit of 1.\n",
currentlyRegisteredTypes.stream().map(type -> type + "=1").toArray(String[]::new)
);
2026-05-15 11:47:40 +02:00
slotUniversalOverrides = config.getStringList("slotUniversalOverrides", categoryOverride, slotUniversalOverrides,
"Bauble types listed here are also allowed in " + BaubleExpandedSlots.universalType + " slots.\n"
+ "Use registered slot type names like " + BaubleExpandedSlots.ringType + ", " + BaubleExpandedSlots.amuletType
+ ", " + BaubleExpandedSlots.beltType + ".\n",
currentlyRegisteredTypes.toArray(new String[0])
);
2026-04-29 19:48:32 +02:00
stackLimitsByType.clear();
2026-05-15 11:47:40 +02:00
universalOverrideTypes.clear();
for (String type : slotUniversalOverrides) {
if (type == null) continue;
String trimmedType = type.trim();
if (trimmedType.isEmpty()) continue;
if (!BaubleExpandedSlots.isTypeRegistered(trimmedType)) {
Baubles.log.warn("Ignoring slotUniversalOverrides entry '{}': unknown slot type '{}'", type, trimmedType);
continue;
}
if (trimmedType.equals(BaubleExpandedSlots.universalType) || trimmedType.equals(BaubleExpandedSlots.unknownType)) {
continue;
}
if (!universalOverrideTypes.contains(trimmedType)) {
universalOverrideTypes.add(trimmedType);
}
}
2026-04-29 19:48:32 +02:00
for (String entry : slotStackLimitOverrides) {
if (entry == null) continue;
String[] split = entry.split("=", 2);
2026-05-14 23:09:31 +02:00
if (split.length != 2) {
Baubles.log.warn("Ignoring malformed slotStackLimitOverrides entry '{}'. Expected format: type=limit", entry);
continue;
}
2026-04-29 19:48:32 +02:00
String type = split[0].trim();
String limitText = split[1].trim();
2026-05-14 23:14:45 +02:00
if (!BaubleExpandedSlots.isTypeRegistered(type)) {
Baubles.log.warn("Ignoring slotStackLimitOverrides entry '{}': unknown slot type '{}'", entry, type);
continue;
}
2026-04-29 19:48:32 +02:00
try {
int limit = Integer.parseInt(limitText);
if (limit > 0) {
stackLimitsByType.put(type, limit);
}
2026-05-14 23:14:45 +02:00
} catch (NumberFormatException ignored) {
Baubles.log.warn("Ignoring slotStackLimitOverrides entry '{}': '{}' is not a valid integer", entry, limitText);
}
2026-04-29 19:48:32 +02:00
}
2023-01-29 00:05:42 -05:00
2021-11-21 23:28:57 -05:00
if(manualSlotSelection) {
BaubleExpandedSlots.overrideSlots(overrideSlotTypes);
}
if(config.hasChanged()) {
config.save();
}
}
2026-04-29 19:48:32 +02:00
public static int getStackLimitForSlotType(String type) {
if (type == null) return 1;
return stackLimitsByType.getOrDefault(type, 1);
}
2026-05-15 11:47:40 +02:00
public static boolean canTypeFitSlot(String itemType, String slotType) {
if (itemType == null || slotType == null) {
return false;
}
if (itemType.equals(BaubleExpandedSlots.universalType) || itemType.equals(slotType)) {
return true;
}
return slotType.equals(BaubleExpandedSlots.universalType) && universalOverrideTypes.contains(itemType);
}
public static String[] getDisplayTypesWithUniversalOverrides(String[] types) {
if (types == null || types.length == 0) {
return new String[0];
}
LinkedHashSet<String> displayTypes = new LinkedHashSet<>();
for (String type : types) {
if (type == null) continue;
String trimmed = type.trim();
if (trimmed.isEmpty()) continue;
displayTypes.add(trimmed);
if (universalOverrideTypes.contains(trimmed)) {
displayTypes.add(BaubleExpandedSlots.universalType);
}
}
return displayTypes.toArray(new String[0]);
}
2021-11-21 23:28:57 -05:00
}