-
Notifications
You must be signed in to change notification settings - Fork 354
Recipe Fail Reason Display #4487
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
Changes from all commits
c751d7b
667947a
cee5381
1a4ab22
babd825
6c5bee0
2375103
f11721d
935f61a
1af017c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ | |
| import com.gregtechceu.gtceu.api.recipe.content.ContentModifier; | ||
| import com.gregtechceu.gtceu.api.recipe.ingredient.EnergyStack; | ||
|
|
||
| import net.minecraft.network.chat.Component; | ||
|
|
||
| import lombok.Setter; | ||
| import lombok.experimental.Accessors; | ||
| import org.jetbrains.annotations.Contract; | ||
|
|
@@ -35,6 +37,7 @@ | |
| @FunctionalInterface | ||
| public interface ModifierFunction { | ||
|
|
||
| // TODO: Add reasons for any NULL ModifierFunction (replace them with cancel) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this finished within this codebase?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not yet. There are still multiple usages of ModifierFunction.NULL in the codebase. Some of them were not replaced because I am not sure about reasons. I have only replaced the more common cases where the fail reason is explicit. |
||
| /** | ||
| * Use this static to denote that the recipe should be cancelled | ||
| */ | ||
|
|
@@ -44,6 +47,21 @@ public interface ModifierFunction { | |
| */ | ||
| ModifierFunction IDENTITY = ModifierFunction.builder().build(); | ||
|
|
||
| static ModifierFunction cancel(Component reason) { | ||
| return new ModifierFunction() { | ||
|
|
||
| @Override | ||
| public @Nullable GTRecipe apply(@NotNull GTRecipe recipe) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public Component getFailReason() { | ||
| return reason; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Applies this modifier to the passed recipe | ||
| * | ||
|
|
@@ -79,6 +97,12 @@ private GTRecipe applySafe(@Nullable GTRecipe recipe) { | |
| return apply(recipe); | ||
| } | ||
|
|
||
| static final Component DEFAULT_FAILURE = Component.translatable("gtceu.recipe_modifier.default_fail"); | ||
|
|
||
| default Component getFailReason() { | ||
| return DEFAULT_FAILURE; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a FunctionBuilder to easily build a ModifierFunction that modifies parts of a recipe. | ||
| * <p> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.