Skip to content

Conversation

@TechLord22
Copy link
Member

What

Moves CraftingComponent to a dedicated API class, and adds a type-safe builder method to create them.

The explicit builder methods restrict the potential ways to represent a crafting ingredient, preventing use of the more esoteric ones allowed in crafting recipes. This paves the way to expand CraftingComponent's use to more than just crafting in the future.

Implementation Details

The only significant behavioral change is that the fallback value is now handled slightly differently. Additionally, specifying a Block without meta now defaults to the wildcard metadata value instead of 0. This aligns better with the expectation that a block without a specific variant specified should accept any variant.

Outcome

Improves CraftingComponent code quality and API.

@TechLord22 TechLord22 requested a review from a team as a code owner May 20, 2025 05:19
@TechLord22 TechLord22 added the type: refactor Suggestion to refactor a section of code label May 20, 2025
Comment on lines 260 to 273
ASSEMBLER_RECIPES.recipeBuilder().duration(80).EUt(VA[HV])
.inputs(MetaItems.COVER_SCREEN.getStackForm())
.inputs((ItemStack) CraftingComponent.HULL.getIngredient(1))
.inputs((ItemStack) CraftingComponents.HULL.getIngredient(1))
.input(wireFine, AnnealedCopper, 8)
.fluidInputs(Polyethylene.getFluid(L))
.outputs(MetaTileEntities.MONITOR_SCREEN.getStackForm())
.buildAndRegister();

ASSEMBLER_RECIPES.recipeBuilder().duration(100).EUt(VA[HV])
.inputs(MetaItems.COVER_SCREEN.getStackForm())
.inputs((ItemStack) CraftingComponent.HULL.getIngredient(3))
.inputs((ItemStack) CraftingComponents.HULL.getIngredient(3))
.input(circuit, MarkerMaterials.Tier.HV, 2)
.fluidInputs(Polyethylene.getFluid(L))
.outputs(MetaTileEntities.CENTRAL_MONITOR.getStackForm())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the 1 and 3 here for getIngredient() use LV and HV instead?

* @param tier the tier of the ingredient
* @return the raw ingredient, which may be either an {@link ItemStack} or {@link String}
*/
public @Nullable Object getIngredient(int tier) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a getItemStack(int tier) method to directly get the tier's item stack so there's no need to cast this method? A getString(int tier) would be good too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: refactor Suggestion to refactor a section of code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants