小优化
This commit is contained in:
parent
eaed56fada
commit
f068f00e7d
|
|
@ -1,55 +0,0 @@
|
|||
package com.extendedae_plus.compat;
|
||||
|
||||
import com.extendedae_plus.util.Logger;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
|
||||
/**
|
||||
* 兼容性测试类
|
||||
* 用于验证模组兼容性检测是否正常工作
|
||||
*/
|
||||
public class CompatibilityTest {
|
||||
|
||||
/**
|
||||
* 测试模组兼容性检测
|
||||
*/
|
||||
public static void testCompatibility() {
|
||||
|
||||
// 测试appflux模组检测
|
||||
boolean appfluxExists = ModList.get().isLoaded("appflux");
|
||||
|
||||
// 测试升级卡槽功能启用状态
|
||||
boolean shouldEnableUpgrades = UpgradeSlotCompat.shouldEnableUpgradeSlots();
|
||||
|
||||
// 测试Screen升级面板添加状态
|
||||
boolean shouldAddPanel = UpgradeSlotCompat.shouldAddUpgradePanelToScreen();
|
||||
|
||||
// 输出兼容性策略
|
||||
if (appfluxExists) {
|
||||
} else {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取兼容性状态报告
|
||||
*/
|
||||
public static String getCompatibilityReport() {
|
||||
boolean appfluxExists = ModList.get().isLoaded("appflux");
|
||||
boolean upgradesEnabled = UpgradeSlotCompat.shouldEnableUpgradeSlots();
|
||||
|
||||
StringBuilder report = new StringBuilder();
|
||||
report.append("ExtendedAE_Plus 兼容性报告:\n");
|
||||
report.append("- ExtendedAE-appflux模组: ").append(appfluxExists ? "已安装" : "未安装").append("\n");
|
||||
report.append("- 升级卡槽功能: ").append(upgradesEnabled ? "启用中" : "已禁用").append("\n");
|
||||
|
||||
if (appfluxExists && !upgradesEnabled) {
|
||||
report.append("- 兼容性状态: 正常 (使用appflux的升级功能)\n");
|
||||
} else if (!appfluxExists && upgradesEnabled) {
|
||||
report.append("- 兼容性状态: 正常 (使用我们的升级功能)\n");
|
||||
} else {
|
||||
report.append("- 兼容性状态: 异常 (配置不一致)\n");
|
||||
}
|
||||
|
||||
return report.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.extendedae_plus.mixin.accessor;
|
||||
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.components.Renderable;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
|
|
@ -15,4 +16,7 @@ public interface ScreenAccessor {
|
|||
|
||||
@Accessor("children")
|
||||
List<GuiEventListener> eap$getChildren();
|
||||
|
||||
@Accessor("font")
|
||||
Font eap$getFont();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ import appeng.menu.slot.AppEngSlot;
|
|||
import com.extendedae_plus.api.IExPatternPageAccessor;
|
||||
import com.extendedae_plus.content.ClientPatternHighlightStore;
|
||||
import com.extendedae_plus.init.ModNetwork;
|
||||
import com.extendedae_plus.mixin.accessor.AbstractContainerScreenAccessor;
|
||||
import com.extendedae_plus.mixin.accessor.ScreenAccessor;
|
||||
import com.extendedae_plus.mixin.ae2.accessor.AEBaseScreenAccessor;
|
||||
import com.extendedae_plus.network.crafting.CraftingMonitorJumpC2SPacket;
|
||||
import com.extendedae_plus.network.crafting.CraftingMonitorOpenProviderC2SPacket;
|
||||
|
|
@ -31,7 +33,6 @@ import net.minecraft.world.inventory.Slot;
|
|||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
|
@ -98,43 +99,11 @@ public abstract class AEBaseScreenMixin {
|
|||
} catch (Throwable ignored) {}
|
||||
}
|
||||
|
||||
@Unique
|
||||
private static int eap$getIntField(Object self, String name, int def) {
|
||||
Class<?> c = self.getClass();
|
||||
while (c != null && c != Object.class) {
|
||||
try {
|
||||
var f = c.getDeclaredField(name);
|
||||
f.setAccessible(true);
|
||||
Object v = f.get(self);
|
||||
if (v instanceof Integer i) return i;
|
||||
} catch (Throwable ignored) {}
|
||||
c = c.getSuperclass();
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
@Unique
|
||||
private static Font eap$getFont(Object self) {
|
||||
Class<?> c = self.getClass();
|
||||
while (c != null && c != Object.class) {
|
||||
try {
|
||||
var f = c.getDeclaredField("font");
|
||||
f.setAccessible(true);
|
||||
Object v = f.get(self);
|
||||
if (v instanceof Font font) return font;
|
||||
} catch (Throwable ignored) {}
|
||||
c = c.getSuperclass();
|
||||
}
|
||||
return net.minecraft.client.Minecraft.getInstance().font;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写renderSlot方法,为所有可见的样板槽位添加数量显示
|
||||
*/
|
||||
@Inject(method = "renderSlot", at = @At("TAIL"))
|
||||
private void eap$renderSlotAmounts(GuiGraphics guiGraphics, Slot s, CallbackInfo ci) {
|
||||
Object self = this;
|
||||
|
||||
// 只处理AppEngSlot类型的槽位
|
||||
if (!(s instanceof AppEngSlot appEngSlot)) {
|
||||
return;
|
||||
|
|
@ -158,7 +127,7 @@ public abstract class AEBaseScreenMixin {
|
|||
}
|
||||
|
||||
// 在槽位右下角绘制数量文本
|
||||
Font font = eap$getFont(self);
|
||||
Font font = ((ScreenAccessor) this).eap$getFont();
|
||||
GuiUtil.drawAmountText(guiGraphics, font, amountText, appEngSlot.x, appEngSlot.y, 0.6f);
|
||||
|
||||
try {
|
||||
|
|
@ -195,14 +164,15 @@ public abstract class AEBaseScreenMixin {
|
|||
}
|
||||
|
||||
// 计算“样板”文本起点与宽度,按对齐方式与缩放修正 x/y
|
||||
int imageWidth = eap$getIntField(self, "imageWidth", 0);
|
||||
int imageHeight = eap$getIntField(self, "imageHeight", 0);
|
||||
int imageWidth = ((AbstractContainerScreenAccessor<?>) this).eap$getImageWidth();
|
||||
int imageHeight = ((AbstractContainerScreenAccessor<?>) this).eap$getImageHeight();
|
||||
|
||||
Rect2i bounds = new Rect2i(0, 0, imageWidth, imageHeight);
|
||||
Point pos = text.getPosition().resolve(bounds);
|
||||
|
||||
float scale = text.getScale();
|
||||
|
||||
Font font = eap$getFont(self);
|
||||
Font font = ((ScreenAccessor) this).eap$getFont();
|
||||
// 只关心第一行(标题类文本无换行或 maxWidth<=0)
|
||||
var contentLine = (text.getMaxWidth() <= 0)
|
||||
? content.getVisualOrderText()
|
||||
|
|
|
|||
|
|
@ -21,10 +21,12 @@ import javax.annotation.Nullable;
|
|||
* 样板供应器数据工具类
|
||||
* 用于获取样板供应器中的所有样板数据,包括输入输出物品的数量信息
|
||||
*/
|
||||
public class PatternProviderDataUtil {
|
||||
public final class PatternProviderDataUtil {
|
||||
private static final int INVALID_SLOT = -1;
|
||||
private static final String UNKNOWN_PROVIDER = "未知供应器";
|
||||
|
||||
private PatternProviderDataUtil() {}
|
||||
|
||||
/**
|
||||
* 判断 provider 是否可用并属于指定网格(在线且有频道/处于活跃状态)
|
||||
*/
|
||||
|
|
@ -37,8 +39,7 @@ public class PatternProviderDataUtil {
|
|||
IManagedGridNode mainNode = accessor.eap$mainNode();
|
||||
return mainNode != null && mainNode.isActive();
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -80,8 +81,7 @@ public class PatternProviderDataUtil {
|
|||
if (details != null && targetDefinition.equals(details.getDefinition())) {
|
||||
return i;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
return INVALID_SLOT;
|
||||
}
|
||||
|
|
@ -156,8 +156,7 @@ public class PatternProviderDataUtil {
|
|||
// 这样客户端可以根据自己的语言设置进行翻译
|
||||
return Component.Serializer.toJson(group.name());
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
return providerId > 0 ? "样板供应器 #" + providerId : "样板供应器";
|
||||
}
|
||||
}
|
||||
|
|
@ -136,15 +136,15 @@ public final class PatternTerminalUtil {
|
|||
/**
|
||||
* 列出当前菜单中所有供应器的服务器ID(原样返回 byId 的 key 集合)。
|
||||
*/
|
||||
public static java.util.List<Long> getAllProviderIds(PatternAccessTermMenu menu) {
|
||||
java.util.List<Long> result = new java.util.ArrayList<>();
|
||||
public static List<Long> getAllProviderIds(PatternAccessTermMenu menu) {
|
||||
List<Long> result = new ArrayList<>();
|
||||
if (menu == null) return result;
|
||||
try {
|
||||
Field byIdField = PatternTerminalUtil.findByIdField(menu.getClass());
|
||||
if (byIdField == null) return result;
|
||||
byIdField.setAccessible(true);
|
||||
@SuppressWarnings("unchecked")
|
||||
java.util.Map<Long, Object> byId = (java.util.Map<Long, Object>) byIdField.get(menu);
|
||||
Map<Long, Object> byId = (Map<Long, Object>) byIdField.get(menu);
|
||||
if (byId != null) {
|
||||
result.addAll(byId.keySet());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user