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

IngredientType and FluidIngredientType's streamCodec only allow registry codecs #1191

Closed
LatvianModder opened this issue Jun 26, 2024 · 0 comments · Fixed by #1192
Closed
Labels
triage Needs triaging and confirmation

Comments

@LatvianModder
Copy link
Contributor

LatvianModder commented Jun 26, 2024

Minecraft Version: 1.21

NeoForge Version: 21.0.37-beta

Example class:

public record NamespaceIngredient(String namespace) implements ICustomIngredient {
	public static final MapCodec<NamespaceIngredient> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
		Codec.STRING.fieldOf("namespace").forGetter(NamespaceIngredient::namespace)
	).apply(instance, NamespaceIngredient::new));

	public static final StreamCodec<ByteBuf, NamespaceIngredient> STREAM_CODEC = ByteBufCodecs.STRING_UTF8.map(NamespaceIngredient::new, NamespaceIngredient::namespace);

Description of issue:

StreamCodec<ByteBuf, ... should be allowed in constructors of IngredientType and FluidIngredientType, but only specifically StreamCodec<RegistryFriendlyByteBuf is.

Using this

new IngredientType<>(NamespaceIngredient.CODEC, NamespaceIngredient.STREAM_CODEC)

will fail to compile with

The way to fix this is change StreamCodec<RegistryFriendlyByteBuf to StreamCodec<? super RegistryFriendlyByteBuf like most other places in Minecraft for both ingredient types.

Temp fix:

Casting the stream codec to diamond-less (StreamCodec) works. Example:

new IngredientType<>(NamespaceIngredient.CODEC, (StreamCodec) NamespaceIngredient.STREAM_CODEC)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Needs triaging and confirmation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant