Skip to content

Commit 1712592

Browse files
📝 Add docstrings to fix/update-datagen-recipe-to-26.1
Docstrings generation was requested by @The-Code-Monkey. * #1 (comment) The following files were modified: * `src/main/java/anya/pizza/houseki/block/entity/custom/CrusherBlockEntity.java` * `src/main/java/anya/pizza/houseki/datagen/ModRecipeProvider.java` * `src/main/java/anya/pizza/houseki/datagen/recipebuilder/CrusherRecipeBuilder.java` * `src/main/java/anya/pizza/houseki/recipe/CrusherRecipe.java`
1 parent 40889d1 commit 1712592

File tree

4 files changed

+142
-7
lines changed

4 files changed

+142
-7
lines changed

src/main/java/anya/pizza/houseki/block/entity/custom/CrusherBlockEntity.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ public AbstractContainerMenu createMenu(int syncId, @NonNull Inventory playerInv
110110
return new CrusherScreenHandler(syncId, playerInventory, this, propertyDelegate);
111111
}
112112

113+
/**
114+
* Drops this block entity's inventory at the given position when the block is removed, then
115+
* invokes superclass removal side-effects.
116+
*
117+
* @param pos the position of the block being removed
118+
* @param oldState the previous block state at that position
119+
*/
113120
@Override
114121
public void preRemoveSideEffects(@NonNull BlockPos pos, @NonNull BlockState oldState) {
115122
assert level != null;
@@ -191,6 +198,14 @@ private void updateMaxProgress(Level world) {
191198
.orElse(CrusherRecipe.DEFAULT_CRUSHING_TIME);
192199
}
193200

201+
/**
202+
* Determines whether the current crusher recipe can be executed given available output space.
203+
*
204+
* Checks that a matching recipe exists and that the recipe's primary output and optional auxiliary
205+
* output can both fit into their respective output slots.
206+
*
207+
* @return true if both the main output and the auxiliary output (if present) can be inserted into their slots, false otherwise.
208+
*/
194209
private boolean canCraft() {
195210
Optional<RecipeHolder<CrusherRecipe>> recipe = getCurrentRecipe();
196211
if (recipe.isEmpty()) return false;
@@ -227,13 +242,11 @@ private boolean canInsertIntoSlot(int slot, ItemStack stack) {
227242
}
228243

229244
/**
230-
* Apply the currently matched crusher recipe: produce the recipe's main output, optionally produce
231-
* the auxiliary output based on its chance, and consume one input item.
245+
* Apply the currently matched crusher recipe, producing the recipe's outputs and consuming one input item.
232246
*
233-
* If no matching recipe is available, the method makes no changes. The main output is always
234-
* inserted (or stacked) into the main output slot; the auxiliary output is inserted only if the
235-
* recipe provides one and its configured chance succeeds. One item is removed from the input slot
236-
* when a recipe is applied.
247+
* If no matching recipe is available, no changes are made. The recipe's main output is inserted into (or stacked
248+
* onto) the main output slot; the auxiliary output is inserted into the auxiliary output slot only if the recipe
249+
* provides one and its configured chance succeeds. One item is removed from the input slot when the recipe is applied.
237250
*/
238251
private void craftItem() {
239252
Optional<RecipeHolder<CrusherRecipe>> recipe = getCurrentRecipe();
@@ -276,6 +289,11 @@ private void insertOrIncrement(int slot, ItemStack result, double chance) {
276289
}
277290
}
278291

292+
/**
293+
* Look up the crusher recipe that matches the current input stack on the server.
294+
*
295+
* @return An Optional containing the matching RecipeHolder<CrusherRecipe> when running on a server and a recipe exists; {@code Optional.empty()} otherwise.
296+
*/
279297
private Optional<RecipeHolder<CrusherRecipe>> getCurrentRecipe() {
280298
Level level = this.getLevel();
281299
if (!(level instanceof ServerLevel serverLevel)) {
@@ -285,6 +303,13 @@ private Optional<RecipeHolder<CrusherRecipe>> getCurrentRecipe() {
285303
.getRecipeFor(ModTypes.CRUSHER_TYPE, new CrusherRecipeInput(inventory.getFirst()), level);
286304
}
287305

306+
/**
307+
* Get the inventory slot indices that are accessible from the given block face.
308+
*
309+
* @param side the block face from which access is attempted
310+
* @return an array of slot indices accessible from the specified face; if {@link Direction#DOWN} returns
311+
* OUTPUT_SLOT and AUXILIARY_OUTPUT_SLOT, otherwise returns INPUT_SLOT and FUEL_SLOT
312+
*/
288313
@Override
289314
public int @NonNull [] getSlotsForFace(@NonNull Direction side) {
290315
return side == Direction.DOWN ? new int[]{OUTPUT_SLOT, AUXILIARY_OUTPUT_SLOT} : new int[]{INPUT_SLOT, FUEL_SLOT};

src/main/java/anya/pizza/houseki/datagen/ModRecipeProvider.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ public ModRecipeProvider(FabricPackOutput output, CompletableFuture<HolderLookup
2929
super(output, registriesFuture);
3030
}
3131

32+
/**
33+
* Create a RecipeProvider that registers all Houseki mod recipes.
34+
*
35+
* <p>The provider's buildRecipes implementation defines crushing, smelting, blasting,
36+
* stonecutting, crafting, tool/armor, upgrade, and related recipes and emits them to
37+
* the given recipe output with mod-specific resource keys.</p>
38+
*
39+
* @param wrapperLookup a registry lookup provider used when constructing recipes
40+
* @param recipeExporter the recipe output to which generated recipes will be saved
41+
* @return a RecipeProvider configured to generate the Houseki mod's recipes
42+
*/
3243
@Override
3344
protected RecipeProvider createRecipeProvider(HolderLookup.Provider wrapperLookup, RecipeOutput recipeExporter) {
3445
return new RecipeProvider(wrapperLookup, recipeExporter) {
@@ -469,4 +480,4 @@ public void buildRecipes() {
469480
public @NonNull String getName() {
470481
return "Houseki Recipes";
471482
}
472-
}
483+
}

src/main/java/anya/pizza/houseki/datagen/recipebuilder/CrusherRecipeBuilder.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,65 @@ public class CrusherRecipeBuilder implements RecipeBuilder {
2929
@Nullable
3030
public String group;
3131

32+
/**
33+
* Creates a new CrusherRecipeBuilder for building a crusher recipe.
34+
*
35+
* @param input the ingredient(s) consumed by the recipe
36+
* @param output the resulting item produced by the recipe
37+
* @param crushingTime the crushing duration in ticks
38+
*/
3239
public CrusherRecipeBuilder(Ingredient input, ItemLike output, int crushingTime) {
3340
this.input = input;
3441
this.output = output;
3542
this.crushingTime = crushingTime;
3643
}
3744

45+
/**
46+
* Create a builder for a crusher recipe.
47+
*
48+
* @param input the ingredient consumed by the recipe
49+
* @param output the item produced by the recipe
50+
* @param crushingTime the crushing duration for the recipe
51+
* @return a CrusherRecipeBuilder configured with the provided input, output, and crushing time
52+
*/
3853
public static CrusherRecipeBuilder create(Ingredient input, ItemLike output, int crushingTime) {
3954
return new CrusherRecipeBuilder(input, output, crushingTime);
4055
}
4156

57+
/**
58+
* Sets an optional auxiliary output item for the crusher recipe.
59+
*
60+
* @param stack the auxiliary output item to produce in addition to the primary output
61+
* @return this builder instance
62+
*/
4263
public CrusherRecipeBuilder auxiliary(ItemLike stack) {
4364
this.auxiliaryOutput = Optional.of(stack);
4465
return this;
4566
}
4667

68+
/**
69+
* Set the probability that the auxiliary output is produced.
70+
*
71+
* @param chance the probability (0.0 to 1.0) that the auxiliary output is produced
72+
* @return the current CrusherRecipeBuilder instance
73+
*/
4774
public CrusherRecipeBuilder chance(double chance) {
4875
this.auxiliaryChance = chance;
4976
return this;
5077
}
5178

79+
/**
80+
* Builds an advancement that unlocks the given recipe and exports the constructed
81+
* CrusherRecipe together with that advancement.
82+
*
83+
* The advancement will include a `"has_the_recipe"` criterion for the provided
84+
* recipe key, any additional criteria configured on this builder, and will reward
85+
* the recipe. The built advancement is placed under the `"recipes/"` advancement
86+
* path when exported.
87+
*
88+
* @param exporter target consumer that accepts the recipe and its advancement
89+
* @param recipeKey resource key identifying the recipe to export
90+
*/
5291
public void save(RecipeOutput exporter, ResourceKey<Recipe<?>> recipeKey) {
5392
// 1. Build the advancement
5493
// We use recipeKey.getValue() to get the Identifier (e.g., "modid:item_crushing")
@@ -76,6 +115,16 @@ public void save(RecipeOutput exporter, ResourceKey<Recipe<?>> recipeKey) {
76115
);
77116
}
78117

118+
/**
119+
* Builds a CrusherRecipe and its unlocking advancement, then registers them with the provided exporter under the "recipes/..." advancement path.
120+
*
121+
* The method parses the given recipeId into an Identifier and ResourceKey, adds a "has_the_recipe" criterion and any configured criteria to the advancement,
122+
* sets the recipe as the advancement reward, constructs a CrusherRecipe using this builder's input, output, crushing time, optional auxiliary output, and auxiliary chance,
123+
* and finally passes the recipe, its resource key, and the built advancement (placed under "recipes/<id>") to the exporter.
124+
*
125+
* @param exporter the RecipeOutput consumer that receives the recipe ResourceKey, the built CrusherRecipe, and its corresponding Advancement
126+
* @param recipeId the string identifier for the recipe (parsed into an Identifier and used to derive the advancement path)
127+
*/
79128
public void save(RecipeOutput exporter, String recipeId) {
80129
// 1. Convert the String ID into an Identifier and a ResourceKey
81130
Identifier id = Identifier.parse(recipeId);
@@ -103,6 +152,13 @@ public void save(RecipeOutput exporter, String recipeId) {
103152
exporter.accept(recipeKey, recipe, advancement.build(id.withPrefix("recipes/")));
104153
}
105154

155+
/**
156+
* Adds an advancement criterion that will be required to unlock the resulting recipe.
157+
*
158+
* @param name a unique identifier for the criterion within the recipe's advancement
159+
* @param criterion the criterion describing the unlocking condition
160+
* @return this builder instance for method chaining
161+
*/
106162
@Override
107163
public @NonNull RecipeBuilder unlockedBy(@NonNull String name, @NonNull Criterion<?> criterion) {
108164
this.criteria.put(name, criterion);
@@ -115,11 +171,21 @@ public void save(RecipeOutput exporter, String recipeId) {
115171
return this;
116172
}
117173

174+
/**
175+
* Indicates this builder does not supply a default recipe identifier.
176+
*
177+
* @return {@code null} to indicate no default {@code ResourceKey<Recipe<?>>} is provided.
178+
*/
118179
@Override
119180
public @Nullable ResourceKey<Recipe<?>> defaultId() {
120181
return null;
121182
}
122183

184+
/**
185+
* Gets the Item representation of the configured recipe output.
186+
*
187+
* @return the Item corresponding to the builder's output
188+
*/
123189
public Item getResult() {
124190
return output.asItem();
125191
}

src/main/java/anya/pizza/houseki/recipe/CrusherRecipe.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,43 @@ public String toString() {
3535
}
3636
}
3737

38+
/**
39+
* Create an ItemStack containing the recipe's primary output.
40+
*
41+
* @param registries the registry provider (not used by this implementation)
42+
* @return an ItemStack containing one unit of the recipe's output
43+
*/
3844
public ItemStack getResult(HolderLookup.Provider registries) {
3945
return new ItemStack(this.output);
4046
}
4147

48+
/**
49+
* Determines whether this recipe matches the provided crusher input.
50+
*
51+
* @param input the crusher input whose first slot will be tested against the recipe's ingredient
52+
* @param level the current level/world context
53+
* @return true if the recipe's input ingredient matches the item in the first slot of {@code input}, false otherwise
54+
*/
4255
@Override
4356
public boolean matches(CrusherRecipeInput input, Level level) {
4457
return this.inputItem.test(input.getItem(0));
4558
}
4659

60+
/**
61+
* Create an ItemStack representing this recipe's primary output.
62+
*
63+
* @return an ItemStack containing the recipe's output item with a count of 1
64+
*/
4765
@Override
4866
public ItemStack assemble(CrusherRecipeInput input) {
4967
return new ItemStack(this.output);
5068
}
5169

70+
/**
71+
* Indicates whether using this recipe triggers a player notification.
72+
*
73+
* @return true if a notification should be shown when the recipe is used, false otherwise.
74+
*/
5275
@Override
5376
public boolean showNotification() {
5477
return true;
@@ -65,6 +88,11 @@ public PlacementInfo placementInfo() {
6588
return PlacementInfo.create(this.inputItem);
6689
}
6790

91+
/**
92+
* Specifies the recipe book category for this recipe.
93+
*
94+
* @return the RecipeBookCategory under which this recipe appears (RecipeBookCategories.CRAFTING_MISC)
95+
*/
6896
@Override
6997
public RecipeBookCategory recipeBookCategory() {
7098
// Use a standard category or your own
@@ -98,6 +126,11 @@ public RecipeSerializer<? extends Recipe<CrusherRecipeInput>> getSerializer() {
98126
return SERIALIZER;
99127
}
100128

129+
/**
130+
* Identifies the recipe type for crusher recipes.
131+
*
132+
* @return the RecipeType instance that identifies crusher recipes
133+
*/
101134
@Override
102135
public RecipeType<? extends Recipe<CrusherRecipeInput>> getType() {
103136
return ModTypes.CRUSHER_TYPE;

0 commit comments

Comments
 (0)