Skip to content

Commit 454a624

Browse files
committed
对递归判断进行一些修正,呃
现在应当可以在完全没有原材料的情况下发起合成
1 parent 3a01dd3 commit 454a624

File tree

4 files changed

+67
-13
lines changed

4 files changed

+67
-13
lines changed

src/main/java/com/circulation/random_complement/common/interfaces/RCCraftingJob.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@
55
public interface RCCraftingJob {
66

77
IAEItemStack getWaitingItem();
8+
9+
boolean isSpecialDeficiency();
10+
11+
void setSpecialDeficiency(boolean b);
812
}

src/main/java/com/circulation/random_complement/mixin/ae2/AccessorCraftingTreeNode.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,13 @@
1010
public interface AccessorCraftingTreeNode {
1111
@Accessor
1212
IItemList<IAEItemStack> getUsed();
13+
14+
@Accessor
15+
long getHowManyEmitted();
16+
17+
@Accessor
18+
void setHowManyEmitted(long howManyEmitted);
19+
20+
@Accessor
21+
boolean isCanEmit();
1322
}

src/main/java/com/circulation/random_complement/mixin/ae2/miss_craft/MixinCraftingJob.java

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import appeng.api.networking.crafting.ICraftingGrid;
44
import appeng.api.storage.data.IAEItemStack;
5-
import appeng.crafting.CraftBranchFailure;
65
import appeng.crafting.CraftingJob;
76
import appeng.crafting.CraftingTreeNode;
87
import appeng.crafting.MECraftingInventory;
@@ -53,30 +52,42 @@ public void record(MECraftingInventory instance, IAEItemStack what, Operation<Vo
5352
original.call(instance, what);
5453
}
5554

55+
@Unique
56+
private boolean r$specialDeficiency;
57+
58+
@Intrinsic
59+
public IAEItemStack getWaitingItem() {
60+
return r$wait;
61+
}
62+
5663
@Inject(method = "run", at = @At(value = "INVOKE", target = "Lappeng/crafting/CraftingTreeNode;request(Lappeng/crafting/MECraftingInventory;JLappeng/api/networking/security/IActionSource;)Lappeng/api/storage/data/IAEItemStack;", shift = At.Shift.AFTER, ordinal = 0))
57-
public void supplementaryOutput(CallbackInfo ci, @Share("rcOutput") LocalLongRef stackLocalRef) throws CraftBranchFailure {
64+
public void supplementaryOutput(CallbackInfo ci, @Share("rcOutput") LocalLongRef stackLocalRef) {
65+
var tree = (AccessorCraftingTreeNode) this.tree;
66+
if (tree.isCanEmit()) return;
5867
final long out = stackLocalRef.get();
5968
if (out > 0) {
6069
for (var details : this.cc.getCraftingFor(this.output, null, 0, this.world)) {
70+
IAEItemStack repeatInput = this.output.copy().setStackSize(0);
71+
for (var input : details.getCondensedInputs()) {
72+
if (this.output.equals(input)) {
73+
repeatInput.incStackSize(input.getStackSize());
74+
}
75+
}
76+
if (repeatInput.getStackSize() == 0) return;
77+
6178
IAEItemStack repeatOutput = this.output.copy().setStackSize(0);
6279
for (var input : details.getCondensedOutputs()) {
6380
if (this.output.equals(input)) {
64-
repeatOutput.setStackSize(repeatOutput.getStackSize() + input.getStackSize());
81+
repeatOutput.incStackSize(input.getStackSize());
6582
}
6683
}
6784
if (repeatOutput.getStackSize() == 0) return;
6885

6986
long outputQuantity = this.output.getStackSize() / repeatOutput.getStackSize();
7087
if (this.output.getStackSize() % repeatOutput.getStackSize() != 0) ++outputQuantity;
88+
repeatInput.setStackSize(repeatInput.getStackSize() * outputQuantity);
7189

72-
IAEItemStack repeatInput = this.output.copy().setStackSize(0);
73-
for (var input : details.getCondensedInputs()) {
74-
if (this.output.equals(input)) {
75-
repeatInput.setStackSize(repeatInput.getStackSize() + (input.getStackSize() * outputQuantity));
76-
}
77-
}
7890
if (repeatInput.getStackSize() > 0) {
79-
var tree = (AccessorCraftingTreeNode) this.tree;
8091
var size = Math.min(out, repeatInput.getStackSize());
8192
tree.getUsed().add(this.output.copy().setStackSize(size));
8293
r$wait = this.output.copy().setStackSize(repeatInput.getStackSize() - size);
@@ -85,17 +96,41 @@ public void supplementaryOutput(CallbackInfo ci, @Share("rcOutput") LocalLongRef
8596
}
8697
} else {
8798
for (var details : this.cc.getCraftingFor(this.output, null, 0, this.world)) {
99+
IAEItemStack repeatInput = this.output.copy().setStackSize(0);
88100
for (var input : details.getCondensedInputs()) {
89101
if (this.output.equals(input)) {
90-
throw new CraftBranchFailure(this.output, this.output.getStackSize());
102+
repeatInput.incStackSize(input.getStackSize());
91103
}
92104
}
105+
final var inputSize = repeatInput.getStackSize();
106+
if (inputSize == 0) return;
107+
108+
IAEItemStack repeatOutput = this.output.copy().setStackSize(0);
109+
for (var input : details.getCondensedOutputs()) {
110+
if (this.output.equals(input)) {
111+
repeatOutput.incStackSize(input.getStackSize());
112+
}
113+
}
114+
if (repeatOutput.getStackSize() == 0) return;
115+
116+
long outputQuantity = this.output.getStackSize() / repeatOutput.getStackSize();
117+
if (this.output.getStackSize() % repeatOutput.getStackSize() != 0) ++outputQuantity;
118+
repeatInput.setStackSize(repeatInput.getStackSize() * outputQuantity + inputSize);
119+
120+
tree.setHowManyEmitted(inputSize);
121+
r$wait = this.output.copy().setStackSize(repeatInput.getStackSize());
122+
setSpecialDeficiency(true);
93123
}
94124
}
95125
}
96126

97127
@Intrinsic
98-
public IAEItemStack getWaitingItem() {
99-
return r$wait;
128+
public boolean isSpecialDeficiency() {
129+
return r$specialDeficiency;
130+
}
131+
132+
@Intrinsic
133+
public void setSpecialDeficiency(boolean b) {
134+
r$specialDeficiency = b;
100135
}
101136
}

src/main/java/com/circulation/random_complement/mixin/ae2/miss_craft/MixinCraftingTreeNode.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import appeng.crafting.MECraftingInventory;
1010
import appeng.util.Platform;
1111
import appeng.util.item.AEItemStack;
12+
import com.circulation.random_complement.common.interfaces.RCCraftingJob;
1213
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
1314
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
1415
import net.minecraft.item.ItemStack;
@@ -71,6 +72,8 @@ public void request(MECraftingInventory inv, long l, IActionSource src, Callback
7172
@WrapOperation(method = "setJob", at = @At(value = "FIELD", opcode = Opcodes.GETFIELD, target = "Lappeng/crafting/CraftingTreeNode;howManyEmitted:J"))
7273
public long setJobHowManyEmitted(CraftingTreeNode instance, Operation<Long> original) {
7374
if (canEmit) return original.call(instance);
75+
if (this.parent == null && ((RCCraftingJob) job).isSpecialDeficiency())
76+
return original.call(instance);
7477
if (this.what.equals(this.job.getOutput())) return 0;
7578
if (this.nodes.isEmpty()) return original.call(instance);
7679
return 0;
@@ -79,13 +82,16 @@ public long setJobHowManyEmitted(CraftingTreeNode instance, Operation<Long> orig
7982
@WrapOperation(method = "getPlan", at = @At(value = "FIELD", opcode = Opcodes.GETFIELD, target = "Lappeng/crafting/CraftingTreeNode;missing:J"))
8083
public long getPlanMissing(CraftingTreeNode instance, Operation<Long> original) {
8184
if (canEmit) return original.call(instance);
85+
if (this.parent == null && ((RCCraftingJob) job).isSpecialDeficiency()) return howManyEmitted;
8286
if (this.what.equals(this.job.getOutput())) return original.call(instance);
8387
return this.howManyEmitted;
8488
}
8589

8690
@WrapOperation(method = "getPlan", at = @At(value = "FIELD", opcode = Opcodes.GETFIELD, target = "Lappeng/crafting/CraftingTreeNode;howManyEmitted:J"))
8791
public long getPlanHowManyEmitted(CraftingTreeNode instance, Operation<Long> original) {
8892
if (canEmit) return original.call(instance);
93+
if (this.parent == null && ((RCCraftingJob) job).isSpecialDeficiency())
94+
return original.call(instance);
8995
if (this.what.equals(this.job.getOutput())) return 0;
9096
if (this.nodes.isEmpty()) return original.call(instance);
9197
return 0;

0 commit comments

Comments
 (0)