From 2ac589066b8fd38ca2bed2f7454eb340e41d0cef Mon Sep 17 00:00:00 2001 From: C-H716 <1536152356@qq.com> Date: Mon, 29 Sep 2025 14:47:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=9D=E5=A7=8B=E5=8C=96=E7=BC=93?= =?UTF-8?q?=E5=AD=98FE=E5=AD=98=E5=82=A8=E5=8F=8D=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ae/parts/EntitySpeedTickerPart.java | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/extendedae_plus/ae/parts/EntitySpeedTickerPart.java b/src/main/java/com/extendedae_plus/ae/parts/EntitySpeedTickerPart.java index 4d06f38..5ff74f6 100644 --- a/src/main/java/com/extendedae_plus/ae/parts/EntitySpeedTickerPart.java +++ b/src/main/java/com/extendedae_plus/ae/parts/EntitySpeedTickerPart.java @@ -65,6 +65,27 @@ public class EntitySpeedTickerPart extends UpgradeablePart implements IGridTick public EntitySpeedTickerMenu menu; // 当前打开的菜单实例 private boolean networkEnergySufficient = true; // 网络能量是否充足 + private static volatile Method cachedFEExtractMethod; + private static volatile boolean FE_UNAVAILABLE; + + // ===== 静态块:反射初始化 FE 方法 ===== + static { + if (ModList.get().isLoaded("appflux")) { + try { + Class helperClass = Class.forName("com.extendedae_plus.util.FluxEnergyHelper"); + cachedFEExtractMethod = helperClass.getMethod( + "extractFE", + IEnergyService.class, + MEStorage.class, + long.class, + IActionSource.class + ); + FE_UNAVAILABLE = false; + } catch (Exception e) { + FE_UNAVAILABLE = true; + } + } + } /** * 构造函数,初始化部件并设置网络节点属性。 * @param partItem 部件物品 @@ -250,7 +271,7 @@ public class EntitySpeedTickerPart extends UpgradeablePart implements IGridTick private int calculateSpeed() { int entitySpeedCardCount = getUpgrades().getInstalledUpgrades(ModItems.ENTITY_SPEED_CARD.get()); if (entitySpeedCardCount <= 0) return 0; - return (int) PowerUtils.computeProductWithCap(getUpgrades(), 8); + return PowerUtils.computeProductWithCap(getUpgrades(), 8); } /** @@ -302,23 +323,16 @@ public class EntitySpeedTickerPart extends UpgradeablePart implements IGridTick } private boolean tryExtractFE(IEnergyService energyService, MEStorage storage, double requiredPower, IActionSource source) { + if (FE_UNAVAILABLE || cachedFEExtractMethod == null) return false; try { - Class helperClass = Class.forName("com.extendedae_plus.util.FluxEnergyHelper"); - Method extractMethod = helperClass.getMethod( - "extractFE", - IEnergyService.class, - MEStorage.class, - long.class, - IActionSource.class - ); - long feRequired = (long) requiredPower << 1; // 1 AE = 2 FE - long feExtracted = (long) extractMethod.invoke(null, energyService, storage, feRequired, source); + long feRequired = (long) requiredPower << 1; + long feExtracted = (long) cachedFEExtractMethod.invoke(null, energyService, storage, feRequired, source); if (feExtracted >= feRequired) { updateNetworkEnergySufficient(true); return true; } } catch (Exception e) { - // 如果反射失败,视为 FE 不可用 + FE_UNAVAILABLE = true; } updateNetworkEnergySufficient(false); return false;