This repository has been archived by the owner on Jul 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure custom ROM is copied in crafting
Fixes: - Turtle upgrades - Pocket upgrades (modems and custom) - Normal to advanced upgrade Also fixes upgraded pocket computers being craftable with a modem
- Loading branch information
Showing
8 changed files
with
133 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.squiddev.cctweaks.core.asm; | ||
|
||
import dan200.computercraft.shared.pocket.recipes.PocketComputerUpgradeRecipe; | ||
import dan200.computercraft.shared.turtle.recipes.TurtleUpgradeRecipe; | ||
import org.objectweb.asm.ClassVisitor; | ||
import org.objectweb.asm.MethodVisitor; | ||
import org.objectweb.asm.tree.InsnList; | ||
import org.objectweb.asm.tree.InsnNode; | ||
import org.objectweb.asm.tree.MethodInsnNode; | ||
import org.squiddev.patcher.transformer.IPatcher; | ||
import org.squiddev.patcher.visitors.FindingVisitor; | ||
|
||
import static org.objectweb.asm.Opcodes.*; | ||
|
||
/** | ||
* Modifies {@link TurtleUpgradeRecipe} and {@link PocketComputerUpgradeRecipe} to set the ROM id. | ||
*/ | ||
public class CopyRom implements IPatcher { | ||
@Override | ||
public boolean matches(String className) { | ||
return className.equals("dan200.computercraft.shared.turtle.recipes.TurtleUpgradeRecipe") | ||
|| className.equals("dan200.computercraft.shared.pocket.recipes.PocketComputerUpgradeRecipe"); | ||
} | ||
|
||
@Override | ||
public ClassVisitor patch(String className, ClassVisitor delegate) throws Exception { | ||
if (className.endsWith("TurtleUpgradeRecipe")) { | ||
return new FindingVisitor( | ||
delegate, | ||
new MethodInsnNode(INVOKESTATIC, "dan200/computercraft/shared/turtle/items/TurtleItemFactory", "create", "(ILjava/lang/String;Ldan200/computercraft/shared/util/Colour;Ldan200/computercraft/shared/computer/core/ComputerFamily;Ldan200/computercraft/api/turtle/ITurtleUpgrade;Ldan200/computercraft/api/turtle/ITurtleUpgrade;ILnet/minecraft/util/ResourceLocation;)Lnet/minecraft/item/ItemStack;", false), | ||
new InsnNode(ARETURN) | ||
) { | ||
@Override | ||
public void handle(InsnList nodes, MethodVisitor visitor) { | ||
nodes.getFirst().accept(visitor); | ||
visitor.visitVarInsn(ALOAD, 3); | ||
visitor.visitMethodInsn(INVOKESTATIC, "org/squiddev/cctweaks/core/rom/CraftingSetRom", "copyRom", "(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;", false); | ||
visitor.visitInsn(ARETURN); | ||
} | ||
}.onMethod("func_77572_b").onMethod("getCraftingResult").mustFind().once(); | ||
} else { | ||
return new FindingVisitor( | ||
delegate, | ||
new MethodInsnNode(INVOKESTATIC, "dan200/computercraft/shared/pocket/items/PocketComputerItemFactory", "create", "(ILjava/lang/String;Ldan200/computercraft/shared/computer/core/ComputerFamily;Z)Lnet/minecraft/item/ItemStack;", false), | ||
new InsnNode(ARETURN) | ||
) { | ||
@Override | ||
public void handle(InsnList nodes, MethodVisitor visitor) { | ||
nodes.getFirst().accept(visitor); | ||
visitor.visitVarInsn(ALOAD, 2); | ||
visitor.visitMethodInsn(INVOKESTATIC, "org/squiddev/cctweaks/core/rom/CraftingSetRom", "copyRom", "(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;", false); | ||
visitor.visitInsn(ARETURN); | ||
} | ||
}.onMethod("func_77572_b").onMethod("getCraftingResult").mustFind().once(); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/org/squiddev/cctweaks/core/asm/PreventModemUpgrade.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,46 @@ | ||
package org.squiddev.cctweaks.core.asm; | ||
|
||
import org.objectweb.asm.ClassVisitor; | ||
import org.objectweb.asm.Label; | ||
import org.objectweb.asm.MethodVisitor; | ||
import org.objectweb.asm.tree.InsnList; | ||
import org.objectweb.asm.tree.JumpInsnNode; | ||
import org.objectweb.asm.tree.MethodInsnNode; | ||
import org.squiddev.patcher.transformer.IPatcher; | ||
import org.squiddev.patcher.visitors.FindingVisitor; | ||
|
||
import static org.objectweb.asm.Opcodes.*; | ||
|
||
/** | ||
* Prevents {@link dan200.computercraft.shared.pocket.recipes.PocketComputerUpgradeRecipe} from working when there is a | ||
* custom upgrade. | ||
*/ | ||
public class PreventModemUpgrade implements IPatcher { | ||
@Override | ||
public boolean matches(String className) { | ||
return className.equals("dan200.computercraft.shared.pocket.recipes.PocketComputerUpgradeRecipe"); | ||
} | ||
|
||
@Override | ||
public ClassVisitor patch(String className, ClassVisitor delegate) throws Exception { | ||
return new FindingVisitor(delegate, | ||
new MethodInsnNode(INVOKEVIRTUAL, "dan200/computercraft/shared/pocket/items/ItemPocketComputer", "getHasModem", "(Lnet/minecraft/item/ItemStack;)Z", false), | ||
new JumpInsnNode(IFEQ, null) | ||
) { | ||
@Override | ||
public void handle(InsnList nodes, MethodVisitor visitor) { | ||
Label exit = new Label(); | ||
Label cont = ((JumpInsnNode) nodes.get(1)).label.getLabel(); | ||
|
||
visitor.visitMethodInsn(INVOKEVIRTUAL, "dan200/computercraft/shared/pocket/items/ItemPocketComputer", "getHasModem", "(Lnet/minecraft/item/ItemStack;)Z", false); | ||
visitor.visitJumpInsn(IFNE, exit); | ||
|
||
visitor.visitVarInsn(ALOAD, 2); | ||
visitor.visitMethodInsn(INVOKESTATIC, "org/squiddev/cctweaks/core/pocket/PocketHooks", "hasPocketUpgrade", "(Lnet/minecraft/item/ItemStack;)Z", false); | ||
visitor.visitJumpInsn(IFEQ, cont); | ||
|
||
visitor.visitLabel(exit); | ||
} | ||
}; | ||
} | ||
} |
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
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