font_renderer.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. var transformerName = "Font Renderer Transformer";
  2. var ASMAPI = Java.type('net.minecraftforge.coremod.api.ASMAPI');
  3. var Opcodes = Java.type('org.objectweb.asm.Opcodes');
  4. var MethodInsnNode = Java.type("org.objectweb.asm.tree.MethodInsnNode");
  5. var FieldInsnNode = Java.type("org.objectweb.asm.tree.FieldInsnNode");
  6. function initializeCoreMod() {
  7. return {
  8. transformerName: {
  9. 'target': {
  10. 'type': 'CLASS',
  11. 'name': 'net.minecraft.client.gui.FontRenderer'
  12. },
  13. 'transformer': function (classNode) {
  14. var methods = classNode.methods;
  15. var targetMethodName = ASMAPI.mapMethod("func_228081_c_"); // renderStringAtPos
  16. var targetMethodDesc = "(Ljava/lang/String;FFIZLnet/minecraft/client/renderer/Matrix4f;Lnet/minecraft/client/renderer/IRenderTypeBuffer;ZII)F";
  17. for (var i in methods)
  18. {
  19. var method = methods[i];
  20. if (method.name.equals(targetMethodName) && method.desc.equals(targetMethodDesc))
  21. {
  22. print(method.name + " " + method.desc);
  23. transform(method);
  24. break;
  25. }
  26. }
  27. return classNode;
  28. }
  29. }
  30. };
  31. }
  32. function transform(method)
  33. {
  34. var instrList = method.instructions;
  35. for (var i = 0; i < instrList.size(); ++i) {
  36. var instr = instrList.get(i);
  37. if(instr instanceof MethodInsnNode && instr.owner.equals("net/minecraft/util/text/TextFormatting"))
  38. {
  39. instrList.remove(instr);
  40. instrList.insert(instrList.get(i - 1), new MethodInsnNode(instr.getOpcode(), "me/ktcm/ModTextFormatting",
  41. ASMAPI.mapMethod(instr.name), instr.desc.replace("net/minecraft/util/text/TextFormatting", "me/ktcm/ModTextFormatting"), false));
  42. }
  43. else if(instr instanceof FieldInsnNode && instr.owner.equals("net/minecraft/util/text/TextFormatting"))
  44. {
  45. instrList.remove(instr);
  46. instrList.insert(instrList.get(i - 1), new FieldInsnNode(instr.getOpcode(), "me/ktcm/ModTextFormatting",
  47. ASMAPI.mapField(instr.name), instr.desc.replace("net/minecraft/util/text/TextFormatting", "me/ktcm/ModTextFormatting")));
  48. }
  49. }
  50. }