Skip to content

Commit

Permalink
Rework JEI Ctrl+Click cancel logic... again
Browse files Browse the repository at this point in the history
  • Loading branch information
NotMyWing committed May 16, 2024
1 parent 58239b2 commit 09e2b83
Showing 1 changed file with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.me.cache.CraftingGridCache;
import appeng.me.cluster.implementations.CraftingCPUCluster;
import co.neeve.nae2.common.helpers.VirtualPatternDetails;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -19,9 +20,6 @@

@Mixin(value = CraftingCPUCluster.class, remap = false)
public abstract class MixinCraftingCPUCluster {
@Shadow
private IItemList<IAEItemStack> waitingFor;

@SuppressWarnings("rawtypes")
@Shadow
@Final
Expand All @@ -39,16 +37,27 @@ public abstract class MixinCraftingCPUCluster {
@Inject(method = "executeCrafting", at = @At(
value = "INVOKE",
target = "Lappeng/me/cluster/implementations/CraftingCPUCluster;canCraft" +
"(Lappeng/api/networking/crafting/ICraftingPatternDetails;[Lappeng/api/storage/data/IAEItemStack;)Z"
"(Lappeng/api/networking/crafting/ICraftingPatternDetails;[Lappeng/api/storage/data/IAEItemStack;)Z",
shift = At.Shift.AFTER
), cancellable = true)
public void executeCrafting(IEnergyGrid eg, CraftingGridCache cc, CallbackInfo ci,
@Local ICraftingPatternDetails details) {
if (details instanceof VirtualPatternDetails) {
if (this.tasks.size() <= 1 && this.waitingFor.isEmpty()) {
this.completeJob();
this.cancel();
ci.cancel();
}
@Local ICraftingPatternDetails details,
@Share(value = "canCraft") LocalBooleanRef canCraftRef) {
if (details instanceof VirtualPatternDetails && canCraftRef != null && canCraftRef.get()) {
this.completeJob();
this.cancel();
ci.cancel();
}
}

@ModifyExpressionValue(method = "executeCrafting", at = @At(
value = "INVOKE",
target = "Lappeng/me/cluster/implementations/CraftingCPUCluster;canCraft" +
"(Lappeng/api/networking/crafting/ICraftingPatternDetails;[Lappeng/api/storage/data/IAEItemStack;)Z"
))
public boolean canCraft(boolean canCraft, @Share(value = "canCraft") LocalBooleanRef canCraftRef) {
canCraftRef.set(canCraft);

return canCraft;
}
}

0 comments on commit 09e2b83

Please sign in to comment.