Tinker Tab Removal - Baubles Slot Limit Config (#32)

This commit is contained in:
Ranzu authored and GitHub committed 2026-05-17 14:42:03 -04:00
1 parent ba5e309ee1
commit 7e5c47e216
6 files changed
+165 -29

No files matched your search

@@ -1,6 +1,9 @@
package baubles.common;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import baubles.api.expanded.BaubleExpandedSlots;
import net.minecraftforge.common.config.Configuration;
@@ -17,6 +20,10 @@ public class BaublesConfig {
public static boolean showUnusedSlots = false;
public static boolean manualSlotSelection = false;
public static boolean displayTooltipOnHover = true;
public static String[] slotStackLimitOverrides = new String[] {};
public static String[] slotUniversalOverrides = new String[] {};
private static final Map<String, Integer> stackLimitsByType = new HashMap<>();
private static final ArrayList<String> universalOverrideTypes = new ArrayList<>();
public static String[] overrideSlotTypes = new String[] {
BaubleExpandedSlots.amuletType,
@@ -71,6 +78,58 @@ public class BaublesConfig {
" types will reduce compatibility with mods made for original Baubles versions!\n",
currentlyRegisteredTypes.toArray(new String[0])
);
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)
);
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])
);
stackLimitsByType.clear();
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);
}
}
for (String entry : slotStackLimitOverrides) {
if (entry == null) continue;
String[] split = entry.split("=", 2);
if (split.length != 2) {
Baubles.log.warn("Ignoring malformed slotStackLimitOverrides entry '{}'. Expected format: type=limit", entry);
continue;
}
String type = split[0].trim();
String limitText = split[1].trim();
if (!BaubleExpandedSlots.isTypeRegistered(type)) {
Baubles.log.warn("Ignoring slotStackLimitOverrides entry '{}': unknown slot type '{}'", entry, type);
continue;
}
try {
int limit = Integer.parseInt(limitText);
if (limit > 0) {
stackLimitsByType.put(type, limit);
}
} catch (NumberFormatException ignored) {
Baubles.log.warn("Ignoring slotStackLimitOverrides entry '{}': '{}' is not a valid integer", entry, limitText);
}
}
if(manualSlotSelection) {
BaubleExpandedSlots.overrideSlots(overrideSlotTypes);
@@ -81,4 +140,36 @@ public class BaublesConfig {
}
}
public static int getStackLimitForSlotType(String type) {
if (type == null) return 1;
return stackLimitsByType.getOrDefault(type, 1);
}
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]);
}
}