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,7 @@
package baubles.api.expanded;
import baubles.api.BaublesApi;
import baubles.common.BaublesConfig;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.GuiScreen;
@@ -26,9 +27,10 @@ public class BaubleItemHelper {
boolean shiftHeld = GuiScreen.isShiftKeyDown();
if(shiftHeld) {
tooltip.add(StatCollector.translateToLocal("tooltip.compatibleslots"));
for(int i = 0; i < types.length; i++) {
String type = StatCollector.translateToLocal("slot." + types[i]);
if(i < types.length - 1) type += ",";
String[] displayTypes = BaublesConfig.getDisplayTypesWithUniversalOverrides(types);
for(int i = 0; i < displayTypes.length; i++) {
String type = StatCollector.translateToLocal("slot." + displayTypes[i]);
if(i < displayTypes.length - 1) type += ",";
tooltip.add(type);
}
} else {
@@ -333,7 +333,7 @@ public class GuiPlayerExpanded extends GuiContainer implements INEIGuiHandler {
tooltipIndexCache = slotIndex;
String slotType = BaubleExpandedSlots.getSlotType(slotIndex);
String slotType = slot instanceof SlotBauble ? ((SlotBauble) slot).getSlotType() : BaubleExpandedSlots.unknownType;
tooltipCache.clear();
@@ -348,7 +348,7 @@ public class GuiPlayerExpanded extends GuiContainer implements INEIGuiHandler {
if (heldItem.getItem() instanceof IBaubleExpanded baubleExpandedItem) {
String[] itemBaubleTypes = baubleExpandedItem.getBaubleTypes(heldItem);
for(String itemBaubleType : itemBaubleTypes) {
if (itemBaubleType.equals(BaubleExpandedSlots.universalType) || slotType.equals(itemBaubleType)) {
if (BaublesConfig.canTypeFitSlot(itemBaubleType, slotType)) {
fitsInSlot = true;
break;
}
@@ -356,7 +356,7 @@ public class GuiPlayerExpanded extends GuiContainer implements INEIGuiHandler {
}
else if(heldItem.getItem() instanceof IBauble baubleItem) {
String itemBaubleType = BaubleExpandedSlots.getTypeFromBaubleType(baubleItem.getBaubleType(heldItem));
if (itemBaubleType.equals(BaubleExpandedSlots.universalType) || slotType.equals(itemBaubleType)) {
if (BaublesConfig.canTypeFitSlot(itemBaubleType, slotType)) {
fitsInSlot = true;
}
}
@@ -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]);
}
}
@@ -247,26 +247,16 @@ public class ContainerPlayerExpanded extends Container {
returnStack = null;
}
} else if (item instanceof IBauble bauble && bauble.canEquip(returnStack, thePlayer)) {
for (int baubleSlot = baubleStart; baubleSlot < baubleEnd; baubleSlot++) {
if (returnStack == null) {
break;
}
if (((Slot) inventorySlots.get(baubleSlot)).getHasStack()) {
continue;
}
String[] types;
if (item instanceof IBaubleExpanded) {
types = ((IBaubleExpanded) item).getBaubleTypes(returnStack);
} else {
types = new String[] {BaubleExpandedSlots.getTypeFromBaubleType(bauble.getBaubleType(returnStack))};
}
for (String type : types) {
if ((type.equals(BaubleExpandedSlots.universalType)
|| type.equals(BaubleExpandedSlots.getSlotType(baubleSlot - baubleStart)))
&& !mergeItemStack(originalStack, baubleSlot, baubleSlot + 1, false)) {
returnStack = null;
}
}
String[] types = item instanceof IBaubleExpanded
? ((IBaubleExpanded) item).getBaubleTypes(returnStack)
: new String[] {BaubleExpandedSlots.getTypeFromBaubleType(bauble.getBaubleType(returnStack))};
// Priority 2: direct slot matches (or universal items)
tryMergeIntoBaubleSlotsByPriority(originalStack, baubleStart, baubleEnd, types, 2);
// Priority 1: override matches (e.g. amulet/ring/belt into universal)
if (originalStack.stackSize > 0) {
tryMergeIntoBaubleSlotsByPriority(originalStack, baubleStart, baubleEnd, types, 1);
}
} else if (slotIndex >= baubleEnd && slotIndex < invEnd) {
if (!mergeItemStack(originalStack, invEnd, hotbarEnd, false)) {
@@ -307,6 +297,54 @@ public class ContainerPlayerExpanded extends Container {
super.putStacksInSlots(p_75131_1_);
}
private void tryMergeIntoBaubleSlotsByPriority(ItemStack sourceStack, int baubleStart, int baubleEnd, String[] itemTypes, int priority) {
// First pass: merge into occupied, compatible bauble slots.
for (int baubleSlot = baubleStart; baubleSlot < baubleEnd && sourceStack.stackSize > 0; baubleSlot++) {
Slot targetInventorySlot = (Slot) inventorySlots.get(baubleSlot);
if (!targetInventorySlot.getHasStack()) {
continue;
}
String targetSlotType = targetInventorySlot instanceof SlotBauble
? ((SlotBauble) targetInventorySlot).getSlotType()
: BaubleExpandedSlots.unknownType;
if (getBestMatchPriority(itemTypes, targetSlotType) != priority) {
continue;
}
mergeItemStack(sourceStack, baubleSlot, baubleSlot + 1, false);
}
// Second pass: place remaining items into empty, compatible bauble slots.
for (int baubleSlot = baubleStart; baubleSlot < baubleEnd && sourceStack.stackSize > 0; baubleSlot++) {
Slot targetInventorySlot = (Slot) inventorySlots.get(baubleSlot);
if (targetInventorySlot.getHasStack()) {
continue;
}
String targetSlotType = targetInventorySlot instanceof SlotBauble
? ((SlotBauble) targetInventorySlot).getSlotType()
: BaubleExpandedSlots.unknownType;
if (getBestMatchPriority(itemTypes, targetSlotType) != priority) {
continue;
}
mergeItemStack(sourceStack, baubleSlot, baubleSlot + 1, false);
}
}
private int getBestMatchPriority(String[] itemTypes, String slotType) {
int best = 0;
for (String type : itemTypes) {
if (type == null) {
continue;
}
if (type.equals(BaubleExpandedSlots.universalType) || type.equals(slotType)) {
return 2;
}
if (BaublesConfig.canTypeFitSlot(type, slotType)) {
best = 1;
}
}
return best;
}
protected boolean mergeItemStack(ItemStack sourceStack, int startIndex, int endIndex, boolean reverse, Slot sourceSlot) {
boolean merged = false;
int index = reverse ? endIndex - 1 : startIndex;
@@ -7,6 +7,7 @@ import baubles.api.BaubleType;
import baubles.api.IBauble;
import baubles.api.expanded.BaubleExpandedSlots;
import baubles.api.expanded.IBaubleExpanded;
import baubles.common.BaublesConfig;
import baubles.common.lib.ItemStackHelper;
import baubles.common.network.PacketHandler;
import baubles.common.network.PacketSyncBauble;
@@ -209,7 +210,7 @@ public class InventoryBaubles implements IInventory {
}
for(String type : types) {
if(type.equals(BaubleExpandedSlots.universalType) || type.equals(slotType)) {
if (BaublesConfig.canTypeFitSlot(type, slotType)) {
return true;
}
}
@@ -36,6 +36,10 @@ public class SlotBauble extends Slot {
}
}
public String getSlotType() {
return slotType;
}
/**
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
*/
@@ -59,7 +63,7 @@ public class SlotBauble extends Slot {
}
for(String type : types) {
if(type.equals(BaubleExpandedSlots.universalType) || type.equals(slotType)) {
if (BaublesConfig.canTypeFitSlot(type, slotType)) {
return true;
}
}
@@ -75,7 +79,7 @@ public class SlotBauble extends Slot {
@Override
public int getSlotStackLimit() {
return 1;
return BaublesConfig.getStackLimitForSlotType(slotType);
}
@Override