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

[bug] Creating Custom Biome Modifiers: example code throws error #227

Closed
Bittorn opened this issue Feb 10, 2025 · 1 comment · Fixed by #228
Closed

[bug] Creating Custom Biome Modifiers: example code throws error #227

Bittorn opened this issue Feb 10, 2025 · 1 comment · Fixed by #228
Labels
incorrect Fixes incorrect information.

Comments

@Bittorn
Copy link
Contributor

Bittorn commented Feb 10, 2025

For the record, I am using NeoForge 21.1.82 for MC 1.21.1 for my project, but I have tested in the latest 21.4.88-beta and it throws the same error.

The relevant code:

RecordCodecBuilder.mapCodec(instance -> instance.group(
                        Biome.LIST_CODEC.fieldOf("biomes").forGetter(ExampleBiomeModifier::biomes),
                        Codec.INT.fieldOf("value").forGetter(ExampleBiomeModifier::value)
                ).apply(instance, ExampleBiomeModifier::new)

Throws this error:

      Required type                                                  Provided
t1: App<Mu<BiomeModifier>, T1>                     RecordCodecBuilder<ExampleBiomeModifier,HolderSet<Biome>>
t2: App<Mu<BiomeModifier>, T2>                     RecordCodecBuilder<ExampleBiomeModifier,Integer>
reason: no instance(s) of type variable(s) exist so that BiomeModifier conforms to ExampleBiomeModifier

I'm pretty new to Minecraft modding so this may be my issue, but I have copied the example code exactly and even tried modifying it to fix it myself and yet no luck. This might be a holdover from NeoForge 1.20 or maybe even older Forge implementation.

@Bittorn Bittorn changed the title Creating Custom Biome Modifiers: example code throws error [bug] Creating Custom Biome Modifiers: example code throws error Feb 10, 2025
@ChampionAsh5357
Copy link
Contributor

ChampionAsh5357 commented Feb 10, 2025

So, this is not an issue with the codec itself, but rather with the ambiguous generic being set. This can be fixed by holding an instance of Supplier<ExampleBiomeModifier> instead of the holder for the constant. The docs should probably be updated to use suppliers or the deferred holder objects by default, leaving holders only when absolutely necessary.

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

Successfully merging a pull request may close this issue.

2 participants