FiguraMC / Figura

Extensively customize your character with Figura!
https://modrinth.com/mod/figura
GNU Lesser General Public License v2.1
225 stars 44 forks source link

Ability to clear require() function's cache #243

Open AceKiron opened 1 month ago

AceKiron commented 1 month ago

Request Description

Currently I have to manually reload my avatar (go into third person, hold R, then select Reload Avatar) in order to fix an issue caused by the fact the require() function is cached.

Could we get a feature that either clears the function's cache, disables its cache altogether, or a second require() function that doesn't cache?

KitCat962 commented 1 month ago

Instead of bugging the devs to impliment a feature that bypasses your script issues, why not just fix your script so it works?

KitCat962 commented 1 month ago

What I mean is, require is behaving as require is expected to behave. There are currently no known issues with require that causes this issue. It is highly likely that instead of require being at fault, your script is at fault. Would you be willing to share your avatar so that we can figure out whether it is a require issue or a skill script issue?

AceKiron commented 1 month ago

About a week ago I made a simplified version of my avatar public (https://github.com/AceKiron/A). It logs _Mx_Ace: Reloading avatar, NOT on server if I'm not playing on a specific server, and _Mx_Ace: Reloading avatar, on server if I am. I'd expect a message to print out every time I join a server (that specific one, or any other one) or a singleplayer world. Instead it only prints out once.

KitCat962 commented 1 month ago

I downloaded your avatar and cannot reproduce your issue. So long as the avatar is uploaded, it will always print something.

What exactly do you mean by require caching? I assumed that you meant that when require loads a script, it will retain the value and give the same value for each subsequent call of require in the same avatar instance. However, your script only has one instance of require. require's cache is always cleared when an avatar is reloaded, uploaded, whatever.

I have a feeling that you think that require caches the result between avatar reloads, which is incorrect. All avatars would break if that was the case.

If you still believe that figura is at fault for this, please provide video proof of just figura with no other mods and state the figura version and minecraft version. I need to see you uploading your test avatar in single player, exiting to menu, going back to the single player world. Then exit and join the server, waiting for your avatar to load. You will need to remove the mod check and use a different server for testing, as this test requires just figura.

Below is me doing just that, using my own ip as a test and removing the mod check. The only change made is line 1 of plugins/sample/index.lua, where I've changed the line to local playingOnTheServer = client:getServerData().ip == "IP", where IP is the ip address of my private server.

https://github.com/user-attachments/assets/19fd422b-0efe-4fe0-8998-85a00444e41e

PoolloverNathan commented 1 month ago

Clearing the require cache wouldn't do anything anyway; all of the files it can load are already stored in a NBT blob that doesn't get modified after the avatar loads.

AceKiron commented 1 month ago

I downloaded your avatar and cannot reproduce your issue. So long as the avatar is uploaded, it will always print something.

That's.. unexpected. That avatar didn't work on my PC at home.

What exactly do you mean by require caching? I assumed that you meant that when require loads a script, it will retain the value and give the same value for each subsequent call of require in the same avatar instance. However, your script only has one instance of require. require's cache is always cleared when an avatar is reloaded, uploaded, whatever.

I have a feeling that you think that require caches the result between avatar reloads, which is incorrect. All avatars would break if that was the case.

A lack of my avatar being reloaded is what's the problem here.

If you still believe that figura is at fault for this, please provide video proof of just figura with no other mods and state the figura version and minecraft version. I need to see you uploading your test avatar in single player, exiting to menu, going back to the single player world. Then exit and join the server, waiting for your avatar to load. You will need to remove the mod check and use a different server for testing, as this test requires just figura.

I'll do that once I come back home.

AceKiron commented 1 month ago

If you still believe that figura is at fault for this, please provide video proof of just figura with no other mods and state the figura version and minecraft version. I need to see you uploading your test avatar in single player, exiting to menu, going back to the single player world. Then exit and join the server, waiting for your avatar to load. You will need to remove the mod check and use a different server for testing, as this test requires just figura.

I'm using Minecraft/FabricMC version fabric-loader-0.15.6-1.20.4, and Figura version figura-0.1.4+1.20.4-fabric-mc. Other than that I don't have any mods installed currently.

The plugins\sample\index.lua:1 line was changed to local playingOnTheServer = client:getServerData().ip == "localhost" for the purpose of this video.

The video was too big for me to upload on GitHub, so I uploaded it to YouTube instead: https://youtu.be/WS04fxiT5Ws.

GrandpaScout commented 1 month ago

It appears that init happens too early in 1.20.4. It also throws when trying to convert the string "minecraft:barrier" to an item as if it didn't exist.

Testing shows that the script does in fact run over the print statement but just doesn't print anything because Minecraft (probably) has nowhere to print it to.

After more testing, I have no idea why the print isn't working. As far as I can tell, Figura should print the message as soon as it is available to. Yet it doesn't.

KitCat962 commented 1 month ago

Found the issue. 1.20.4 is not reloading the player at all between world loads. I think vanilla is doing some "optimizations" by keeping the Player entity in memory instead of creating a new instance. Figura only triggers the reload when a new instance is created.

Below video showcases this issue. Top left os 1.20.1, bottom right is 1.20.4. Expected behavior is when exiting to menu and rejoining the world, the player is reinitialized. This is showcased by the other minecraft instance uploading a different avatar. However, when 1.20.4 exits and rejoins the world, the avatar persists through the world transfer. Initialization scripts are not executed. Major bug plz fix

https://github.com/user-attachments/assets/e5bfb903-a148-40ac-928d-c36c5a92c210

KitCat962 commented 1 month ago

Can someone else figure out which versions of minecraft this occurs on? 1.20.1 has expected results, 1.20.4 does not. Still need to check 1.20.6 and 1.21

the following avatar was used to check: printinit.zip

Riftlight commented 1 month ago

Can someone else figure out which versions of minecraft this occurs on? 1.20.1 has expected results, 1.20.4 does not. Still need to check 1.20.6 and 1.21

Reproduced on 1.21 (same bug as you experienced in 1.20.4). i lack a 1.20.6 instance but its probably safe to assume its a bug on 1.20.4+