Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registry DSL does not check types of registered items on compile #70

Open
waterlilly-lilly opened this issue Apr 22, 2023 · 1 comment

Comments

@waterlilly-lilly
Copy link

The Registry DSL does not properly check the type of registry items on compile time. For example, a Block can be registered to the Item registry without a compile time error, only crashing at runtime with a potentially confusing exception.
Test code:

object ExampleMod : ModInitializer {
    val TEST_BLOCK: Block = Block(QuiltBlockSettings.of(Material.STONE)
    override fun onInitialize(mod: ModContainer) {
        Registries.ITEM {
            TEST_BLOCK withId Identifier("example_mod:test_block")
        }
    }
}

This code will compile, but on runtime the game will crash with the error java.lang.IllegalStateException: Some intrusive holders were not registered: [Reference{null=Block{minecraft:air}}], which may be confusing and does not reveal the true cause of the issue.

@Cypher121
Copy link
Contributor

Cypher121 commented Apr 23, 2023

From a cursory look, the issue seems to be that there's a fallback function that matches withId in this example

Registry.invoke call on line 4 of the example creates a RegistryAction<Item> scope and its withId method (this one) will only accept subtypes of item.

Since it doesn't match though, the compiler finds a function that does: this one, one that doesn't require a RegistryAction scope and just makes an object.

So the error here isn't that it's registered into the wrong registry (which would most assuredly give a ClassCast somewhere), it ends up not being registered anywhere.

Would help to add CheckReturnValue to the loose withId, but ideally it should be renamed or moved to a different context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants