friendlyhj / ZenUtils

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

Cannot use `mods.zenutils.StaticString.join` to join string array #30

Closed Krutoy242 closed 10 months ago

Krutoy242 commented 10 months ago

Seems like mods.zenutils.StaticString.join should work with any types of CraftTweaker arrays, but it cant work with string[]

Both this lines erroring:

print(mods.zenutils.StaticString.join(['a','b'], ','));
print(mods.zenutils.StaticString.join(['a','b'] as string[], ','));

Error in crafttweaker.log:

12 methods available but none matches the parameters (string[], string)
This is usually an error in your script, not in the mod
join(short[], string)
join(float[], string)
join(double[], string)
join(int[], string)
join(long[], string)
join(ZenTypeNative: java.lang.Object[], string)
join(float[], string, int, int)
join(ZenTypeNative: java.lang.Object[], string, int, int)
join(int[], string, int, int)
join(long[], string, int, int)
join(short[], string, int, int)
join(double[], string, int, int)
Krutoy242 commented 10 months ago

I dont know Java well, but considering latest commit, maybe this function should be changed too? https://github.com/friendlyhj/ZenUtils/blob/ac9e64a86ff2cc98d9996c3825e9983bd5da8dbb/src/main/java/youyihj/zenutils/api/util/StaticString.java#L735-L738

friendlyhj commented 10 months ago

This method is no problem. The issue is string[] is not Object[], ZS needs to cast string[] to another array, but there is other methods that accept int[] float[]. string[] can be cast to these array type, too. So ZS doesn't know which array type to cast to, and use which method then.

Krutoy242 commented 10 months ago

Is that means i cant use startIndex and endIndex for joining string[] array at all?

This zs code have error too:

print(mods.zenutils.StaticString.join(['a','b'] as string[], ',', 0, 1));
12 methods available but none matches the parameters (string[], string, int, int)
friendlyhj commented 10 months ago

Oh, there also is conflicted method that accept int[], string, int, int. Is this problem urgent? If not, I'm going to fix it in next update.

Krutoy242 commented 10 months ago

No, its not urgent. I will use my own implementation of join 😀 https://github.com/Krutoy242/Craft.zs/blob/885c0ee8e0029fa3b8303242d0d468c393d4161e/serialize.zs#L34-L43