Skip to content

Commit 98f12fa

Browse files
📝 Add docstrings to feat/add-farmers-workbench
Docstrings generation was requested by @The-Code-Monkey. The following files were modified: * `src/client/java/com/tcm/MineTale/MineTaleClient.java` * `src/client/java/com/tcm/MineTale/block/workbenches/screen/ArmorersWorkbenchScreen.java` * `src/client/java/com/tcm/MineTale/block/workbenches/screen/FarmersWorkbenchScreen.java` * `src/client/java/com/tcm/MineTale/block/workbenches/screen/WorkbenchWorkbenchScreen.java` * `src/client/java/com/tcm/MineTale/datagen/recipes/FarmerRecipes.java` * `src/client/java/com/tcm/MineTale/datagen/recipes/WorkbenchRecipes.java` * `src/main/java/com/tcm/MineTale/MineTale.java` * `src/main/java/com/tcm/MineTale/block/workbenches/FarmersWorkbench.java` * `src/main/java/com/tcm/MineTale/block/workbenches/entity/FarmersWorkbenchEntity.java` * `src/main/java/com/tcm/MineTale/block/workbenches/menu/AbstractWorkbenchContainerMenu.java` * `src/main/java/com/tcm/MineTale/block/workbenches/menu/ArmorersWorkbenchMenu.java` * `src/main/java/com/tcm/MineTale/block/workbenches/menu/CampfireWorkbenchMenu.java` * `src/main/java/com/tcm/MineTale/block/workbenches/menu/FarmersWorkbenchMenu.java` * `src/main/java/com/tcm/MineTale/block/workbenches/menu/FurnaceWorkbenchMenu.java` * `src/main/java/com/tcm/MineTale/block/workbenches/menu/WorkbenchWorkbenchMenu.java` * `src/main/java/com/tcm/MineTale/registry/ModRecipes.java`
1 parent f42074a commit 98f12fa

16 files changed

Lines changed: 162 additions & 59 deletions

src/client/java/com/tcm/MineTale/MineTaleClient.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424

2525
public class MineTaleClient implements ClientModInitializer {
2626
/**
27-
* Register client-side screen factories for custom workbench menu types.
27+
* Initializes client-side handlers for the MineTale mod.
2828
*
29-
* Binds ModMenuTypes.FURNACE_WORKBENCH_MENU to FurnaceWorkbenchScreen,
30-
* ModMenuTypes.CAMPFIRE_WORKBENCH_MENU to CampfireWorkbenchScreen, and
31-
* ModMenuTypes.WORKBENCH_WORKBENCH_MENU to WorkbenchWorkbenchScreen so the client
32-
* can create the appropriate GUI when those menus open.
29+
* Registers screen factories for custom workbench menu types, configures block render
30+
* layers for furnace workbenches, and registers a global network receiver that applies
31+
* nearby inventory item lists to an open workbench menu when available.
32+
*
33+
* The network receiver schedules a client task that retries up to 10 frames if the
34+
* player's container menu is not yet an instance of the expected workbench menu and
35+
* logs a failure message if synchronization could not be applied after retries.
3336
*/
3437
@Override
3538
public void onInitializeClient() {

src/client/java/com/tcm/MineTale/block/workbenches/screen/ArmorersWorkbenchScreen.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ protected void init() {
118118
}).bounds(defaultLeft + 40, defaultTop + 22, 35, 20).build());
119119
}
120120

121+
/**
122+
* Sends a craft request for the recipe remembered by this screen's last known selection.
123+
*
124+
* Resolves the remembered recipe to its resulting item(s) and, if available, sends a network
125+
* CraftRequestPayload containing the first result and the requested amount. If no remembered
126+
* selection or no results are available, no payload is sent.
127+
*
128+
* @param amount the quantity to craft; use -1 to request crafting all available units
129+
*/
121130
private void handleCraftRequest(int amount) {
122131
// Look at our "Memory" instead of the component
123132
if (this.lastKnownSelectedId != null) {

src/client/java/com/tcm/MineTale/block/workbenches/screen/FarmersWorkbenchScreen.java

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class FarmersWorkbenchScreen extends AbstractRecipeBookScreen<FarmersWork
5050
private Button craftAllBtn;
5151

5252
/**
53-
* Initialize a workbench GUI screen using the provided container menu, player inventory, and title.
53+
* Creates a FarmersWorkbenchScreen configured with the provided container menu, player inventory, and title.
5454
*
5555
* @param menu the menu supplying slots and synchronized state for this screen
5656
* @param inventory the player's inventory to display and interact with
@@ -74,10 +74,10 @@ private FarmersWorkbenchScreen(FarmersWorkbenchMenu menu, Inventory inventory, C
7474
}
7575

7676
/**
77-
* Create a MineTaleRecipeBookComponent configured for the workbench screen.
77+
* Creates a MineTaleRecipeBookComponent configured for the farmers workbench screen.
7878
*
7979
* @param menu the workbench menu used to initialize the recipe book component
80-
* @return a MineTaleRecipeBookComponent containing the workbench tab and associated recipe category
80+
* @return the recipe book component containing the workbench tab and the FARMERS recipe category
8181
*/
8282
private static MineTaleRecipeBookComponent createRecipeBookComponent(FarmersWorkbenchMenu menu) {
8383
ItemStack tabIcon = new ItemStack(ModBlocks.FARMERS_WORKBENCH_BLOCK.asItem());
@@ -90,12 +90,12 @@ private static MineTaleRecipeBookComponent createRecipeBookComponent(FarmersWork
9090
}
9191

9292
/**
93-
* Configure the screen's GUI dimensions and initialize widgets.
94-
*
95-
* Sets the layout size (imageWidth = 176, imageHeight = 166), delegates remaining
96-
* layout initialization to the superclass, and creates the three craft buttons
97-
* ("1", "10", "All") wired to their respective handlers.
98-
*/
93+
* Configure the screen layout size and initialize crafting widgets.
94+
*
95+
* Sets the GUI dimensions to 176x166 and creates three craft buttons:
96+
* "Craft" (requests 1), "x10" (requests 10), and "All" (requests all, represented by -1),
97+
* each wired to their respective handler.
98+
*/
9999
@Override
100100
protected void init() {
101101
// Important: Set your GUI size before super.init()
@@ -121,14 +121,14 @@ protected void init() {
121121
}
122122

123123
/**
124-
* Sends a crafting request for the currently selected recipe in the integrated recipe book.
125-
*
126-
* Locates the last recipe collection and last selected recipe ID from the recipe book component,
127-
* resolves the recipe's result item, and sends a CraftRequestPayload to the server containing that
128-
* item and the requested amount.
129-
*
130-
* @param amount the quantity to craft; use -1 to request crafting of the full available stack ("All")
131-
*/
124+
* Requests the server to craft the currently selected recipe from the integrated recipe book.
125+
*
126+
* If a previously selected recipe is remembered and has at least one result item, sends a
127+
* CraftRequestPayload containing the recipe's primary result and the requested amount. If no
128+
* remembered selection or no result exists, no request is sent.
129+
*
130+
* @param amount the quantity to craft; use -1 to request crafting the maximum available amount ("All")
131+
*/
132132
private void handleCraftRequest(int amount) {
133133
// Look at our "Memory" instead of the component
134134
if (this.lastKnownSelectedId != null) {
@@ -161,6 +161,14 @@ protected void renderBg(GuiGraphics guiGraphics, float f, int i, int j) {
161161
guiGraphics.blit(RenderPipelines.GUI_TEXTURED, TEXTURE, k, l, 0.0F, 0.0F, this.imageWidth, this.imageHeight, 256, 256);
162162
}
163163

164+
/**
165+
* Renders the screen, preserves the last selected recipe, and updates craft button states.
166+
*
167+
* Remembers the recipe book's current selection (so selection persists when the book is closed),
168+
* resolves the corresponding known RecipeDisplayEntry from the player's recipe book when available,
169+
* enables or disables the craft buttons based on whether the player can craft 1, more-than-one, or 10
170+
* of the selected recipe, and renders the background and tooltips.
171+
*/
164172
@Override
165173
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
166174
renderBackground(graphics, mouseX, mouseY, delta);
@@ -201,11 +209,11 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
201209
}
202210

203211
/**
204-
* Determines whether the player has enough ingredients to craft the given recipe the specified number of times.
212+
* Checks whether the given player has the required ingredients to craft the specified recipe the provided number of times.
205213
*
206-
* @param player the player whose inventory (and networked nearby items) will be checked; may be null
207-
* @param entry the recipe display entry providing crafting requirements; may be null
208-
* @param craftCount the multiplier for required ingredient quantities (e.g., 1, 10, or -1 is not specially handled here)
214+
* @param player the player whose inventory and nearby networked items are considered; may be null
215+
* @param entry the recipe entry supplying crafting requirements; may be null
216+
* @param craftCount the number of times to craft the recipe (multiplies each requirement)
209217
* @return `true` if the player has at least the required quantity of each ingredient multiplied by `craftCount`, `false` otherwise (also returns `false` if `player` or `entry` is null or the recipe has no requirements)
210218
*/
211219
private boolean canCraft(Player player, RecipeDisplayEntry entry, int craftCount) {
@@ -248,6 +256,18 @@ private boolean canCraft(Player player, RecipeDisplayEntry entry, int craftCount
248256
return true;
249257
}
250258

259+
/**
260+
* Checks whether the given inventory combined with the workbench's networked nearby items
261+
* contains at least the requested number of items matching the provided ingredient.
262+
*
263+
* Counts matching item stacks from the supplied player inventory and, when the screen's menu
264+
* is an AbstractWorkbenchContainerMenu, from its networked nearby items list.
265+
*
266+
* @param inventory the player's inventory to search
267+
* @param ingredient the ingredient matcher to test item stacks against
268+
* @param totalRequired the total number of matching items required
269+
* @return `true` if the combined sources contain at least `totalRequired` matching items, `false` otherwise
270+
*/
251271
private boolean hasIngredientAmount(Inventory inventory, Ingredient ingredient, int totalRequired) {
252272
System.out.println("DEBUG: Searching inventory + nearby for " + totalRequired + "...");
253273
if (totalRequired <= 0) return true;

src/client/java/com/tcm/MineTale/block/workbenches/screen/WorkbenchWorkbenchScreen.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,10 @@ protected void init() {
121121
}
122122

123123
/**
124-
* Sends a crafting request for the currently selected recipe in the integrated recipe book.
124+
* Request crafting for the currently selected recipe from the integrated recipe book.
125125
*
126-
* Locates the last recipe collection and last selected recipe ID from the recipe book component,
127-
* resolves the recipe's result item, and sends a CraftRequestPayload to the server containing that
128-
* item and the requested amount.
126+
* If a recipe is selected, sends a CraftRequestPayload to the server for that recipe and the
127+
* specified quantity. If no recipe is selected, no request is sent.
129128
*
130129
* @param amount the quantity to craft; use -1 to request crafting of the full available stack ("All")
131130
*/
@@ -161,6 +160,14 @@ protected void renderBg(GuiGraphics guiGraphics, float f, int i, int j) {
161160
guiGraphics.blit(RenderPipelines.GUI_TEXTURED, TEXTURE, k, l, 0.0F, 0.0F, this.imageWidth, this.imageHeight, 256, 256);
162161
}
163162

163+
/**
164+
* Renders the screen, updates the remembered recipe selection, and enables or disables craft buttons based on the player's available ingredients.
165+
*
166+
* <p>This method draws the background and the superclass UI, captures the current recipe selection (persisting it to
167+
* {@code lastKnownSelectedId} when present), resolves the remembered selection against the client's known recipes
168+
* (when a level and player are available), updates the activation state of the craft buttons for counts of 1, 2 and 10
169+
* depending on whether the player has sufficient materials, and finally renders any tooltips.</p>
170+
*/
164171
@Override
165172
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
166173
renderBackground(graphics, mouseX, mouseY, delta);

src/client/java/com/tcm/MineTale/datagen/recipes/FarmerRecipes.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
import net.minecraft.world.level.block.Blocks;
1414

1515
public class FarmerRecipes {
16+
/**
17+
* Registers Farmer workbench recipes and writes them to the provided exporter.
18+
*
19+
* <p>Emits multiple WorkbenchRecipeBuilder entries (bamboo planter, moss variants, rugs,
20+
* vines, soil/grass variants, and other farmer-related recipes) and configures their
21+
* ingredient lists, times, book categories, and unlock conditions.</p>
22+
*
23+
* @param provider source of recipe unlock predicates (used to build "has_farmers_workbench" and similar conditions)
24+
* @param exporter destination that receives the generated recipe data
25+
* @param lookup holder/tag resolver used when recipes specify ingredients by tag
26+
*/
1627
public static void buildRecipes(RecipeProvider provider, RecipeOutput exporter, HolderLookup.Provider lookup) {
1728
// new WorkbenchRecipeBuilder(ModRecipes.FARMERS_TYPE, ModRecipes.FARMERS_SERIALIZER)
1829
// .input(ItemTags.PLANKS, lookup, 20)

src/client/java/com/tcm/MineTale/datagen/recipes/WorkbenchRecipes.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
import net.minecraft.world.item.Items;
1414

1515
public class WorkbenchRecipes {
16+
/**
17+
* Registers workbench crafting recipes and saves them to the provided exporter.
18+
*
19+
* Builds and configures multiple WorkbenchRecipeBuilder instances (inputs, outputs, craft time,
20+
* unlock conditions, and book category) and persists each recipe using the exporter with a
21+
* unique identifier.
22+
*
23+
* @param provider a RecipeProvider used to query existing items/blocks for unlock conditions and tags
24+
* @param exporter the RecipeOutput that receives and writes the generated recipe data
25+
* @param lookup a HolderLookup.Provider used to resolve tag holders (e.g., ItemTags) when specifying inputs
26+
*/
1627
public static void buildRecipes(RecipeProvider provider, RecipeOutput exporter, HolderLookup.Provider lookup) {
1728
new WorkbenchRecipeBuilder(ModRecipes.WORKBENCH_TYPE, ModRecipes.WORKBENCH_SERIALIZER)
1829
.input(Items.COPPER_INGOT, 2)

src/main/java/com/tcm/MineTale/MineTale.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ public class MineTale implements ModInitializer {
4242
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
4343

4444
/**
45-
* Initializes and registers the mod's game content and subsystems during Fabric startup.
45+
* Initialize and register the mod's game content, network payloads, and runtime subsystems on startup.
4646
*
47-
* <p>Triggers initialization for blocks, block entities, menu types, entities, items, and entity
48-
* data serializers so they are registered with the game before gameplay begins.</p>
47+
* <p>Registers blocks, items, block entities, entities, menus, recipes, recipe displays, creative tab,
48+
* entity data serializers, recipe serializer synchronization, and loot-table modifiers. Also registers
49+
* client↔server payload codecs and a global server receiver that processes craft requests from workbench-like menus.
4950
*/
5051
@Override
5152
public void onInitialize() {

src/main/java/com/tcm/MineTale/block/workbenches/FarmersWorkbench.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class FarmersWorkbench extends AbstractWorkbench<FarmersWorkbenchEntity>
3030
public static final MapCodec<FarmersWorkbench> CODEC = simpleCodec(FarmersWorkbench::new);
3131

3232
/**
33-
* Constructs a FarmersWorkbench that uses the mod's FARMERS_WORKBENCH_BE block entity type.
33+
* Creates a FarmersWorkbench preconfigured to use ModBlockEntities.FARMERS_WORKBENCH_BE as its block entity type.
3434
*
3535
* @param properties block properties for this workbench
3636
*/
@@ -40,10 +40,10 @@ public FarmersWorkbench(Properties properties) {
4040
}
4141

4242
/**
43-
* Constructs a FarmersWorkbench using the provided block properties and block-entity type supplier.
43+
* Create a FarmersWorkbench with the given block properties and a supplier for its block-entity type.
4444
*
4545
* @param properties block properties to apply to this workbench
46-
* @param supplier supplier that provides the BlockEntityType for the FarmersWorkbenchEntity
46+
* @param supplier supplier that provides the specific BlockEntityType to use for FarmersWorkbenchEntity
4747
*/
4848
public FarmersWorkbench(Properties properties, Supplier<BlockEntityType<? extends FarmersWorkbenchEntity>> supplier) {
4949
super(properties, supplier, IS_WIDE, IS_TALL, 1);

src/main/java/com/tcm/MineTale/block/workbenches/entity/FarmersWorkbenchEntity.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
public class FarmersWorkbenchEntity extends AbstractWorkbenchEntity {
2828
protected final ContainerData data = new ContainerData() {
2929
/**
30-
* Retrieves an internal data value by index for UI synchronization.
30+
* Provide the container's UI-synchronized integer value for the specified data index.
3131
*
32-
* @param index There is no cook time or anything for this block as it doesnt use it
33-
* @return the value associated with {@code index}, or 0 for any other index
32+
* This workbench exposes four data slots (indices 0–3); all slots are currently unused and always return 0.
33+
*
34+
* @param index the data index to read (expected range: 0–3)
35+
* @return 0 for the requested index
3436
*/
3537
@Override
3638
public int get(int index) {
@@ -40,10 +42,10 @@ public int get(int index) {
4042
}
4143

4244
/**
43-
* No-op for this workbench; data is server-driven and not set client-side.
45+
* No-op setter: client-side attempts to change workbench UI data are ignored because the server is authoritative.
4446
*
45-
* `@param` index the data index to set
46-
* `@param` value the value to assign (ignored)
47+
* @param index the data index (ignored)
48+
* @param value the value to assign (ignored)
4749
*/
4850
@Override
4951
public void set(int index, int value) {
@@ -62,9 +64,9 @@ public int getCount() {
6264
};
6365

6466
/**
65-
* Creates a FarmersWorkbenchEntity for the specified world position and block state.
67+
* Create a FarmersWorkbenchEntity at the given world position and block state.
6668
*
67-
* Sets the entity's scanRadius to 0.0 and tier to 1.
69+
* Initializes the workbench tier to 1 and enables pulling from nearby inventories.
6870
*
6971
* @param blockPos the world position of this block entity
7072
* @param blockState the block state for this block entity
@@ -77,12 +79,10 @@ public FarmersWorkbenchEntity(BlockPos blockPos, BlockState blockState) {
7779
}
7880

7981
/**
80-
* Persist this workbench's state to the given ValueOutput.
81-
*
82-
* Stores "WorkbenchTier" (int), "ScanRadius" (double), and the full inventory under "Inventory"
83-
* using type-safe Codecs.
82+
* Writes this workbench's persistent state to the provided output, including the workbench tier,
83+
* scan radius, and full inventory (stored under the keys "WorkbenchTier", "ScanRadius", and "Inventory").
8484
*
85-
* @param valueOutput the writer used to serialize this entity's fields
85+
* @param valueOutput the output used to serialize this entity's fields
8686
*/
8787
@Override
8888
protected void saveAdditional(ValueOutput valueOutput) {
@@ -126,12 +126,12 @@ protected void loadAdditional(ValueInput valueInput) {
126126
}
127127

128128
/**
129-
* Creates the server-side container menu for this workbench's UI.
129+
* Create the server-side menu for a player to interact with this workbench and synchronize nearby data to that player.
130130
*
131131
* @param syncId the window id used to synchronize the menu with the client
132132
* @param playerInventory the opening player's inventory
133133
* @param player the player who opened the menu
134-
* @return a FarmersWorkbenchMenu bound to this workbench's inventory and synced data
134+
* @return the FarmersWorkbenchMenu bound to this workbench's inventory and synchronization data
135135
*/
136136
@Override
137137
public @Nullable AbstractContainerMenu createMenu(int syncId, Inventory playerInventory, Player player) {

src/main/java/com/tcm/MineTale/block/workbenches/menu/AbstractWorkbenchContainerMenu.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,19 @@ public void setNetworkedNearbyItems(List<ItemStack> items) {
5252
}
5353

5454
/**
55-
* Gets the list of items found in nearby chests.
55+
* Accesses the network-synchronized list of nearby item stacks used to simulate available ingredients.
56+
*
57+
* @return the live list of {@code ItemStack} instances representing nearby items synchronized from the server; entries may be empty
5658
*/
5759
public List<ItemStack> getNetworkedNearbyItems() {
5860
return this.networkedNearbyItems;
5961
}
6062

63+
/**
64+
* Provide the recipe system used by this workbench menu.
65+
*
66+
* @return the {@code RecipeType<WorkbenchRecipe>} used to match and retrieve recipes for this workbench
67+
*/
6168
public RecipeType<WorkbenchRecipe> getRecipeType() {
6269
return this.recipeType;
6370
}

0 commit comments

Comments
 (0)