添加合成计划字节数使用的格式化显示
This commit is contained in:
parent
42a2df53da
commit
43361b2023
|
|
@ -0,0 +1,26 @@
|
|||
// 文件路径: src/main/java/yourmod/mixin/CraftConfirmScreenMixin.java
|
||||
package com.extendedae_plus.mixin.ae2.client.gui;
|
||||
|
||||
import appeng.client.gui.me.crafting.CraftConfirmScreen;
|
||||
import com.extendedae_plus.util.NumberFormatUtil;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
|
||||
@Mixin(value = CraftConfirmScreen.class, remap = false)
|
||||
public class CraftConfirmScreenMixin {
|
||||
|
||||
@Redirect(
|
||||
method = "updateBeforeRender",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Ljava/text/NumberFormat;format(J)Ljava/lang/String;",
|
||||
ordinal = 0
|
||||
)
|
||||
)
|
||||
private String useCustomFormat(NumberFormat instance, long number) {
|
||||
return NumberFormatUtil.formatNumber(number);
|
||||
}
|
||||
}
|
||||
|
|
@ -18,16 +18,24 @@ public class NumberFormatUtil {
|
|||
return String.valueOf(number);
|
||||
}
|
||||
|
||||
String[] preFixes = new String[]{"k", "M", "G", "T", "P", "E", "Z", "Y"};
|
||||
String[] suffixes = {"k", "M", "G", "T", "P", "E", "Z", "Y"};
|
||||
double value = number;
|
||||
String level = "";
|
||||
int index = 0;
|
||||
|
||||
for (int offset = 0; value >= 1000.0 && offset < preFixes.length; ++offset) {
|
||||
while (value >= 1000.0 && index < suffixes.length) {
|
||||
value /= 1000.0;
|
||||
level = preFixes[offset];
|
||||
index++;
|
||||
}
|
||||
|
||||
return formatDecimal(value, level);
|
||||
String formatted;
|
||||
if (Math.abs(value - Math.round(value)) < 0.001) {
|
||||
formatted = String.valueOf(Math.round(value));
|
||||
} else {
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
formatted = df.format(value);
|
||||
}
|
||||
|
||||
return formatted + suffixes[index - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
"ae2.accessor.PatternAccessTermScreenAccessor",
|
||||
"ae2.accessor.PatternAccessTermScreenSlotsRowAccessor",
|
||||
"ae2.client.gui.AEBaseScreenMixin",
|
||||
"ae2.client.gui.CraftConfirmScreenMixin",
|
||||
"ae2.client.gui.InterfaceScreenMixin",
|
||||
"ae2.client.gui.PatternEncodingTermScreenMixin",
|
||||
"ae2.client.gui.SlotGridLayoutMixin",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user