-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
349 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/cn/taskeren/op/mixin/late/AdditionalAE_UpgradeInventory_Mixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cn.taskeren.op.mixin.late; | ||
|
||
import appeng.api.config.Upgrades; | ||
import appeng.parts.automation.UpgradeInventory; | ||
import cn.taskeren.op.ae.OP_AEUpgrades; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
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; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(value = UpgradeInventory.class, remap = false) | ||
public abstract class AdditionalAE_UpgradeInventory_Mixin { | ||
|
||
/* | ||
The additional upgrade items are registered as `OP_GeneratedAEUpgradeItem` and it implements IUpgradeModule, so we don't need to | ||
do extra things in `isItemValidForSlot`. | ||
In this class, we should manually count our custom upgrades and return the right value in the method. | ||
*/ | ||
|
||
@Unique | ||
private int op$programmedUpgrades = 0; | ||
|
||
@Inject(method = "updateUpgradeInfo", at = @At("HEAD")) | ||
private void op$updateUpgradeInfo_cleanse(CallbackInfo ci) { | ||
op$programmedUpgrades = 0; | ||
} | ||
|
||
@Inject(method = "updateUpgradeInfo", at = @At(value = "INVOKE_ASSIGN", target = "Lappeng/api/implementations/items/IUpgradeModule;getType(Lnet/minecraft/item/ItemStack;)Lappeng/api/config/Upgrades;")) | ||
private void op$updateUpgradeInfo_count(CallbackInfo ci, @Local(name = "myUpgrade") Upgrades myUpgrade) { | ||
if(myUpgrade == OP_AEUpgrades.getProgrammedUpgrade()) { | ||
op$programmedUpgrades++; | ||
} | ||
} | ||
|
||
@Inject(method = "getInstalledUpgrades", at = @At("RETURN"), cancellable = true) | ||
private void op$getInstalledUpgrades(Upgrades u, CallbackInfoReturnable<Integer> cir) { | ||
// overwrite | ||
if (u == OP_AEUpgrades.getProgrammedUpgrade()) { | ||
cir.setReturnValue(op$programmedUpgrades); | ||
} | ||
} | ||
|
||
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/cn/taskeren/op/mixin/late/AdditionalAE_Upgrades_Mixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package cn.taskeren.op.mixin.late; | ||
|
||
import appeng.api.config.Upgrades; | ||
import org.spongepowered.asm.mixin.*; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
@Mixin(value = Upgrades.class, remap = false) | ||
@Unique | ||
public abstract class AdditionalAE_Upgrades_Mixin { | ||
|
||
/* | ||
Added an extra instance to `Upgrades` enum. | ||
This tricky method is from https://github.com/SpongePowered/Mixin/issues/387#issuecomment-888408556 | ||
But there is a potential bug that in the runtime the new created instance is added to the $VALUES twice, and | ||
I cannot find the reason it is added twice. But it works for now, so I assume it affect nothing. | ||
You should get the instance from `OP_AEUpgrades`. | ||
*/ | ||
|
||
@Shadow | ||
@Final | ||
@Mutable | ||
private static Upgrades[] $VALUES; | ||
|
||
private static final Upgrades PROGRAMMED = op$createInstance("PROGRAMMED", 1); | ||
|
||
@Invoker("<init>") | ||
public static Upgrades op$constructor(String name, int ordinal, int tier) { | ||
throw new AssertionError(); | ||
} | ||
|
||
private static Upgrades op$createInstance(String name, int tier) { | ||
// get existing instances | ||
ArrayList<Upgrades> values = new ArrayList<>(Arrays.asList($VALUES)); | ||
// create the new instance | ||
Upgrades value = op$constructor(name, values.get(values.size() - 1).ordinal() + 1, tier); | ||
// add the new instance to the instance cache list | ||
values.add(value); | ||
// overwrite the $VALUES to the value list with the new instance | ||
$VALUES = values.toArray(new Upgrades[0]); | ||
// return the new instance | ||
return value; | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/cn/taskeren/op/mixin/late/GTApi_GregTech_API_Mixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package cn.taskeren.op.mixin.late; | ||
|
||
import com.google.common.collect.Multimap; | ||
import gregtech.api.GregTech_API; | ||
import net.minecraft.item.ItemStack; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(value = GregTech_API.class, remap = false) | ||
public interface GTApi_GregTech_API_Mixin { | ||
|
||
@Accessor("sRealConfigurationList") | ||
static Multimap<Integer, ItemStack> getRealConfigurationList() { | ||
throw new AssertionError(); | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/cn/taskeren/op/mixin/late/ProInterface_DualityInterface_Mixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package cn.taskeren.op.mixin.late; | ||
|
||
import appeng.api.config.Upgrades; | ||
import appeng.api.networking.crafting.ICraftingPatternDetails; | ||
import appeng.helpers.DualityInterface; | ||
import cn.taskeren.op.ae.OP_AEUpgrades; | ||
import cn.taskeren.op.gt.utils.GTApi; | ||
import codechicken.lib.inventory.InventoryUtils; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import gregtech.api.interfaces.IConfigurationCircuitSupport; | ||
import gregtech.api.metatileentity.BaseMetaTileEntity; | ||
import gregtech.api.util.GT_Utility; | ||
import net.minecraft.inventory.IInventory; | ||
import net.minecraft.inventory.InventoryCrafting; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.tileentity.TileEntity; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
@Mixin(value = DualityInterface.class, remap = false) | ||
public abstract class ProInterface_DualityInterface_Mixin { | ||
|
||
@Shadow | ||
private List<ItemStack> waitingToSend; | ||
|
||
@Shadow | ||
public abstract IInventory getStorage(); | ||
|
||
@Shadow | ||
public abstract int getInstalledUpgrades(Upgrades u); | ||
|
||
@Inject(method = "pushPattern", at = @At(value = "INVOKE", target = "Lappeng/helpers/DualityInterface;pushItemsOut(Ljava/util/EnumSet;)Z", ordinal = 0)) | ||
private void op$pushItemsOut(ICraftingPatternDetails patternDetails, InventoryCrafting table, CallbackInfoReturnable<Boolean> cir, @Local(name = "te") TileEntity tile) { | ||
if(getInstalledUpgrades(OP_AEUpgrades.getProgrammedUpgrade()) < 1) { // requires the upgrade installed | ||
return; | ||
} | ||
|
||
if(tile instanceof BaseMetaTileEntity) { | ||
BaseMetaTileEntity bmte = (BaseMetaTileEntity) tile; | ||
IConfigurationCircuitSupport circuitSupport = bmte.getConfigurationCircuitSupport(); | ||
if(circuitSupport != null) { | ||
// get the first circuit stack in the items that will be inserted to the machine | ||
Optional<ItemStack> circuitStackOptional = waitingToSend.stream() | ||
.filter(Objects::nonNull) | ||
.filter(GTApi.INSTANCE::isConfigurationCircuit).findFirst(); | ||
|
||
circuitStackOptional.ifPresent(circuitStack -> { | ||
if (circuitSupport.getConfigurationCircuits().stream().anyMatch(allowedStack -> GT_Utility.areStacksEqual(allowedStack, circuitStack))) { | ||
// set the circuit slot to the circuit stack | ||
int circuitSlot = circuitSupport.getCircuitSlot(); | ||
bmte.getMetaTileEntity().setInventorySlotContents(circuitSlot, circuitStack.copy()); | ||
// remove the circuit stack from items that will be inserted to the machine | ||
waitingToSend.remove(circuitStack); | ||
// and return the circuit stack to the interface storage | ||
InventoryUtils.insertItem(getStorage(), circuitStack, false); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/cn/taskeren/op/utils/MixinAccessorBridge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cn.taskeren.op.utils; | ||
|
||
import cn.taskeren.op.mixin.late.GTApi_GregTech_API_Mixin; | ||
import com.google.common.collect.Multimap; | ||
import net.minecraft.item.ItemStack; | ||
|
||
/** | ||
* This class is a bridge that used to access {@link org.spongepowered.asm.mixin.gen.Accessor}s in Kotlin while not throwing {@link IncompatibleClassChangeError}. | ||
*/ | ||
public class MixinAccessorBridge { | ||
|
||
/** | ||
* @return gregtech.api.GregTech_API#sRealConfigurationList | ||
*/ | ||
public static Multimap<Integer, ItemStack> getRealConfigurationList() { | ||
return GTApi_GregTech_API_Mixin.getRealConfigurationList(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cn.taskeren.op.ae | ||
|
||
import appeng.api.AEApi | ||
import appeng.api.config.Upgrades | ||
import cn.taskeren.op.OP_Logger | ||
import com.glodblock.github.loader.ItemAndBlockHolder as AE2FCItemAndBlockHolder | ||
|
||
/** | ||
* @see cn.taskeren.op.mixin.late.AdditionalAE_Upgrades_Mixin | ||
*/ | ||
object OP_AEUpgrades : OP_Logger { | ||
|
||
/** | ||
* @return the instance of Programmed Upgrade, or `null` if the mixin is failed or AE2 is not available. | ||
*/ | ||
@JvmStatic | ||
val programmedUpgrade: Upgrades? by lazy { runCatching { Upgrades.valueOf("PROGRAMMED") }.getOrNull() } | ||
|
||
/** | ||
* @return the available OP additional upgrades. | ||
*/ | ||
@JvmStatic | ||
val upgrades: List<Upgrades> by lazy { listOf(programmedUpgrade).filterNotNull() } | ||
|
||
fun init() { | ||
val aeApi = AEApi.instance() | ||
|
||
// add upgrades to the allowlist of the ae2 parts and blocks | ||
if(programmedUpgrade != null) { | ||
logger.info("Programmed Upgrade is found!") | ||
// ae2 | ||
programmedUpgrade?.registerItem(aeApi.definitions().parts().iface(), 1) | ||
programmedUpgrade?.registerItem(aeApi.definitions().blocks().iface(), 1) | ||
// ae2fc | ||
programmedUpgrade?.registerItem(AE2FCItemAndBlockHolder.FLUID_INTERFACE.stack(), 1) | ||
programmedUpgrade?.registerItem(AE2FCItemAndBlockHolder.INTERFACE.stack(), 1) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.