From 35b5475e5a3f9160e82e94dff1bfb7387c30fe9c Mon Sep 17 00:00:00 2001 From: redbirdly <155550833+redbirdly@users.noreply.github.com> Date: Sat, 8 Jun 2024 08:56:42 +0800 Subject: [PATCH] Update fast_lightmap.js --- mods/fast_lightmap.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mods/fast_lightmap.js b/mods/fast_lightmap.js index 58cd9553..f572cb1d 100644 --- a/mods/fast_lightmap.js +++ b/mods/fast_lightmap.js @@ -266,8 +266,19 @@ elements.plasma.tick = function(pixel) { }; // Wait for loading -// if it loads too soon then width will be undefined -setTimeout(() => { initializeLightmap(width, height); }, 700); +let i = 0; +let interval = setInterval(() => { + if (typeof width !== 'undefined') { + clearInterval(interval); + initializeLightmap(width, height); + } + i += 1; + // if width is not defined for 3 seconds or longer, it's probably broken, so it will just try run the function anyways to see the error + if (i >= 30) { + clearInterval(interval); + initializeLightmap(width, height); + } +}, 100); // Add code to functions instead of replacing them let originalTick = tick;