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

[1.21.1] Processing Recipe Rework #7945

Open
wants to merge 6 commits into
base: mc1.21.1/dev
Choose a base branch
from

Conversation

RaymondBlaze
Copy link

@RaymondBlaze RaymondBlaze commented Mar 14, 2025

Fixes #8048.

Overview

This PR reworked the Processing Recipe system in order to:

  • Better adapt the Codec/StreamCodec based RecipeSerializer system in 1.21.1
  • Remove unavailable recipe id context from ProcessingRecipe and ProcessingRecipeParams, the recipe id is no longer retrievable upon deserialization so recipes should not ask for its own id upon construction.
  • Decouple AllRecipeTypes from ProcessingRecipe so addons can create their own processing recipe types
  • Make ProcessingRecipe generic and ProcessingRecipeParams extensible so ProcessingRecipe with more context (like ItemApplicationRecipe) can be created without having to injecting extra context to the base ProcessingRecipeParams.

Usage

To create a custom ProcessingRecipe with custom ProcessingRecipeParams, take ItemApplicationRecipe as an example:

  1. Create a custom ProcessingRecipeParams class: ItemApplicationRecipeParams, add your own field (boolean keepHeldItem) to it;
  2. Create a MapCodec for the params class by grouping a MapCodec with all fields in ProcessingRecipeParams handled and your own field MapCodecs, the prior can be created from ProcessingRecipeParams.codec(Supplier<P>):
public static MapCodec<ItemApplicationRecipeParams> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
		codec(ItemApplicationRecipeParams::new).forGetter(Function.identity()),
		Codec.BOOL.optionalFieldOf("keep_held_item", false).forGetter(ItemApplicationRecipeParams::keepHeldItem)
	).apply(instance, (params, keepHeldItem) -> {
		params.keepHeldItem = keepHeldItem;
		return params;
	}));
  1. Override the encode and decode methods for network (de)serialization, and create a StreamCodec for the params class using ProcessingRecipeParams.streamCodec(Supplier<P>):
public static StreamCodec<RegistryFriendlyByteBuf, ItemApplicationRecipeParams> STREAM_CODEC = streamCodec(ItemApplicationRecipeParams::new);

	@Override
	protected void encode(RegistryFriendlyByteBuf buffer) {
		super.encode(buffer);
		ByteBufCodecs.BOOL.encode(buffer, keepHeldItem);
	}

	@Override
	protected void decode(RegistryFriendlyByteBuf buffer) {
		super.decode(buffer);
		keepHeldItem = ByteBufCodecs.BOOL.decode(buffer);
	}
  1. Create the recipe's MapCodec and StreamCodec from the params', using MapCodec#xmap and StreamCodec#map, and create your own RecipeSerializer with them.
  2. Create the recipe's builder, extending ProcessingRecipeBuilder, you may optionally specify a generic factory interface for input if you wish to use the params for multiple recipes so they can share the builder class:
@FunctionalInterface
public interface Factory<R extends ItemApplicationRecipe> extends ProcessingRecipe.Factory<ItemApplicationRecipeParams, R> {
	R create(ItemApplicationRecipeParams params);
}

public static class Builder<R extends ItemApplicationRecipe> extends ProcessingRecipeBuilder<ItemApplicationRecipeParams, R, Builder<R>> {
	public Builder(Factory<R> factory, ResourceLocation recipeId) {
		super(factory, recipeId);
	}

	@Override
	protected ItemApplicationRecipeParams createParams() {
		return new ItemApplicationRecipeParams();
	}

	@Override
	public Builder<R> self() {
		return this;
	}

	public Builder<R> toolNotConsumed() {
		params.keepHeldItem = true;
		return this;
	}
}
  1. You may now register the recipe's IRecipeTypeInfo, and use the recipe builder in datagen.

@RaymondBlaze
Copy link
Author

RaymondBlaze commented Mar 19, 2025

Update for JEI integration

  • Implemented fix for [1.21.1] Migrate CreateRecipeCategory to use RecipeHolder as generic type #8048.
  • API-fied CreateRecipeCategory's builder so addons may make use of it.
  • Improved Spout Category's render, the fluid in Spout is now aligned with the current displayed fluid input.
  • Improved Sand Paper Polishing Category's render, the polished item is now aligned with the current displayed input.
  • Added IRecipeSlotsView param to SequencedAssemblySubCategory#draw to allow the Spout subcategory to render the current displayed fluid input in Spout.
  • Added the sequenced index to SequencedAssemblySubCategory#setRecipe to allow setting slot name based on the sequenced index so that the slot can be retrieved by name in SequencedAssemblySubCategory#draw, used to support the Spout subcategory to render the current displayed fluid input in Spout.

@VoidLeech
Copy link
Collaborator

  • API-fied CreateRecipeCategory's builder so addons may make use of it.
  • Improved Spout Category's render, the fluid in Spout is now aligned with the current displayed fluid input.
  • Improved Sand Paper Polishing Category's render, the polished item is now aligned with the current displayed input.
  • Added IRecipeSlotsView param to SequencedAssemblySubCategory#draw to allow the Spout subcategory to render the current displayed fluid input in Spout.
    -Added the sequenced index to SequencedAssemblySubCategory#setRecipe to allow setting slot name based on the sequenced index so that the slot can be retrieved by name in SequencedAssemblySubCategory#draw, used to support the Spout subcategory to render the current displayed fluid input in Spout.

Is there any part of this bit of the PR that would also be applicable to 1.20.1?
For visual improvements, some before/afters would be nice to have. I'm personally not seeing any differences between 6.0.4 and this PR; no shift in sandpaper item or spouting fluid positioning (it's already aligned), nor was the fluid missing from the recipe category's spout; unless of course one of the earlier commits in this PR broke it.

@VoidLeech VoidLeech added area: api Issue or PR is related to API pr type: feature PR adds a new feature or changes an existing feature labels Mar 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: api Issue or PR is related to API pr type: feature PR adds a new feature or changes an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants