添加智能倍增对高级ae的处理样板支持
This commit is contained in:
parent
61d7980ba6
commit
ac2c524fe8
|
|
@ -5,6 +5,7 @@ import appeng.crafting.inv.CraftingSimulationState;
|
||||||
import appeng.crafting.pattern.AEProcessingPattern;
|
import appeng.crafting.pattern.AEProcessingPattern;
|
||||||
import com.extendedae_plus.ae.api.crafting.ScaledProcessingPattern;
|
import com.extendedae_plus.ae.api.crafting.ScaledProcessingPattern;
|
||||||
import com.extendedae_plus.api.smartDoubling.ISmartDoublingAwarePattern;
|
import com.extendedae_plus.api.smartDoubling.ISmartDoublingAwarePattern;
|
||||||
|
import com.extendedae_plus.util.smartDoubling.PatternScaler;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
|
@ -42,6 +43,7 @@ public abstract class CraftingSimulationStateMixin {
|
||||||
perCraftLimit = aware.eap$getMultiplierLimit(); // 已经是最大倍率限制
|
perCraftLimit = aware.eap$getMultiplierLimit(); // 已经是最大倍率限制
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 不允许缩放或者需求为 1
|
||||||
if (!allowScaling || craftsAmount == 1) {
|
if (!allowScaling || craftsAmount == 1) {
|
||||||
crafts.merge(processingPattern, craftsAmount, Long::sum);
|
crafts.merge(processingPattern, craftsAmount, Long::sum);
|
||||||
return;
|
return;
|
||||||
|
|
@ -56,7 +58,7 @@ public abstract class CraftingSimulationStateMixin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 无限制:合并倍率并复用 ScaledProcessingPattern 对象 */
|
/** 无限制:合并倍率并复用 ScaledProcessingPattern 或 AAE 扩展 */
|
||||||
private void mergeUnlimited(AEProcessingPattern original, long multiplier) {
|
private void mergeUnlimited(AEProcessingPattern original, long multiplier) {
|
||||||
ScaledProcessingPattern existing = scaledCache.get(original);
|
ScaledProcessingPattern existing = scaledCache.get(original);
|
||||||
long total = multiplier;
|
long total = multiplier;
|
||||||
|
|
@ -66,23 +68,25 @@ public abstract class CraftingSimulationStateMixin {
|
||||||
crafts.remove(existing);
|
crafts.remove(existing);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScaledProcessingPattern scaled = new ScaledProcessingPattern(original, total);
|
// 使用 PatternScaler 自动选择原版或 AAE 扩展
|
||||||
|
ScaledProcessingPattern scaled = PatternScaler.createScaled(original, total);
|
||||||
|
|
||||||
scaledCache.put(original, scaled);
|
scaledCache.put(original, scaled);
|
||||||
crafts.put(scaled, 1L);
|
crafts.put(scaled, 1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 有限制:拆分 full + remainder */
|
/** 有限制:拆分 full + remainder,并支持原版/AAE 扩展 */
|
||||||
private void splitLimited(AEProcessingPattern original, long totalAmount, int limit) {
|
private void splitLimited(AEProcessingPattern original, long totalAmount, int limit) {
|
||||||
long fullCrafts = totalAmount / limit;
|
long fullCrafts = totalAmount / limit;
|
||||||
long remainder = totalAmount % limit;
|
long remainder = totalAmount % limit;
|
||||||
|
|
||||||
if (fullCrafts > 0) {
|
if (fullCrafts > 0) {
|
||||||
ScaledProcessingPattern scaledFull = new ScaledProcessingPattern(original, limit);
|
ScaledProcessingPattern scaledFull = PatternScaler.createScaled(original, limit);
|
||||||
crafts.merge(scaledFull, fullCrafts, Long::sum);
|
crafts.merge(scaledFull, fullCrafts, Long::sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remainder > 0) {
|
if (remainder > 0) {
|
||||||
ScaledProcessingPattern scaledRemainder = new ScaledProcessingPattern(original, remainder);
|
ScaledProcessingPattern scaledRemainder = PatternScaler.createScaled(original, remainder);
|
||||||
crafts.merge(scaledRemainder, 1L, Long::sum);
|
crafts.merge(scaledRemainder, 1L, Long::sum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,63 @@ import appeng.api.stacks.AEFluidKey;
|
||||||
import appeng.api.stacks.AEItemKey;
|
import appeng.api.stacks.AEItemKey;
|
||||||
import appeng.api.stacks.AEKey;
|
import appeng.api.stacks.AEKey;
|
||||||
import appeng.crafting.pattern.AEProcessingPattern;
|
import appeng.crafting.pattern.AEProcessingPattern;
|
||||||
|
import com.extendedae_plus.ae.api.crafting.ScaledProcessingPattern;
|
||||||
|
import net.minecraftforge.fml.loading.LoadingModList;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
public final class PatternScaler {
|
public final class PatternScaler {
|
||||||
|
private static final boolean advAvailable;
|
||||||
|
private static final Constructor<?> advCtor;
|
||||||
|
private static final Class<?> advIfaceClass;
|
||||||
|
|
||||||
|
static {
|
||||||
|
boolean available = false;
|
||||||
|
Constructor<?> ctor = null;
|
||||||
|
Class<?> iface = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 尝试加载扩展类
|
||||||
|
Class<?> clazz = Class.forName("com.extendedae_plus.ae.api.crafting.ScaledProcessingPatternAdv");
|
||||||
|
ctor = clazz.getConstructor(AEProcessingPattern.class, long.class);
|
||||||
|
|
||||||
|
// 加载接口
|
||||||
|
iface = Class.forName("net.pedroksl.advanced_ae.common.patterns.AdvPatternDetails");
|
||||||
|
|
||||||
|
// 检查是否安装 Advanced AE
|
||||||
|
if (LoadingModList.get() != null && LoadingModList.get().getModFileById("advanced_ae") != null) {
|
||||||
|
available = true;
|
||||||
|
}
|
||||||
|
} catch (Throwable ignored) {}
|
||||||
|
|
||||||
|
advAvailable = available;
|
||||||
|
advCtor = ctor;
|
||||||
|
advIfaceClass = iface;
|
||||||
|
}
|
||||||
|
|
||||||
private PatternScaler() {}
|
private PatternScaler() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建缩放样板。
|
||||||
|
* 自动支持原版 AE 和可选 AAE 的 AdvProcessingPattern。
|
||||||
|
*/
|
||||||
|
public static ScaledProcessingPattern createScaled(AEProcessingPattern base, long multiplier) {
|
||||||
|
// 尝试 Advanced AE 扩展
|
||||||
|
if (advAvailable && advIfaceClass != null && advCtor != null) {
|
||||||
|
try {
|
||||||
|
if (advIfaceClass.isInstance(base)) {
|
||||||
|
return (ScaledProcessingPattern) advCtor.newInstance(base, multiplier);
|
||||||
|
}
|
||||||
|
} catch (InstantiationException | IllegalAccessException | InvocationTargetException ignored) {
|
||||||
|
// 出错退回普通逻辑
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 回退原版
|
||||||
|
return new ScaledProcessingPattern(base, multiplier);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算基于 limit 的最大允许倍率(单次输出主物品 ≤ limit)
|
* 计算基于 limit 的最大允许倍率(单次输出主物品 ≤ limit)
|
||||||
*/
|
*/
|
||||||
|
|
@ -42,7 +95,8 @@ public final class PatternScaler {
|
||||||
if ("me.ramidzkh.mekae2.ae2.MekanismKey".equals(key.getClass().getName())) {
|
if ("me.ramidzkh.mekae2.ae2.MekanismKey".equals(key.getClass().getName())) {
|
||||||
return 1000L;
|
return 1000L;
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
return 1L;
|
return 1L;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user