friendlyhj / ZenUtils

https://www.curseforge.com/minecraft/mc-mods/zenutil
MIT License
19 stars 8 forks source link

getPlayerBaubleItemHandler() should somehow not lead to total script failure when baubles isnt present #36

Closed Shibva closed 7 months ago

Shibva commented 8 months ago

bit of a niche issue but the only way I can describe this issue is to relate it to my current delema.

in my custom script I am using something that dosent nessisary rely on baubles as a requirement nor do Intend on it being a requirement; however, a specific error utilizing getPlayerBaubleItemHandler() breaks the entiery of my script using it.

this may seem redundant; though I can assure that this is a problem as even if I were to have it kept in some sort of if condition it still outright breaks from its meer presence image image ^ atempt to not use it; failed lel

my suggestion here is to somehow still keep this line as a viable method but instead have it return as null or something; allowing for a simple !isNull() check to be done to prevent that part of the code being used and have it be used without baubles as a dependency

friendlyhj commented 8 months ago

You can wrap this function In your event scripts (events.zs for example)

static baubleItemHandlerFactory as function(IPlayer)ItemHandler = null;

// events.onXXX...
if (!isNull(baubleItemHandlerFactory)) {
    val babel = baubleItemHandlerFactory(event.player);
}

And a script only loaded when bauble is loaded.


#modloaded baubles
scripts.events.baubleItemHandlerFactory = function(player as IPlayer) as ItemHandler {
    return player.getPlayerBaubleItemHandler();
};