兼容applied flux
This commit is contained in:
parent
428f4520b2
commit
b8bfd1a3f6
|
|
@ -44,6 +44,15 @@ public class UpgradeSlotCompat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测是否应该启用频道卡功能
|
||||||
|
* 频道卡是我们独有的功能,即使appflux存在也应该启用
|
||||||
|
* @return 总是返回true,因为频道卡功能不与appflux冲突
|
||||||
|
*/
|
||||||
|
public static boolean shouldEnableChannelCard() {
|
||||||
|
return true; // 频道卡功能总是启用,因为appflux没有实现这个功能
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检测是否应该在Screen中添加升级面板
|
* 检测是否应该在Screen中添加升级面板
|
||||||
* @return true如果应该添加,false如果检测到appflux模组存在
|
* @return true如果应该添加,false如果检测到appflux模组存在
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,8 @@ import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PatternProviderLogic的兼容性Mixin
|
* PatternProviderLogic的兼容性Mixin
|
||||||
* 优先级设置为500,避免与appflux冲突
|
* 优先级设置为1500,在appflux之后应用
|
||||||
|
* 根据appflux是否存在来决定是否实现IUpgradeableObject接口
|
||||||
*/
|
*/
|
||||||
@Mixin(value = PatternProviderLogic.class, priority = 500, remap = false)
|
@Mixin(value = PatternProviderLogic.class, priority = 500, remap = false)
|
||||||
public abstract class PatternProviderLogicCompatMixin implements IUpgradeableObject, InterfaceWirelessLinkBridge {
|
public abstract class PatternProviderLogicCompatMixin implements IUpgradeableObject, InterfaceWirelessLinkBridge {
|
||||||
|
|
@ -64,31 +65,60 @@ public abstract class PatternProviderLogicCompatMixin implements IUpgradeableObj
|
||||||
|
|
||||||
@Unique
|
@Unique
|
||||||
private void eap$compatOnUpgradesChanged() {
|
private void eap$compatOnUpgradesChanged() {
|
||||||
if (!UpgradeSlotCompat.shouldEnableUpgradeSlots()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.host.saveChanges();
|
this.host.saveChanges();
|
||||||
// 升级变更,重置并尝试初始化
|
// 频道卡功能独立于升级槽功能,总是处理
|
||||||
eap$compatLastChannel = -1;
|
if (UpgradeSlotCompat.shouldEnableChannelCard()) {
|
||||||
eap$compatHasInitialized = false;
|
// 升级变更,重置并尝试初始化频道卡
|
||||||
eap$compatInitializeChannelLink();
|
eap$compatLastChannel = -1;
|
||||||
|
eap$compatHasInitialized = false;
|
||||||
|
eap$compatInitializeChannelLink();
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
com.extendedae_plus.util.ExtendedAELogger.LOGGER.error("兼容性升级变更处理失败", e);
|
com.extendedae_plus.util.ExtendedAELogger.LOGGER.error("兼容性升级变更处理失败", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 监听appflux的升级变化 - 通过注入到appflux的af_$onUpgradesChanged方法
|
||||||
|
@Inject(method = "af_$onUpgradesChanged", at = @At("TAIL"), remap = false, require = 0)
|
||||||
|
private void eap$onAppfluxUpgradesChanged(CallbackInfo ci) {
|
||||||
|
try {
|
||||||
|
if (UpgradeSlotCompat.shouldEnableChannelCard()) {
|
||||||
|
com.extendedae_plus.util.ExtendedAELogger.LOGGER.info("监听到appflux升级变化,处理频道卡");
|
||||||
|
// 升级变更,重置并尝试初始化频道卡
|
||||||
|
eap$compatLastChannel = -1;
|
||||||
|
eap$compatHasInitialized = false;
|
||||||
|
eap$compatInitializeChannelLink();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
com.extendedae_plus.util.ExtendedAELogger.LOGGER.error("监听appflux升级变化失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Inject(method = "<init>(Lappeng/api/networking/IManagedGridNode;Lappeng/helpers/patternprovider/PatternProviderLogicHost;I)V",
|
@Inject(method = "<init>(Lappeng/api/networking/IManagedGridNode;Lappeng/helpers/patternprovider/PatternProviderLogicHost;I)V",
|
||||||
at = @At("TAIL"))
|
at = @At("TAIL"))
|
||||||
private void eap$compatInitUpgrades(IManagedGridNode mainNode, PatternProviderLogicHost host, int patternInventorySize, CallbackInfo ci) {
|
private void eap$compatInitUpgrades(IManagedGridNode mainNode, PatternProviderLogicHost host, int patternInventorySize, CallbackInfo ci) {
|
||||||
try {
|
try {
|
||||||
if (UpgradeSlotCompat.shouldEnableUpgradeSlots()) {
|
com.extendedae_plus.util.ExtendedAELogger.LOGGER.info("兼容性PatternProviderLogic初始化被调用");
|
||||||
|
|
||||||
|
boolean upgradeSlots = UpgradeSlotCompat.shouldEnableUpgradeSlots();
|
||||||
|
boolean channelCard = UpgradeSlotCompat.shouldEnableChannelCard();
|
||||||
|
|
||||||
|
com.extendedae_plus.util.ExtendedAELogger.LOGGER.info("升级槽功能: {}, 频道卡功能: {}", upgradeSlots, channelCard);
|
||||||
|
|
||||||
|
if (upgradeSlots) {
|
||||||
|
// 只有在升级槽功能启用时才创建升级槽
|
||||||
this.eap$compatUpgrades = UpgradeInventories.forMachine(
|
this.eap$compatUpgrades = UpgradeInventories.forMachine(
|
||||||
host.getTerminalIcon().getItem(),
|
host.getTerminalIcon().getItem(),
|
||||||
1,
|
1,
|
||||||
this::eap$compatOnUpgradesChanged
|
this::eap$compatOnUpgradesChanged
|
||||||
);
|
);
|
||||||
|
com.extendedae_plus.util.ExtendedAELogger.LOGGER.info("创建了完整的升级槽");
|
||||||
|
} else if (channelCard) {
|
||||||
|
// 如果装了appflux,我们不创建自己的升级槽,而是监听appflux的升级槽
|
||||||
|
com.extendedae_plus.util.ExtendedAELogger.LOGGER.info("装了appflux,将监听其升级槽来处理频道卡");
|
||||||
|
} else {
|
||||||
|
com.extendedae_plus.util.ExtendedAELogger.LOGGER.info("跳过升级槽创建");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
com.extendedae_plus.util.ExtendedAELogger.LOGGER.error("兼容性升级初始化失败", e);
|
com.extendedae_plus.util.ExtendedAELogger.LOGGER.error("兼容性升级初始化失败", e);
|
||||||
|
|
@ -98,7 +128,7 @@ public abstract class PatternProviderLogicCompatMixin implements IUpgradeableObj
|
||||||
@Inject(method = "writeToNBT", at = @At("TAIL"))
|
@Inject(method = "writeToNBT", at = @At("TAIL"))
|
||||||
private void eap$compatSaveUpgrades(CompoundTag tag, CallbackInfo ci) {
|
private void eap$compatSaveUpgrades(CompoundTag tag, CallbackInfo ci) {
|
||||||
try {
|
try {
|
||||||
if (UpgradeSlotCompat.shouldEnableUpgradeSlots()) {
|
if (UpgradeSlotCompat.shouldEnableUpgradeSlots() || UpgradeSlotCompat.shouldEnableChannelCard()) {
|
||||||
this.eap$compatUpgrades.writeToNBT(tag, "compat_upgrades");
|
this.eap$compatUpgrades.writeToNBT(tag, "compat_upgrades");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
@ -109,12 +139,14 @@ public abstract class PatternProviderLogicCompatMixin implements IUpgradeableObj
|
||||||
@Inject(method = "readFromNBT", at = @At("TAIL"))
|
@Inject(method = "readFromNBT", at = @At("TAIL"))
|
||||||
private void eap$compatLoadUpgrades(CompoundTag tag, CallbackInfo ci) {
|
private void eap$compatLoadUpgrades(CompoundTag tag, CallbackInfo ci) {
|
||||||
try {
|
try {
|
||||||
if (UpgradeSlotCompat.shouldEnableUpgradeSlots()) {
|
if (UpgradeSlotCompat.shouldEnableUpgradeSlots() || UpgradeSlotCompat.shouldEnableChannelCard()) {
|
||||||
this.eap$compatUpgrades.readFromNBT(tag, "compat_upgrades");
|
this.eap$compatUpgrades.readFromNBT(tag, "compat_upgrades");
|
||||||
// 从 NBT 加载后,重置并尝试初始化
|
// 从 NBT 加载后,重置并尝试初始化频道卡
|
||||||
eap$compatLastChannel = -1;
|
if (UpgradeSlotCompat.shouldEnableChannelCard()) {
|
||||||
eap$compatHasInitialized = false;
|
eap$compatLastChannel = -1;
|
||||||
eap$compatInitializeChannelLink();
|
eap$compatHasInitialized = false;
|
||||||
|
eap$compatInitializeChannelLink();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
com.extendedae_plus.util.ExtendedAELogger.LOGGER.error("兼容性升级加载失败", e);
|
com.extendedae_plus.util.ExtendedAELogger.LOGGER.error("兼容性升级加载失败", e);
|
||||||
|
|
@ -124,7 +156,7 @@ public abstract class PatternProviderLogicCompatMixin implements IUpgradeableObj
|
||||||
@Inject(method = "addDrops", at = @At("TAIL"))
|
@Inject(method = "addDrops", at = @At("TAIL"))
|
||||||
private void eap$compatDropUpgrades(List<ItemStack> drops, CallbackInfo ci) {
|
private void eap$compatDropUpgrades(List<ItemStack> drops, CallbackInfo ci) {
|
||||||
try {
|
try {
|
||||||
if (UpgradeSlotCompat.shouldEnableUpgradeSlots()) {
|
if (UpgradeSlotCompat.shouldEnableUpgradeSlots() || UpgradeSlotCompat.shouldEnableChannelCard()) {
|
||||||
for (var stack : this.eap$compatUpgrades) {
|
for (var stack : this.eap$compatUpgrades) {
|
||||||
if (!stack.isEmpty()) {
|
if (!stack.isEmpty()) {
|
||||||
drops.add(stack);
|
drops.add(stack);
|
||||||
|
|
@ -139,7 +171,7 @@ public abstract class PatternProviderLogicCompatMixin implements IUpgradeableObj
|
||||||
@Inject(method = "clearContent", at = @At("TAIL"))
|
@Inject(method = "clearContent", at = @At("TAIL"))
|
||||||
private void eap$compatClearUpgrades(CallbackInfo ci) {
|
private void eap$compatClearUpgrades(CallbackInfo ci) {
|
||||||
try {
|
try {
|
||||||
if (UpgradeSlotCompat.shouldEnableUpgradeSlots()) {
|
if (UpgradeSlotCompat.shouldEnableUpgradeSlots() || UpgradeSlotCompat.shouldEnableChannelCard()) {
|
||||||
this.eap$compatUpgrades.clear();
|
this.eap$compatUpgrades.clear();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
@ -150,14 +182,19 @@ public abstract class PatternProviderLogicCompatMixin implements IUpgradeableObj
|
||||||
@Override
|
@Override
|
||||||
public IUpgradeInventory getUpgrades() {
|
public IUpgradeInventory getUpgrades() {
|
||||||
if (UpgradeSlotCompat.shouldEnableUpgradeSlots()) {
|
if (UpgradeSlotCompat.shouldEnableUpgradeSlots()) {
|
||||||
return this.eap$compatUpgrades;
|
// 不装appflux时,返回我们自己的升级槽
|
||||||
|
return this.eap$compatUpgrades != null ? this.eap$compatUpgrades : UpgradeInventories.empty();
|
||||||
|
} else {
|
||||||
|
// 装了appflux时,这个方法不应该被调用,因为appflux的Mixin会覆盖它
|
||||||
|
// 但是为了安全起见,返回空的升级槽
|
||||||
|
com.extendedae_plus.util.ExtendedAELogger.LOGGER.debug("装了appflux时getUpgrades被调用,这不应该发生");
|
||||||
|
return UpgradeInventories.empty();
|
||||||
}
|
}
|
||||||
return UpgradeInventories.empty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void eap$updateWirelessLink() {
|
public void eap$updateWirelessLink() {
|
||||||
if (!UpgradeSlotCompat.shouldEnableUpgradeSlots()) {
|
if (!UpgradeSlotCompat.shouldEnableChannelCard()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -172,7 +209,7 @@ public abstract class PatternProviderLogicCompatMixin implements IUpgradeableObj
|
||||||
|
|
||||||
@Unique
|
@Unique
|
||||||
public void eap$compatInitializeChannelLink() {
|
public void eap$compatInitializeChannelLink() {
|
||||||
if (!UpgradeSlotCompat.shouldEnableUpgradeSlots()) {
|
if (!UpgradeSlotCompat.shouldEnableChannelCard()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -200,11 +237,33 @@ public abstract class PatternProviderLogicCompatMixin implements IUpgradeableObj
|
||||||
|
|
||||||
long channel = 0L;
|
long channel = 0L;
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (ItemStack stack : this.eap$compatUpgrades) {
|
|
||||||
if (!stack.isEmpty() && stack.getItem() == ModItems.CHANNEL_CARD.get()) {
|
// 获取升级槽 - 如果装了appflux则从appflux获取,否则从我们自己的获取
|
||||||
channel = ChannelCardItem.getChannel(stack);
|
IUpgradeInventory upgrades = null;
|
||||||
found = true;
|
if (UpgradeSlotCompat.shouldEnableUpgradeSlots()) {
|
||||||
break;
|
// 不装appflux时使用我们自己的升级槽
|
||||||
|
upgrades = this.eap$compatUpgrades;
|
||||||
|
} else if (UpgradeSlotCompat.shouldEnableChannelCard()) {
|
||||||
|
// 装了appflux时,尝试从PatternProviderLogic获取升级槽
|
||||||
|
try {
|
||||||
|
if (this instanceof IUpgradeableObject) {
|
||||||
|
IUpgradeableObject upgradeableThis = (IUpgradeableObject) this;
|
||||||
|
upgrades = upgradeableThis.getUpgrades();
|
||||||
|
com.extendedae_plus.util.ExtendedAELogger.LOGGER.debug("从appflux获取到升级槽: {}", upgrades != null);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
com.extendedae_plus.util.ExtendedAELogger.LOGGER.error("获取appflux升级槽失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (upgrades != null) {
|
||||||
|
for (ItemStack stack : upgrades) {
|
||||||
|
if (!stack.isEmpty() && stack.getItem() == ModItems.CHANNEL_CARD.get()) {
|
||||||
|
channel = ChannelCardItem.getChannel(stack);
|
||||||
|
found = true;
|
||||||
|
com.extendedae_plus.util.ExtendedAELogger.LOGGER.info("找到频道卡,频道: {}", channel);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -244,14 +303,14 @@ public abstract class PatternProviderLogicCompatMixin implements IUpgradeableObj
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void eap$setClientWirelessState(boolean connected) {
|
public void eap$setClientWirelessState(boolean connected) {
|
||||||
if (UpgradeSlotCompat.shouldEnableUpgradeSlots()) {
|
if (UpgradeSlotCompat.shouldEnableChannelCard()) {
|
||||||
eap$compatClientConnected = connected;
|
eap$compatClientConnected = connected;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean eap$isWirelessConnected() {
|
public boolean eap$isWirelessConnected() {
|
||||||
if (!UpgradeSlotCompat.shouldEnableUpgradeSlots()) {
|
if (!UpgradeSlotCompat.shouldEnableChannelCard()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -269,7 +328,7 @@ public abstract class PatternProviderLogicCompatMixin implements IUpgradeableObj
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean eap$hasTickInitialized() {
|
public boolean eap$hasTickInitialized() {
|
||||||
if (UpgradeSlotCompat.shouldEnableUpgradeSlots()) {
|
if (UpgradeSlotCompat.shouldEnableChannelCard()) {
|
||||||
return eap$compatHasInitialized;
|
return eap$compatHasInitialized;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -277,14 +336,14 @@ public abstract class PatternProviderLogicCompatMixin implements IUpgradeableObj
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void eap$setTickInitialized(boolean initialized) {
|
public void eap$setTickInitialized(boolean initialized) {
|
||||||
if (UpgradeSlotCompat.shouldEnableUpgradeSlots()) {
|
if (UpgradeSlotCompat.shouldEnableChannelCard()) {
|
||||||
eap$compatHasInitialized = initialized;
|
eap$compatHasInitialized = initialized;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void eap$handleDelayedInit() {
|
public void eap$handleDelayedInit() {
|
||||||
if (!UpgradeSlotCompat.shouldEnableUpgradeSlots()) {
|
if (!UpgradeSlotCompat.shouldEnableChannelCard()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -317,7 +376,7 @@ public abstract class PatternProviderLogicCompatMixin implements IUpgradeableObj
|
||||||
|
|
||||||
@Inject(method = "onMainNodeStateChanged", at = @At("TAIL"))
|
@Inject(method = "onMainNodeStateChanged", at = @At("TAIL"))
|
||||||
private void eap$compatOnMainNodeStateChangedTail(CallbackInfo ci) {
|
private void eap$compatOnMainNodeStateChangedTail(CallbackInfo ci) {
|
||||||
if (!UpgradeSlotCompat.shouldEnableUpgradeSlots()) {
|
if (!UpgradeSlotCompat.shouldEnableChannelCard()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ public interface PatternProviderLogicHostCompatMixin extends IUpgradeableObject
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default IUpgradeInventory getUpgrades() {
|
default IUpgradeInventory getUpgrades() {
|
||||||
if (!UpgradeSlotCompat.shouldEnableUpgradeSlots()) {
|
if (!UpgradeSlotCompat.shouldEnableUpgradeSlots() && !UpgradeSlotCompat.shouldEnableChannelCard()) {
|
||||||
return UpgradeInventories.empty();
|
return UpgradeInventories.empty();
|
||||||
}
|
}
|
||||||
return ((IUpgradeableObject) this.getLogic()).getUpgrades();
|
return ((IUpgradeableObject) this.getLogic()).getUpgrades();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user