From e718d154393b1a201a9dbcdc416aaa54af3402cf Mon Sep 17 00:00:00 2001 From: ZXMushroom63 Date: Wed, 12 Jun 2024 16:01:10 +0800 Subject: [PATCH] Update tracers.js to use new method maps --- ExampleMods/tracers.js | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/ExampleMods/tracers.js b/ExampleMods/tracers.js index aaf72d2..c055c75 100644 --- a/ExampleMods/tracers.js +++ b/ExampleMods/tracers.js @@ -18,6 +18,15 @@ function initTracers() { WorldRenderer: ModAPI.reflect.getClassByName("WorldRenderer") }; + //Build a method map object, to avoid searching for methods multiple times over. + const methodMaps = {}; + var usedClasses = Object.keys(classes); + usedClasses.forEach((className)=>{ + methodMaps[className] = ModAPI.reflect.getMethodMapFromClass(classes[className]); + }); + + console.log(methodMaps); + //Get the vertex format for 'POSITION' const positionVertexFormat = ModAPI.reflect.getClassByName("VertexFormat").class.$platformClass.$$enumConstants$$().data[5]; @@ -43,41 +52,29 @@ function initTracers() { } - //Utility functions for running methods on classes/instances of classes + //Utility functions for running methods on classes/instances of classes by referencing the created methodMaps object. function glFunction(name, args) { - return classes.GlStateManager.methods.filter((method) => { - return method.methodName === name - })[0].exec(args); + return methodMaps["GlStateManager"][name].exec(args); } function gpuFunction(name, args) { - return classes.EaglercraftGPU.methods.filter((method) => { - return method.methodName === name - })[0].exec(args); + return methodMaps["EaglercraftGPU"][name].exec(args); } function entityRendererFunction(name, args) { - return classes.EntityRenderer.methods.filter((method) => { - return method.methodName === name - })[0].exec(args); + return methodMaps["EntityRenderer"][name].exec(args); } function mathHelperFunction(name, args) { - return classes.MathHelper.methods.filter((method) => { - return method.methodName === name - })[0].exec(args); + return methodMaps["MathHelper"][name].exec(args); } function tessellatorFunction(name, args) { - return classes.Tessellator.methods.filter((method) => { - return method.methodName === name - })[0].exec(args); + return methodMaps["Tessellator"][name].exec(args); } function worldRendererFunction(name, args) { - return classes.WorldRenderer.methods.filter((method) => { - return method.methodName === name - })[0].exec(args); + return methodMaps["WorldRenderer"][name].exec(args); }