-
Notifications
You must be signed in to change notification settings - Fork 0
Fix/single recipe per workbench type #28
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 4 commits
0facd4c
7e8066d
468419c
093ac22
c43b5df
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 |
|---|---|---|
|
|
@@ -11,12 +11,14 @@ | |
| import com.mojang.serialization.MapCodec; | ||
| import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
| import com.tcm.MineTale.recipe.WorkbenchRecipe; | ||
| import com.tcm.MineTale.registry.ModRecipeDisplay; | ||
|
|
||
| import net.minecraft.advancements.Advancement; | ||
| import net.minecraft.advancements.AdvancementRequirements; | ||
| import net.minecraft.advancements.AdvancementRewards; | ||
| import net.minecraft.advancements.Criterion; | ||
| import net.minecraft.advancements.criterion.RecipeUnlockedTrigger; | ||
| import net.minecraft.core.registries.BuiltInRegistries; | ||
| import net.minecraft.core.registries.Registries; | ||
| import net.minecraft.data.recipes.RecipeBuilder; | ||
| import net.minecraft.data.recipes.RecipeOutput; | ||
|
|
@@ -28,6 +30,7 @@ | |
| import net.minecraft.world.item.crafting.CraftingBookCategory; | ||
| import net.minecraft.world.item.crafting.Ingredient; | ||
| import net.minecraft.world.item.crafting.Recipe; | ||
| import net.minecraft.world.item.crafting.RecipeBookCategory; | ||
| import net.minecraft.world.item.crafting.RecipeSerializer; | ||
| import net.minecraft.world.item.crafting.RecipeType; | ||
|
|
||
|
|
@@ -38,6 +41,8 @@ public class WorkbenchRecipeBuilder implements RecipeBuilder { | |
| private final List<ItemStack> results = new ArrayList<>(); | ||
| private final Map<String, Criterion<?>> criteria = new LinkedHashMap<>(); | ||
| private CraftingBookCategory category = CraftingBookCategory.MISC; | ||
| private Identifier bookCategory = BuiltInRegistries.RECIPE_BOOK_CATEGORY | ||
| .getKey(ModRecipeDisplay.CAMPFIRE_SEARCH); | ||
| private int cookTime = 200; | ||
| @Nullable private String group; | ||
|
|
||
|
|
@@ -56,9 +61,11 @@ public static final MapCodec<WorkbenchRecipe> CODEC(RecipeType<WorkbenchRecipe> | |
| ItemStack.STRICT_CODEC.listOf().fieldOf("results").forGetter(WorkbenchRecipe::results), | ||
| Codec.INT.optionalFieldOf("cookTime", 200).forGetter(WorkbenchRecipe::cookTime), | ||
| // Updated to CraftingBookCategory codec | ||
| CraftingBookCategory.CODEC.optionalFieldOf("category", CraftingBookCategory.MISC).forGetter(WorkbenchRecipe::category) | ||
| ).apply(inst, (ingredients, results, cookTime, category) -> | ||
| new WorkbenchRecipe(ingredients, results, cookTime, type, serializer, category) | ||
| CraftingBookCategory.CODEC.optionalFieldOf("category", CraftingBookCategory.MISC).forGetter(WorkbenchRecipe::category), | ||
| Identifier.CODEC.fieldOf("book_category").forGetter(WorkbenchRecipe::bookCategory) | ||
|
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.
Using Proposed fix- Identifier.CODEC.fieldOf("book_category").forGetter(WorkbenchRecipe::bookCategory)
+ Identifier.CODEC.optionalFieldOf("book_category",
+ Identifier.fromNamespaceAndPath("minetale", "campfire_recipe_book_category"))
+ .forGetter(WorkbenchRecipe::bookCategory)The same change should also be applied in 🤖 Prompt for AI Agents |
||
| ).apply(inst, (ingredients, results, cookTime, category, bookCategory) -> | ||
| // 2. Pass the new bookCategory into the constructor | ||
| new WorkbenchRecipe(ingredients, results, cookTime, type, serializer, category, bookCategory) | ||
| )); | ||
| } | ||
|
|
||
|
|
@@ -100,6 +107,15 @@ public WorkbenchRecipeBuilder category(CraftingBookCategory category) { | |
| return this; | ||
| } | ||
|
|
||
| public WorkbenchRecipeBuilder bookCategory(RecipeBookCategory category) { | ||
| Identifier id = BuiltInRegistries.RECIPE_BOOK_CATEGORY.getKey(category); | ||
| if (id != null) { | ||
| this.bookCategory = id; | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Adds an output item stack to the recipe. | ||
| * | ||
|
|
@@ -190,6 +206,9 @@ public void save(RecipeOutput recipeOutput, ResourceKey<Recipe<?>> resourceKey) | |
| .requirements(AdvancementRequirements.Strategy.OR); | ||
|
|
||
| // Add your criteria here (omitted for brevity) | ||
| for (Map.Entry<String, Criterion<?>> entry : this.criteria.entrySet()) { | ||
| advancement.addCriterion(entry.getKey(), entry.getValue()); | ||
| } | ||
|
|
||
| // 3. Create the Recipe Instance | ||
| WorkbenchRecipe recipe = new WorkbenchRecipe( | ||
|
|
@@ -198,7 +217,8 @@ public void save(RecipeOutput recipeOutput, ResourceKey<Recipe<?>> resourceKey) | |
| cookTime, | ||
| this.type, | ||
| this.serializer, | ||
| this.category | ||
| this.category, | ||
| this.bookCategory | ||
| ); | ||
|
|
||
| // 4. Accept the recipe into the generator | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Furnace recipe outputs
ACACIA_BOATfromPORKCHOP— is this intentional?This looks like a debug/test placeholder. Cooking a porkchop into a boat doesn't make sense as a real recipe. If this is intentionally different from the campfire recipe to verify type-based filtering works, please add a comment — otherwise revert to a sensible output.
Also, the comment on line 62 (
"Campfires usually take longer") is copy-pasted from the campfire recipe block above and doesn't apply here.🤖 Prompt for AI Agents