GregTechCEu Modern

GregTechCEu Modern

6M Downloads

KubeJS giving ambiguous constructor error when creating a material/element

rodrigoasfr24022003 opened this issue ยท 4 comments

commented

Checked for existing issues

  • I have checked for existing issues, and have found none.

Tested latest version

  • I have checked that this occurs on the latest version.

GregTech CEu Version

1.4.4

Minecraft Version

1.21.1

Recipe Viewer Installed

JEI

Environment

Singleplayer

Cross-Mod Interaction

Yes

Other Installed Mods

architectury-13.0.6-neoforge.jar
hyperions-3.36.32-neoforge-1.21.1.jar (private mod, provbably not the cause)
primetals-4.6.2-neoforge-1.21.1.jar (private mod, provbably not the cause)
rodrigonia_dim-0.10.41-neoforge-1.21.1.har (private mod, probably not the cause)
jei-1.21.1-neoforge-19.21.0.244.jar
kubejs-neoforge-2101.7.0-build.171.jar
rhino-2101.2.5-build.54.jar

Expected Behavior

KubeJS creating the Rodrigonium material and Rodrigonium element from the attached code for a KubeJS script:

GTCEuStartupEvents.registry('gtceu:element', event => {
    event.create('rodrigonium', 150, 270, -1, null, 'Rod', false)
})

GTCEuStartupEvents.registry('gtceu:material', event => {
    event.create('rodrigonium')
        .ingot(5)
        .components('1x rodrigonium')
        .color(0x003153).iconSet(GTMaterialIconSet.METALLIC)
        .flags(GTMaterialFlags.GENERATE_PLATE, GTMaterialFlags.GENERATE_GEAR, GTMaterialFlags.GENERATE_SMALL_GEAR)
})

Actual Behavior

KubeJS gives an "ambiguous constructor" error for both the element and the material: startup.log, preventing Minecraft from loading with the following KubeJS script:

GTCEuStartupEvents.registry('gtceu:element', event => {
    event.create('rodrigonium', 150, 270, -1, null, 'Rod', false)
})

GTCEuStartupEvents.registry('gtceu:material', event => {
    event.create('rodrigonium')
        .ingot(5)
        .components('1x rodrigonium')
        .color(0x003153).iconSet(GTMaterialIconSet.METALLIC)
        .flags(GTMaterialFlags.GENERATE_PLATE, GTMaterialFlags.GENERATE_GEAR, GTMaterialFlags.GENERATE_SMALL_GEAR)
})

Steps to Reproduce

  1. Go to <Your MC Folder>\.kubejs\startup_scripts;
  2. Create a Javascipt file there;
  3. Paste the following code in the file and save it:
GTCEuStartupEvents.registry('gtceu:element', event => {
    event.create('rodrigonium', 150, 270, -1, null, 'Rod', false)
})

GTCEuStartupEvents.registry('gtceu:material', event => {
    event.create('rodrigonium')
        .ingot(5)
        .components('1x rodrigonium')
        .color(0x003153).iconSet(GTMaterialIconSet.METALLIC)
        .flags(GTMaterialFlags.GENERATE_PLATE, GTMaterialFlags.GENERATE_GEAR, GTMaterialFlags.GENERATE_SMALL_GEAR)
})
  1. Start Minecraft;
  2. It should give an error on load.

Additional Information

The launcher I'm using is MultiMC 0.7.0-3863: link to Launcher (This launcher requires a MS acc to load Minecraft, but supports multiple instances)
3 of the mods are personal use mods, I hope the problem isn't with those.
If this needs to be reported on KubeJS's github instead, tell me.
Image with the error

Thanks for your attention,
Rodrigo

commented

I saw that you're calling .components() for a material that's supposed to be representative of an element. It is required in this case that you call .element() instead, passing your custom Element in with GTElements.get(). This will resolve the error on line 12, but of course only if the error on line 4 is resolved first.
Edit: Try enclosing all the parameters you pass into the element builder except your element ID with square brackets, like so:
event.create('rodrigonium', [150, 270, -1, null, 'Rod', false])
It has come to my attention that KubeJS and Rhino better recognize a varargs parameter (the event.create() method for the element registry takes a ResourceLocation, which KubeJS can parse from a JS string, and an Object... varargs, which contains the rest of the element's registry information, as its only two parameters) if its contents are enclosed in such square brackets, so it may help KubeJS better parse your custom element definition.

commented

@AncientShotgun
Ok so the error on line 12 is solved and I am very grateful for your help.
The error on line 4 still stays:
startup.log

Many thanks,
Rodrigo

commented

OK, at least progress has been made!
Try disambiguating the method call, like so:
event["create(java.lang.String,java.lang.Object[])"]('rodrigonium', [150, 270, -1, null, 'Rod', false]).
This, in theory, should tell the Rhino engine which of the three available methods to use. In this case, we are trying the one that takes a String (your element's id) and an Object[] (which contains the rest of your element's properties).

Please also be aware that there is no full stop between event and ["create()"]() in this notation, as there would be in a regular method call:

  • event.create() is the regular call's notation
  • event["create(java.lang.String,java.lang.Object[])"]() is the disambiguated call's notation

I have made that error personally an embarrassing number of times due to muscle memory and would like to warn you of it in advance.

commented

Disambiguating the method call worked.
No error on line 4.

Many thanks,
Rodrigo