feat: 放宽扩展供应器内的样板手动倍增限制(不超int), 调整样板显示,以支持大数显示
This commit is contained in:
parent
857fadc7ad
commit
6f42b50ea0
|
|
@ -134,10 +134,12 @@ public abstract class ContainerExPatternProviderMixin extends PatternProviderMen
|
||||||
} else {
|
} else {
|
||||||
for (var stack : stacks) {
|
for (var stack : stacks) {
|
||||||
if (stack != null) {
|
if (stack != null) {
|
||||||
long upper = 999999L * stack.what().getAmountPerUnit();
|
long amt = stack.amount();
|
||||||
if (stack.amount() * scale > upper) {
|
// 先检查乘法是否会导致超出 Long.MAX_VALUE,避免溢出
|
||||||
|
if (amt > Integer.MAX_VALUE / scale) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// 已移除原有的业务上限检查(999999 * amountPerUnit),仅保留溢出检查
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -150,7 +152,18 @@ public abstract class ContainerExPatternProviderMixin extends PatternProviderMen
|
||||||
var stack = src[i];
|
var stack = src[i];
|
||||||
if (stack != null) {
|
if (stack != null) {
|
||||||
long amt = stack.amount();
|
long amt = stack.amount();
|
||||||
long newAmt = div ? (amt / scale) : (amt * scale);
|
long newAmt;
|
||||||
|
if (div) {
|
||||||
|
newAmt = amt / scale;
|
||||||
|
} else {
|
||||||
|
// 防御性检查:虽然上游已检查过,但在此处再次确保不会溢出
|
||||||
|
if (amt > Integer.MAX_VALUE / scale) {
|
||||||
|
// 遇到潜在溢出时跳过该项(保持原样为 null),调用方已通过 eap$checkModify 避免进入此分支
|
||||||
|
dst[i] = null;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
newAmt = amt * scale;
|
||||||
|
}
|
||||||
dst[i] = new GenericStack(stack.what(), newAmt);
|
dst[i] = new GenericStack(stack.what(), newAmt);
|
||||||
} else {
|
} else {
|
||||||
dst[i] = null;
|
dst[i] = null;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package com.extendedae_plus.util;
|
package com.extendedae_plus.util;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数字格式化工具类,提供大数字和小数的格式化功能
|
* 数字格式化工具类,提供大数字和小数的格式化功能
|
||||||
*/
|
*/
|
||||||
|
|
@ -7,46 +9,59 @@ public class NumberFormatUtil {
|
||||||
private NumberFormatUtil() {throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");}
|
private NumberFormatUtil() {throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 格式化数字,将大数字转换为k、m等格式
|
* 格式化数字,将大数字转换为 k、M、G 等格式(物品用整数/一位小数显示规则)
|
||||||
* 支持小数显示,小数点后为0则不显示0
|
|
||||||
* @param number 要格式化的数字
|
* @param number 要格式化的数字
|
||||||
* @return 格式化后的字符串
|
* @return 格式化后的字符串
|
||||||
*/
|
*/
|
||||||
public static String formatNumber(long number) {
|
public static String formatNumber(long number) {
|
||||||
if (number < 1000) {
|
if (number < 1000) {
|
||||||
return String.valueOf(number);
|
return String.valueOf(number);
|
||||||
} else if (number < 1000000) {
|
|
||||||
double value = number / 1000.0;
|
|
||||||
return formatDecimal(value, "k");
|
|
||||||
} else {
|
|
||||||
double value = number / 1000000.0;
|
|
||||||
return formatDecimal(value, "m");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String[] preFixes = new String[]{"k", "M", "G", "T", "P", "E", "Z", "Y"};
|
||||||
|
double value = number;
|
||||||
|
String level = "";
|
||||||
|
|
||||||
|
for (int offset = 0; value >= 1000.0 && offset < preFixes.length; ++offset) {
|
||||||
|
value /= 1000.0;
|
||||||
|
level = preFixes[offset];
|
||||||
|
}
|
||||||
|
|
||||||
|
return formatDecimal(value, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 格式化带小数的数字,支持流体等需要显示小数的场景
|
* 格式化带小数的数字,支持流体等需要显示小数的场景(保留至多两位小数)
|
||||||
|
* 流体显示规则不同于物品,统一使用两位小数的 DecimalFormat
|
||||||
* @param value 小数值
|
* @param value 小数值
|
||||||
* @return 格式化后的字符串
|
* @return 格式化后的字符串
|
||||||
*/
|
*/
|
||||||
public static String formatNumberWithDecimal(double value) {
|
public static String formatNumberWithDecimal(double value) {
|
||||||
if (value < 1000) {
|
if (value < 1000) {
|
||||||
|
DecimalFormat smallDf = new DecimalFormat("#.##");
|
||||||
|
// 小于1000时,若是整数则显示整数,否则显示最多两位小数
|
||||||
if (value == (long) value) {
|
if (value == (long) value) {
|
||||||
return String.valueOf((long) value);
|
return String.valueOf((long) value);
|
||||||
} else {
|
} else {
|
||||||
return String.format("%.1f", value).replaceAll("\\.0$", "");
|
return smallDf.format(value);
|
||||||
}
|
}
|
||||||
} else if (value < 1000000) {
|
|
||||||
return formatDecimal(value / 1000.0, "k");
|
|
||||||
} else {
|
|
||||||
return formatDecimal(value / 1000000.0, "m");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String[] preFixes = new String[]{"k", "M", "G", "T", "P", "E", "Z", "Y"};
|
||||||
|
String level = "";
|
||||||
|
for (int offset = 0; value >= 1000.0 && offset < preFixes.length; ++offset) {
|
||||||
|
value /= 1000.0;
|
||||||
|
level = preFixes[offset];
|
||||||
|
}
|
||||||
|
|
||||||
|
DecimalFormat df = new DecimalFormat("#.##");
|
||||||
|
return df.format(value) + level;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 格式化小数,如果小数点后为0则不显示0
|
* 格式化小数(物品显示规则):如果小数点后接近 0 则显示为整数,否则显示一位小数
|
||||||
* @param value 小数值
|
* @param value 小数值
|
||||||
* @param suffix 后缀(k、m、g等)
|
* @param suffix 后缀(k、M、G 等)
|
||||||
* @return 格式化后的字符串
|
* @return 格式化后的字符串
|
||||||
*/
|
*/
|
||||||
private static String formatDecimal(double value, String suffix) {
|
private static String formatDecimal(double value, String suffix) {
|
||||||
|
|
@ -54,9 +69,9 @@ public class NumberFormatUtil {
|
||||||
if (Math.abs(value - Math.round(value)) < 0.001) {
|
if (Math.abs(value - Math.round(value)) < 0.001) {
|
||||||
return String.valueOf(Math.round(value)) + suffix;
|
return String.valueOf(Math.round(value)) + suffix;
|
||||||
} else {
|
} else {
|
||||||
// 修复重复后缀问题:先格式化数字,再添加后缀
|
// 使用一位小数显示,去掉末尾 .0
|
||||||
String formatted = String.format("%.1f", value).replaceAll("\\.0$", "");
|
String formatted = String.format("%.1f", value).replaceAll("\\.0$", "");
|
||||||
return formatted + suffix;
|
return formatted + suffix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user