KubeJS

KubeJS

61M Downloads

`VariantBlockStateGenerator`'s `variant` method overloads should be called different things

nok-ko opened this issue ยท 0 comments

commented

Describe the feature

I propose renaming the variant(String,String) method in VariantBlockStateGenerator.

Additional info

Consider a user who wants to add the following BlockState definition to their custom block:

{
    "variants": { "": [
        {
            "model": "kubejs:block/example_block",
        },
        {
            "model": "kubejs:block/example_block",
            "y": 90
        },
        {
            "model": "kubejs:block/example_block",
            "y": 180
        },
        {
            "model": "kubejs:block/example_block",
            "y": 270
        }
    ]}
}

(Akin to the vanilla grass block's rotation variants.)

They may reasonably expect the following code snippet to work:

ClientEvents.highPriorityAssets(event => {
	event.addBlockState("kubejs:example_block", generator => {
		generator.variant("", variant => {
				variant.model("kubejs:block/example_block");
				variant.model("kubejs:block/example_block").y(90);
				variant.model("kubejs:block/example_block").y(180);
				variant.model("kubejs:block/example_block").y(270);
			}
		);
	})
}

However, this produces the following error:

[Worker-Main-25/WARN] [minecraft/ModelBakery]: Exception loading blockstate definition: 'kubejs:blockstates/example_block.json' missing model for variant: 'kubejs:example_block#'
[Worker-Main-25/WARN] [minecraft/ModelBakery]: Exception loading blockstate definition: 'kubejs:blockstates/example_block.json' in resourcepack: 'KubeJS Resource Pack [assets]': Non [a-z0-9/._-] character in path of location: minecraft:ArrowFunction (1) => {...}

This is because the supplied function is converted to a string. The runtime tries to call VariantBlockStateGenerator#variant(String,String), not the (clearly-intended) VariantBlockStateGenerator#variant(String,Consumer<Variant>). Instead the proper call is:

ClientEvents.highPriorityAssets(event => {
	event.addBlockState("kubejs:example_block", generator => {
		generator["variant(java.lang.String,java.util.function.Consumer)"]("",
			variant => {
				variant.model("kubejs:block/example_block").y(0);
				variant.model("kubejs:block/example_block").y(90);
				variant.model("kubejs:block/example_block").y(180);
				variant.model("kubejs:block/example_block").y(270);
			}
		);
	})
})

The above snippet works as expected.

The simple solution is just to rename one of the methods so that JS callers don't have to disambiguate the overload.