Skip to content

Commit

Permalink
fix huge energy drain when doing fluid crafting job
Browse files Browse the repository at this point in the history
  • Loading branch information
GlodBlock committed Aug 10, 2022
1 parent bb52c7b commit 77c3201
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/com/glodblock/github/coremod/CoreModHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ public static IAEItemStack displayAEFluid(IAEItemStack drop) {
else return drop;
}

public static long getFluidSize(IAEItemStack aeStack) {
if (aeStack.getDefinition() != null && !aeStack.getDefinition().isEmpty() && aeStack.getDefinition().getItem() instanceof ItemFluidDrop) {
return (long) Math.max(aeStack.getStackSize() / 1000D, 1);
}
else return aeStack.getStackSize();
}

public static void storeFluidItem(CraftingCPUCluster instance) {
final IGrid g = Ae2Reflect.getGrid(instance);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
private static class TransformExecuteCrafting extends MethodVisitor {

private boolean gotInventory = false;
private int reach_stack = 0;

TransformExecuteCrafting(int api, MethodVisitor mv) {
super(api, mv);
Expand All @@ -60,8 +61,28 @@ public void visitLineNumber(int line, Label start) {
super.visitLineNumber(line, start);
}

@Override
public void visitJumpInsn(int opcode, Label label) {
if (opcode == Opcodes.IFNULL && reach_stack == 0) {
reach_stack = 1;
}
super.visitJumpInsn(opcode, label);
}

@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
if (reach_stack == 1) {
if (opcode == Opcodes.INVOKEINTERFACE
&& owner.equals("appeng/api/storage/data/IAEItemStack") && name.equals("getStackSize")) {
reach_stack = 2;
super.visitMethodInsn(Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/CoreModHooks",
"getFluidSize",
"(Lappeng/api/storage/data/IAEItemStack;)J",
false);
return;
}
}
super.visitMethodInsn(opcode, owner, name, desc, itf);
if (gotInventory) {
if (opcode == Opcodes.INVOKESTATIC
Expand Down

0 comments on commit 77c3201

Please sign in to comment.