feat: 修正逻辑

This commit is contained in:
C-H716 2025-09-30 10:01:48 +08:00
parent e7add431ce
commit 8ba6aa4fcd

View File

@ -69,7 +69,10 @@ public class EntitySpeedTickerPart extends UpgradeablePart implements IGridTicka
// 静态块初始化缓存
static {
cachedAttempts = ModConfig.INSTANCE.prioritizeDiskEnergy ? new boolean[]{false, true, true} : new boolean[]{true, false, true};
// 优先磁盘 -> FE 然后 AE否则 AE 然后 FE
cachedAttempts = ModConfig.INSTANCE.prioritizeDiskEnergy ?
new boolean[]{ true, true, false } :
new boolean[]{ false, true, true };
if (ModList.get().isLoaded("appflux")) {
try {
Class<?> helperClass = Class.forName("com.extendedae_plus.util.FluxEnergyHelper");
@ -118,10 +121,14 @@ public class EntitySpeedTickerPart extends UpgradeablePart implements IGridTicka
*/
public static void updateCachedAttempts(boolean prioritizeDiskEnergy) {
synchronized (EntitySpeedTickerPart.class) {
cachedAttempts = prioritizeDiskEnergy ? new boolean[]{false, true, true} : new boolean[]{true, false, true};
// 优先磁盘 -> FE 然后 AE否则 AE 然后 FE
cachedAttempts = prioritizeDiskEnergy ?
new boolean[]{ true, true, false } :
new boolean[]{ false, true, true };
}
}
public boolean getAccelerateEnabled() {
return this.getConfigManager().getSetting(com.extendedae_plus.ae.api.config.Settings.ACCELERATE) == YesNo.YES;
}
@ -336,35 +343,39 @@ public class EntitySpeedTickerPart extends UpgradeablePart implements IGridTicka
for (int i = 0; i < cachedAttempts.length; i++) {
if (!cachedAttempts[i]) continue;
if (i == 0 || i == 2) { // FE 提取
if (!FE_UNAVAILABLE && cachedFEExtractMethod != null) {
try {
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_UNAVAILABLE = true;
// FE 提取
if ((i == 0 || i == 2) && !FE_UNAVAILABLE && cachedFEExtractMethod != null) {
try {
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_UNAVAILABLE = true;
continue;
}
} else { // AE 提取
}
// AE 提取
else {
double simulated = energyService.extractAEPower(requiredPower, Actionable.SIMULATE, PowerMultiplier.CONFIG);
if (simulated >= requiredPower) {
if (simulated >= requiredPower) { // 模拟足够
double extracted = energyService.extractAEPower(requiredPower, Actionable.MODULATE, PowerMultiplier.CONFIG);
boolean sufficient = extracted >= requiredPower;
updateNetworkEnergySufficient(sufficient);
if (sufficient) {
return true;
}
if (sufficient) return true;
}
}
}
// 所有尝试都不够
updateNetworkEnergySufficient(false);
return false;
}
/**
* 执行加速 tick 操作
*