Skip to content

Commit 41f3a8a

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/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` These files were kept as they were: * `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/registry/ModRecipes.java`
1 parent 98f12fa commit 41f3a8a

13 files changed

Lines changed: 108 additions & 106 deletions

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

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

2525
public class MineTaleClient implements ClientModInitializer {
2626
/**
27-
* Initializes client-side handlers for the MineTale mod.
27+
* Initialises client-side handlers for the MineTale mod.
2828
*
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.
29+
* Registers screen factories for custom workbench menu types, configures render
30+
* layers for furnace workbench blocks, and registers a global network receiver
31+
* that applies nearby inventory items to an open workbench menu.
3232
*
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.
33+
* The network receiver schedules work on the client thread and retries application
34+
* for up to 10 client ticks if the expected workbench menu is not yet open; if
35+
* synchronization still fails it logs a failure message.
3636
*/
3737
@Override
3838
public void onInitializeClient() {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ private static MineTaleRecipeBookComponent createRecipeBookComponent(ArmorersWor
8888
}
8989

9090
/**
91-
* Configure the screen's GUI dimensions and initialize widgets.
92-
*
93-
* Sets the layout size (imageWidth = 176, imageHeight = 166), delegates remaining
94-
* layout initialization to the superclass, and creates the three craft buttons
95-
* ("1", "10", "All") wired to their respective handlers.
96-
*/
91+
* Initialises the screen size and adds the three crafting buttons.
92+
*
93+
* Sets the GUI image dimensions, delegates further initialisation to the superclass,
94+
* and creates/registers three buttons wired to craft one, ten or all items
95+
* (they invoke handleCraftRequest with 1, 10 and -1 respectively; -1 signifies "All").
96+
*/
9797
@Override
9898
protected void init() {
9999
// Important: Set your GUI size before super.init()

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,12 @@ private static MineTaleRecipeBookComponent createRecipeBookComponent(FarmersWork
9090
}
9191

9292
/**
93-
* Configure the screen layout size and initialize crafting widgets.
93+
* Initialises the screen layout and registers the crafting controls.
9494
*
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.
95+
* Sets the GUI dimensions to 176×166 and adds three buttons wired to craft requests:
96+
* - "Craft" requests 1,
97+
* - "x10" requests 10,
98+
* - "All" requests all (represented by -1).
9899
*/
99100
@Override
100101
protected void init() {
@@ -257,16 +258,13 @@ private boolean canCraft(Player player, RecipeDisplayEntry entry, int craftCount
257258
}
258259

259260
/**
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.
261+
* Determine whether the player inventory together with the workbench's networked nearby items
262+
* contains at least the specified quantity of items matching the given ingredient.
262263
*
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
264+
* @param inventory the player's inventory to check
265+
* @param ingredient the ingredient matcher used to test item stacks
268266
* @param totalRequired the total number of matching items required
269-
* @return `true` if the combined sources contain at least `totalRequired` matching items, `false` otherwise
267+
* @return true if the combined sources contain at least totalRequired matching items, false otherwise
270268
*/
271269
private boolean hasIngredientAmount(Inventory inventory, Ingredient ingredient, int totalRequired) {
272270
System.out.println("DEBUG: Searching inventory + nearby for " + totalRequired + "...");
@@ -303,10 +301,10 @@ private boolean hasIngredientAmount(Inventory inventory, Ingredient ingredient,
303301
}
304302

305303
/**
306-
* Computes the on-screen position for the recipe book toggle button for this GUI.
307-
*
308-
* @return the screen position placed 5 pixels from the GUI's left edge and 49 pixels above the GUI's vertical center
309-
*/
304+
* Get the screen position for the recipe book toggle button.
305+
*
306+
* @return the ScreenPosition located 5 pixels from the GUI's left edge and 49 pixels above the GUI's vertical centre
307+
*/
310308
@Override
311309
protected ScreenPosition getRecipeBookButtonPosition() {
312310
// 1. Calculate the start (left) of your workbench GUI

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,14 @@ private static MineTaleRecipeBookComponent createRecipeBookComponent(WorkbenchWo
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+
* Initialises the workbench screen's GUI size and interactive widgets.
94+
*
95+
* Sets the screen image dimensions, delegates remaining setup to the superclass,
96+
* computes default button positions and creates three craft buttons:
97+
* - "Craft" (requests 1),
98+
* - "x10" (requests 10),
99+
* - "All" (requests -1 to indicate all).
100+
*/
99101
@Override
100102
protected void init() {
101103
// Important: Set your GUI size before super.init()
@@ -147,12 +149,12 @@ private void handleCraftRequest(int amount) {
147149
}
148150

149151
/**
150-
* Draws the workbench GUI background texture at the screen's top-left corner.
152+
* Draws the workbench background texture at the screen's current GUI origin.
151153
*
152154
* @param guiGraphics the graphics context used to draw GUI elements
153155
* @param f partial tick time for interpolation
154-
* @param i current mouse x coordinate relative to the window
155-
* @param j current mouse y coordinate relative to the window
156+
* @param i current mouse x coordinate
157+
* @param j current mouse y coordinate
156158
*/
157159
protected void renderBg(GuiGraphics guiGraphics, float f, int i, int j) {
158160
int k = this.leftPos;
@@ -161,12 +163,11 @@ protected void renderBg(GuiGraphics guiGraphics, float f, int i, int j) {
161163
}
162164

163165
/**
164-
* Renders the screen, updates the remembered recipe selection, and enables or disables craft buttons based on the player's available ingredients.
166+
* Render the screen, remember the current recipe selection and update craft-button availability.
165167
*
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>
168+
* Remembers the recipe selected in the recipe book, resolves that selection against the client's known recipes when possible,
169+
* sets the craft buttons active or inactive according to whether the player has sufficient ingredients for counts of 1, 2 and 10,
170+
* renders the background, the superclass UI and any tooltips.
170171
*/
171172
@Override
172173
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {

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

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

4444
/**
45-
* Initialize and register the mod's game content, network payloads, and runtime subsystems on startup.
45+
* Initialise the mod: register game content, networking codecs and runtime subsystems.
4646
*
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.
47+
* Performs startup registration in dependency order (blocks, items, block entities, entities,
48+
* menus, recipes and recipe displays), registers the creative tab and entity data serializers,
49+
* synchronises the furnace recipe serializer, applies loot-table modifiers, registers client↔server
50+
* payload codecs and a global server receiver that processes craft requests from workbench-like menus.
5051
*/
5152
@Override
5253
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-
* Creates a FarmersWorkbench preconfigured to use ModBlockEntities.FARMERS_WORKBENCH_BE as its block entity type.
33+
* Initialise a FarmersWorkbench that uses the mod's FARMERS_WORKBENCH_BE block-entity type and default size.
3434
*
3535
* @param properties block properties for this workbench
3636
*/
@@ -40,10 +40,10 @@ public FarmersWorkbench(Properties properties) {
4040
}
4141

4242
/**
43-
* Create a FarmersWorkbench with the given block properties and a supplier for its block-entity type.
43+
* Constructs a FarmersWorkbench with the supplied block properties and block-entity type supplier.
4444
*
4545
* @param properties block properties to apply to this workbench
46-
* @param supplier supplier that provides the specific BlockEntityType to use for FarmersWorkbenchEntity
46+
* @param supplier supplier of the BlockEntityType to use for the workbench's block entity
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ public int get(int index) {
4242
}
4343

4444
/**
45-
* No-op setter: client-side attempts to change workbench UI data are ignored because the server is authoritative.
45+
* Ignore attempts to modify the workbench's container data from the client; changes are a no-op.
4646
*
47-
* @param index the data index (ignored)
48-
* @param value the value to assign (ignored)
47+
* @param index the data slot index (ignored)
48+
* @param value the value provided (ignored)
4949
*/
5050
@Override
5151
public void set(int index, int value) {

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ public abstract class AbstractWorkbenchContainerMenu extends RecipeBookMenu impl
4444
private List<ItemStack> networkedNearbyItems = new ArrayList<>();
4545

4646
/**
47-
* Updates the list of items available from nearby chests.
48-
* Called by the networking system when a sync packet arrives.
47+
* Replace the cached list of nearby item stacks supplied by the server for recipe simulation.
48+
*
49+
* Updates the menu's networked nearby-items list with the provided stacks; this list is used
50+
* when the recipe book or placement logic simulates available ingredients from nearby inventories.
51+
*
52+
* @param items the new list of nearby ItemStack instances received from the server
4953
*/
5054
public void setNetworkedNearbyItems(List<ItemStack> items) {
5155
this.networkedNearbyItems = items;
@@ -61,31 +65,31 @@ public List<ItemStack> getNetworkedNearbyItems() {
6165
}
6266

6367
/**
64-
* Provide the recipe system used by this workbench menu.
68+
* The recipe type used to match recipes for this workbench.
6569
*
66-
* @return the {@code RecipeType<WorkbenchRecipe>} used to match and retrieve recipes for this workbench
70+
* @return the RecipeType for WorkbenchRecipe instances, or {@code null} if no recipe type was provided
6771
*/
6872
public RecipeType<WorkbenchRecipe> getRecipeType() {
6973
return this.recipeType;
7074
}
7175

7276
/**
73-
* Constructs a workbench container menu, initializes inventory and sync state, and opens the container for the player.
77+
* Initialise a workbench container menu, attach the player inventory and hotbar, and open the backing container for the player.
7478
*
75-
* The constructor conditionally validates container size and attaches container data slots only when the container actually
76-
* contains slots (i.e., when `outputEnd >= 0` and the container size is > 0). For slotless workbenches it only verifies the
77-
* container is non-null with size 0. If the container has slots, workbench-specific slots are added; the player's inventory
78-
* and hotbar are always added. The container is opened for the provided player.
79+
* If the backing container provides slots (determined by a non-negative `outputEnd` and a positive container size),
80+
* container size and data slot counts are validated and the provided `data` is attached for progress syncing; when the
81+
* container is slotless the constructor validates an empty container and skips slot/data attachment.
7982
*
80-
* @param menuType the menu type or null for an unregistered type
81-
* @param syncId synchronization id for the menu
82-
* @param container the underlying container backing this menu
83-
* @param data container data used to sync progress/state (e.g., burn/cook times)
84-
* @param containerDataSize expected size of `data` when the container provides slots; used for data count validation
85-
* @param playerInventory the player's inventory to attach to this menu
86-
* @param inputEnd index (inclusive) of the last input slot in the container
87-
* @param outputEnd index (inclusive) of the last output slot in the container; if negative or container is empty,
88-
* the menu is treated as slotless and slot/data initialization is skipped
83+
* @param menuType the menu type, or {@code null} for an unregistered type
84+
* @param syncId synchronization id for this menu instance
85+
* @param container the backing container for workbench slots (may be empty for slotless workbenches)
86+
* @param data container data used to sync progress/state (e.g. burn/cook times)
87+
* @param containerDataSize expected size of {@code data} when the container provides slots; used for validation
88+
* @param playerInventory the player's inventory to attach to the menu and to open the container for
89+
* @param inputEnd inclusive index of the last input slot in {@code container}
90+
* @param outputEnd inclusive index of the last output slot in {@code container}; negative or empty container
91+
* indicates a slotless workbench
92+
* @param recipeType the recipe type used by this workbench, or {@code null} if none
8993
*/
9094
public AbstractWorkbenchContainerMenu(@Nullable MenuType<?> menuType, int syncId, Container container, ContainerData data, int containerDataSize, Inventory playerInventory, int inputEnd, int outputEnd, RecipeType<WorkbenchRecipe> recipeType) {
9195
super(menuType, syncId);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ public ArmorersWorkbenchMenu(int syncId, Inventory playerInventory) {
3737
}
3838

3939
/**
40-
* Creates a workbench menu associated with the given player inventory and optional block entity.
40+
* Creates a workbench menu bound to the given player inventory and optional block entity.
4141
*
42-
* Uses an empty internal container (size 0) and the class's data size for syncing numeric state.
42+
* Uses an empty internal container (size 0) and the class's data size to synchronise numeric state.
4343
*
44-
* @param syncId synchronization id for this menu
44+
* @param syncId the synchronisation id for this menu
4545
* @param playerInventory the player's inventory used for slot access and recipe-book integration
46-
* @param data container data used to sync numeric state between server and client
46+
* @param data container data used to synchronise numeric state between server and client
4747
* @param blockEntity nullable block entity this menu is bound to, or {@code null} if not bound
4848
*/
4949
public ArmorersWorkbenchMenu(int syncId, Inventory playerInventory, ContainerData data, @Nullable AbstractWorkbenchEntity blockEntity) {

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,25 @@ public class CampfireWorkbenchMenu extends AbstractWorkbenchContainerMenu {
2424
private final AbstractWorkbenchEntity blockEntity;
2525

2626
/**
27-
* Creates a CampfireWorkbenchMenu using default internal storage and data containers.
27+
* Create a CampfireWorkbenchMenu initialised with the default internal inventory and data containers.
2828
*
29-
* Constructs a menu with a new SimpleContainer of size {@code containerSize} and a new
30-
* SimpleContainerData of size {@code containerDataSize}, then delegates to the primary constructor.
29+
* The menu is constructed with a 7‑slot internal container and a data container sized by {@code containerDataSize}.
3130
*
32-
* @param syncId synchronization id for the menu
31+
* @param syncId the synchronization id for this menu
3332
* @param playerInventory the player's inventory interacting with this menu
3433
*/
3534
public CampfireWorkbenchMenu(int syncId, Inventory playerInventory) {
3635
this(syncId, playerInventory, new SimpleContainer(7), new SimpleContainerData(containerDataSize), null);
3736
}
3837

3938
/**
40-
* Constructs a CampfireWorkbenchMenu connected to the given player inventory, container, and container data.
39+
* Create a CampfireWorkbenchMenu bound to the given player inventory, container and container data.
4140
*
42-
* @param syncId the synchronization id for this menu used for client/server container sync
41+
* @param syncId the synchronisation id used for clientserver container sync
4342
* @param playerInventory the player's inventory
44-
* @param container the backing container for the workbench slots
45-
* @param data the container data used for syncing additional numeric state
46-
* @param blockEntity the associated workbench block entity, or `null` if not bound to a block
43+
* @param container the backing container that provides the workbench slots
44+
* @param data the container data used to synchronise numeric state
45+
* @param blockEntity the associated workbench block entity, or {@code null} if not bound to a block
4746
*/
4847
public CampfireWorkbenchMenu(int syncId, Inventory playerInventory, Container container, ContainerData data, @Nullable AbstractWorkbenchEntity blockEntity) {
4948
super(ModMenuTypes.CAMPFIRE_WORKBENCH_MENU, syncId, container, data, containerDataSize, playerInventory, Constants.INPUT_START + 1, 6, ModRecipes.CAMPFIRE_TYPE);

0 commit comments

Comments
 (0)