-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamically generate temporary crafting patterns for however many EMC…
…-able items have been requested (involves some hijacking of the auto-crafting system)
- Loading branch information
Showing
7 changed files
with
256 additions
and
12 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
52 changes: 52 additions & 0 deletions
52
src/main/java/gripe/_90/appliede/mixin/crafting/CraftConfirmMenuMixin.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 gripe._90.appliede.mixin.crafting; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
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 net.minecraft.world.entity.player.Player; | ||
|
||
import appeng.api.networking.IGrid; | ||
import appeng.api.networking.crafting.ICraftingPlan; | ||
import appeng.api.stacks.AEItemKey; | ||
import appeng.menu.me.crafting.CraftConfirmMenu; | ||
|
||
import gripe._90.appliede.me.service.KnowledgeService; | ||
import gripe._90.appliede.me.service.TransmutationPattern; | ||
|
||
@Mixin(value = CraftConfirmMenu.class, remap = false) | ||
public abstract class CraftConfirmMenuMixin { | ||
@Shadow | ||
private ICraftingPlan result; | ||
|
||
@Unique | ||
private boolean appliede$submitted = false; | ||
|
||
@Shadow | ||
protected abstract IGrid getGrid(); | ||
|
||
// spotless:off | ||
@Inject( | ||
method = "startJob", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lappeng/menu/me/crafting/CraftConfirmMenu;setAutoStart(Z)V")) | ||
// spotless:on | ||
private void setSubmitted(CallbackInfo ci) { | ||
appliede$submitted = true; | ||
} | ||
|
||
@Inject(method = "removed", at = @At("TAIL"), remap = true) | ||
private void clearTemporaryPatterns(Player player, CallbackInfo ci) { | ||
if (getGrid() != null && result != null && !appliede$submitted) { | ||
for (var pattern : result.patternTimes().keySet()) { | ||
if (pattern instanceof TransmutationPattern && pattern.getOutputs()[0].what() instanceof AEItemKey) { | ||
getGrid().getService(KnowledgeService.class).removeTemporaryPattern(pattern); | ||
} | ||
} | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/gripe/_90/appliede/mixin/crafting/CraftingCPULogicMixin.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,71 @@ | ||
package gripe._90.appliede.mixin.crafting; | ||
|
||
import java.util.Iterator; | ||
import java.util.Map; | ||
|
||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
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; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
|
||
import net.minecraft.world.level.Level; | ||
|
||
import appeng.api.crafting.IPatternDetails; | ||
import appeng.api.networking.energy.IEnergyService; | ||
import appeng.api.stacks.AEItemKey; | ||
import appeng.crafting.execution.CraftingCpuLogic; | ||
import appeng.crafting.execution.ExecutingCraftingJob; | ||
import appeng.me.cluster.implementations.CraftingCPUCluster; | ||
import appeng.me.service.CraftingService; | ||
|
||
import gripe._90.appliede.me.service.KnowledgeService; | ||
import gripe._90.appliede.me.service.TransmutationPattern; | ||
|
||
@Mixin(value = CraftingCpuLogic.class, remap = false) | ||
public abstract class CraftingCPULogicMixin { | ||
@Shadow | ||
@Final | ||
CraftingCPUCluster cluster; | ||
|
||
@Inject( | ||
method = "executeCrafting", | ||
at = @At(value = "INVOKE", target = "Ljava/util/Iterator;remove()V"), | ||
locals = LocalCapture.CAPTURE_FAILEXCEPTION) | ||
private void removeOnFinishStep( | ||
int maxPatterns, | ||
CraftingService craftingService, | ||
IEnergyService energyService, | ||
Level level, | ||
CallbackInfoReturnable<Integer> cir, | ||
ExecutingCraftingJob job, | ||
int pushedPatterns, | ||
Iterator<?> it, | ||
Map.Entry<IPatternDetails, ?> task) { | ||
appliede$removeTemporaryPattern(task.getKey()); | ||
} | ||
|
||
@Inject( | ||
method = "finishJob", | ||
at = @At(value = "INVOKE", target = "Ljava/util/Map$Entry;getKey()Ljava/lang/Object;"), | ||
locals = LocalCapture.CAPTURE_FAILEXCEPTION) | ||
private void removeOnCancel( | ||
boolean success, CallbackInfo ci, Iterator<?> iter, Map.Entry<IPatternDetails, ?> entry) { | ||
appliede$removeTemporaryPattern(entry.getKey()); | ||
} | ||
|
||
@Unique | ||
private void appliede$removeTemporaryPattern(IPatternDetails pattern) { | ||
if (pattern instanceof TransmutationPattern && pattern.getOutputs()[0].what() instanceof AEItemKey) { | ||
var grid = cluster.getGrid(); | ||
|
||
if (grid != null) { | ||
grid.getService(KnowledgeService.class).removeTemporaryPattern(pattern); | ||
} | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/gripe/_90/appliede/mixin/crafting/CraftingTreeNodeMixin.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,68 @@ | ||
package gripe._90.appliede.mixin.crafting; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
|
||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
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.LocalCapture; | ||
|
||
import appeng.api.crafting.IPatternDetails; | ||
import appeng.api.networking.IGridNode; | ||
import appeng.api.networking.crafting.ICraftingService; | ||
import appeng.api.stacks.AEItemKey; | ||
import appeng.api.stacks.KeyCounter; | ||
import appeng.crafting.CraftingCalculation; | ||
import appeng.crafting.CraftingTreeNode; | ||
import appeng.crafting.CraftingTreeProcess; | ||
import appeng.crafting.inv.CraftingSimulationState; | ||
|
||
import gripe._90.appliede.me.service.KnowledgeService; | ||
import gripe._90.appliede.me.service.TransmutationPattern; | ||
|
||
@Mixin(value = CraftingTreeNode.class, remap = false) | ||
public abstract class CraftingTreeNodeMixin { | ||
@Shadow | ||
private ArrayList<CraftingTreeProcess> nodes; | ||
|
||
@Shadow | ||
@Final | ||
private CraftingCalculation job; | ||
|
||
@Unique | ||
private long appliede$requestedAmount; | ||
|
||
@Inject(method = "request", at = @At("HEAD")) | ||
private void trackRequested( | ||
CraftingSimulationState inv, long requestedAmount, KeyCounter containerItems, CallbackInfo ci) { | ||
appliede$requestedAmount = requestedAmount; | ||
} | ||
|
||
// spotless:off | ||
@Inject( | ||
method = "buildChildPatterns", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Ljava/util/ArrayList;add(Ljava/lang/Object;)Z"), | ||
locals = LocalCapture.CAPTURE_FAILEXCEPTION, | ||
cancellable = true) | ||
// spotless:on | ||
private void recalculatePattern( | ||
CallbackInfo ci, | ||
IGridNode gridNode, | ||
ICraftingService craftingService, | ||
Iterator<IPatternDetails> iterator, | ||
IPatternDetails details) { | ||
if (details instanceof TransmutationPattern && details.getOutputs()[0].what() instanceof AEItemKey item) { | ||
ci.cancel(); | ||
var newPattern = new TransmutationPattern(item, appliede$requestedAmount); | ||
gridNode.getGrid().getService(KnowledgeService.class).addTemporaryPattern(newPattern); | ||
nodes.add(new CraftingTreeProcess(craftingService, job, newPattern, (CraftingTreeNode) (Object) this)); | ||
} | ||
} | ||
} |
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