Skip to content

Commit 6c39d4c

Browse files
📝 Add docstrings to feat/add-workbench
Docstrings generation was requested by @The-Code-Monkey. * #30 (comment) The following files were modified: * `src/client/java/com/tcm/MineTale/block/workbenches/screen/WorkbenchWorkbenchScreen.java` * `src/main/java/com/tcm/MineTale/block/workbenches/WorkbenchWorkbench.java` * `src/main/java/com/tcm/MineTale/block/workbenches/entity/WorkbenchWorkbenchEntity.java` * `src/main/java/com/tcm/MineTale/block/workbenches/menu/WorkbenchWorkbenchMenu.java` * `src/main/java/com/tcm/MineTale/registry/ModBlockEntities.java` * `src/main/java/com/tcm/MineTale/registry/ModBlocks.java` * `src/main/java/com/tcm/MineTale/registry/ModRecipeDisplay.java` * `src/main/java/com/tcm/MineTale/registry/ModRecipes.java`
1 parent 4d00701 commit 6c39d4c

8 files changed

Lines changed: 110 additions & 52 deletions

File tree

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

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public class WorkbenchWorkbenchScreen extends AbstractRecipeBookScreen<Workbench
2424
Identifier.fromNamespaceAndPath(MineTale.MOD_ID, "textures/gui/container/furnace_workbench.png");
2525

2626
/**
27-
* Creates a campfire workbench screen for the provided menu, player inventory, and title.
27+
* Initialize a workbench GUI screen using the provided container menu, player inventory, and title.
2828
*
29-
* @param menu the container menu that provides slots and synchronizes state for this screen
29+
* @param menu the menu supplying slots and synchronized state for this screen
3030
* @param inventory the player's inventory to display and interact with
3131
* @param title the title component shown at the top of the screen
3232
*/
@@ -35,8 +35,10 @@ public WorkbenchWorkbenchScreen(WorkbenchWorkbenchMenu menu, Inventory inventory
3535
}
3636

3737
/**
38-
* Static helper to build the component with the custom MineTale tabs
39-
* before the super constructor is called.
38+
* Create a MineTaleRecipeBookComponent configured for the workbench screen.
39+
*
40+
* @param menu the workbench menu used to initialize the recipe book component
41+
* @return a MineTaleRecipeBookComponent containing the workbench tab and associated recipe category
4042
*/
4143
private static MineTaleRecipeBookComponent createRecipeBookComponent(WorkbenchWorkbenchMenu menu) {
4244
ItemStack tabIcon = new ItemStack(ModBlocks.WORKBENCH_WORKBENCH_BLOCK.asItem());
@@ -49,7 +51,10 @@ private static MineTaleRecipeBookComponent createRecipeBookComponent(WorkbenchWo
4951
}
5052

5153
/**
52-
* Initializes the screen and centers the title horizontally by setting {@code titleLabelX}.
54+
* Sets the screen's GUI size and initializes layout so the title is centered.
55+
*
56+
* Sets imageWidth to 176 and imageHeight to 166 before delegating to the superclass
57+
* init method to complete widget and layout initialization (including horizontal title centering).
5358
*/
5459
@Override
5560
protected void init() {
@@ -61,12 +66,12 @@ protected void init() {
6166
}
6267

6368
/**
64-
* Renders the campfire workbench background texture at the screen's top-left position.
69+
* Renders the workbench GUI background texture at the screen's top-left position.
6570
*
66-
* @param guiGraphics the graphics context used for drawing
67-
* @param f partial ticks for interpolation
68-
* @param i current mouse x position
69-
* @param j current mouse y position
71+
* @param guiGraphics the graphics context for drawing
72+
* @param f partial tick time used for interpolation
73+
* @param i current mouse x coordinate
74+
* @param j current mouse y coordinate
7075
*/
7176
protected void renderBg(GuiGraphics guiGraphics, float f, int i, int j) {
7277
int k = this.leftPos;
@@ -75,13 +80,13 @@ protected void renderBg(GuiGraphics guiGraphics, float f, int i, int j) {
7580
}
7681

7782
/**
78-
* Renders the campfire workbench screen, drawing its background, contents, and tooltips.
79-
*
80-
* @param graphics the graphics context used for rendering
81-
* @param mouseX the current mouse X coordinate
82-
* @param mouseY the current mouse Y coordinate
83-
* @param delta the frame time delta (partial tick) used for animated rendering
84-
*/
83+
* Renders the workbench screen including the background tint, GUI elements, and tooltips.
84+
*
85+
* @param graphics the graphics context
86+
* @param mouseX the current mouse x-coordinate
87+
* @param mouseY the current mouse y-coordinate
88+
* @param delta the partial tick delta for frame interpolation
89+
*/
8590
@Override
8691
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
8792
// 1. Always render the dark background tint first
@@ -93,6 +98,11 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
9398
renderTooltip(graphics, mouseX, mouseY);
9499
}
95100

101+
/**
102+
* Compute the on-screen position for the recipe book toggle button for this GUI.
103+
*
104+
* @return the ScreenPosition located 5 pixels from the GUI's left edge and 49 pixels above the GUI's vertical center
105+
*/
96106
@Override
97107
protected ScreenPosition getRecipeBookButtonPosition() {
98108
// 1. Calculate the start (left) of your workbench GUI

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

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

3232
/**
33-
* Creates a WorkbenchWorkbench configured to use the mod's WORKBENCH_WORKBENCH_BE block entity type.
33+
* Constructs a WorkbenchWorkbench that uses the mod's WORKBENCH_WORKBENCH_BE block entity type.
3434
*
35-
* @param properties block properties used to construct this workbench
35+
* @param properties block properties for this workbench
3636
*/
3737
public WorkbenchWorkbench(Properties properties) {
3838
// Hardcode the supplier and sounds here if they never change
@@ -51,9 +51,9 @@ public WorkbenchWorkbench(Properties properties, Supplier<BlockEntityType<? exte
5151
}
5252

5353
/**
54-
* Provides a ticker that updates workbench workbench block entities each tick.
54+
* Supplies a ticker that updates WorkbenchWorkbench block entities each tick.
5555
*
56-
* @return a BlockEntityTicker that invokes AbstractWorkbenchEntity.tick for WorkbenchWorkbenchEntity instances, or `null` if the supplied block entity type does not match the workbench workbench type.
56+
* @return a BlockEntityTicker that invokes AbstractWorkbenchEntity.tick for matching WorkbenchWorkbenchEntity instances, `null` if the supplied block entity type does not match
5757
*/
5858
@Nullable
5959
@Override
@@ -63,7 +63,7 @@ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, Block
6363
}
6464

6565
/**
66-
* The codec used to serialize and deserialize this WorkbenchWorkbench type.
66+
* Provides the MapCodec used to serialize and deserialize this workbench.
6767
*
6868
* @return the MapCodec for this WorkbenchWorkbench
6969
*/
@@ -87,9 +87,11 @@ public RenderShape getRenderShape(BlockState state) {
8787
private static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 7, 16);
8888

8989
/**
90-
* Gets the block's collision and interaction shape.
90+
* Provides the block's collision and interaction shape.
9191
*
92-
* @return the voxel shape representing the block's collision and interaction bounds
92+
* <p>Uses a fixed voxel shape covering a 1×1 footprint with a height of 7 units (coordinates: x 0–16, y 0–7, z 0–16).</p>
93+
*
94+
* @return the voxel shape used for collision and interaction
9395
*/
9496
@Override
9597
public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {

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

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ public int get(int index) {
5050
}
5151

5252
/**
53-
* Sets an internal workbench data field identified by index.
53+
* Update an internal workbench data field identified by index.
5454
*
5555
* Supported indices:
5656
* <ul>
57-
* <li>0 — sets {@code fuelTime}</li>
58-
* <li>2 — sets {@code cookTime}</li>
57+
* <li>0 — set {@code fuelTime}</li>
58+
* <li>2 — set {@code cookTime}</li>
5959
* </ul>
6060
* Other indices are ignored.
6161
*
@@ -97,10 +97,14 @@ public WorkbenchWorkbenchEntity(BlockPos blockPos, BlockState blockState) {
9797
}
9898

9999
/**
100-
* Performs server-side per-tick updates for this workbench.
100+
* Run server-side per-tick updates for this workbench entity.
101101
*
102-
* <p>This method is a no-op on the client and exits immediately; server-side update logic
103-
* should be implemented here.
102+
* <p>Does nothing on the client. On the server this advances the input queue so the next
103+
* item becomes ready and, if any state changes occur, marks the block entity as changed.
104+
*
105+
* @param level the world in which the workbench exists
106+
* @param pos the position of the workbench block
107+
* @param state the current block state at the workbench's position
104108
*/
105109
public void tick(Level level, BlockPos pos, BlockState state) {
106110
if (level.isClientSide()) return;
@@ -118,8 +122,9 @@ public void tick(Level level, BlockPos pos, BlockState state) {
118122
}
119123

120124
/**
121-
* Iterates through the queue range. If a slot is empty, it pulls the item
122-
* from the slot behind it.
125+
* Compacts the input queue by moving items forward into the first empty slot ahead of them.
126+
*
127+
* @return `true` if any items were moved, `false` otherwise.
123128
*/
124129
private boolean shiftQueueForward() {
125130
boolean moved = false;
@@ -152,12 +157,12 @@ private boolean shiftQueueForward() {
152157
// private boolean isFuel(ItemStack stack) { return stack.is(ItemTags.LOGS_THAT_BURN) || stack.is(Items.STICK); }
153158

154159
/**
155-
* Persist entity-specific state into the provided ValueOutput.
160+
* Persist this workbench's state to the given ValueOutput.
156161
*
157-
* Stores the workbench's tier as "WorkbenchTier" and its scan radius as "ScanRadius"
162+
* Stores "WorkbenchTier" (int), "ScanRadius" (double), and the full inventory under "Inventory"
158163
* using type-safe Codecs.
159164
*
160-
* @param valueOutput the output writer used to serialize this entity's fields
165+
* @param valueOutput the writer used to serialize this entity's fields
161166
*/
162167
@Override
163168
protected void saveAdditional(ValueOutput valueOutput) {
@@ -201,22 +206,22 @@ protected void loadAdditional(ValueInput valueInput) {
201206
}
202207

203208
/**
204-
* Create the server-side container menu for the workbench workbench UI.
209+
* Creates the server-side container menu for this workbench's UI.
205210
*
206-
* @param syncId window id used to synchronize the menu with the client
211+
* @param syncId the window id used to synchronize the menu with the client
207212
* @param playerInventory the opening player's inventory
208-
* @param player the player who opened the menu
209-
* @return a WorkbenchWorkbenchMenu tied to this workbench's inventory and sync data
213+
* @param player the player who opened the menu
214+
* @return a WorkbenchWorkbenchMenu bound to this workbench's inventory and synced data
210215
*/
211216
@Override
212217
public @Nullable AbstractContainerMenu createMenu(int syncId, Inventory playerInventory, Player player) {
213218
return new WorkbenchWorkbenchMenu(syncId, playerInventory, this.inventory, this.data, this);
214219
}
215220

216221
/**
217-
* Specifies which recipe type this workbench uses.
222+
* Identifies the recipe type used to find and match recipes for this workbench.
218223
*
219-
* @return the workbench workbench recipe type used to look up and match recipes
224+
* @return the RecipeType for workbench recipes
220225
*/
221226
@Override
222227
public RecipeType<WorkbenchRecipe> getWorkbenchRecipeType() {

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

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public class WorkbenchWorkbenchMenu extends AbstractWorkbenchContainerMenu {
2323
private final AbstractWorkbenchEntity blockEntity;
2424

2525
/**
26-
* Creates a WorkbenchWorkbenchMenu using default internal storage and data containers.
26+
* Constructs a WorkbenchWorkbenchMenu backed by default internal storage and data.
2727
*
28-
* Constructs a menu with a new SimpleContainer of size {@code containerSize} and a new
29-
* SimpleContainerData of size {@code containerDataSize}, then delegates to the primary constructor.
28+
* Initializes the menu with a new 7-slot SimpleContainer and a SimpleContainerData of size
29+
* {@code containerDataSize}, and binds it to the provided player inventory.
3030
*
3131
* @param syncId synchronization id for the menu
3232
* @param playerInventory the player's inventory interacting with this menu
@@ -36,23 +36,34 @@ public WorkbenchWorkbenchMenu(int syncId, Inventory playerInventory) {
3636
}
3737

3838
/**
39-
* Creates a WorkbenchWorkbenchMenu bound to the given player inventory, container, and container data.
39+
* Creates a workbench menu bound to the given player inventory, container, container data, and optional block entity.
4040
*
41-
* @param syncId the synchronization id for this menu (used by the client/server container sync)
41+
* @param syncId synchronization id for this menu
4242
* @param playerInventory the player's inventory
43-
* @param container the backing container for the workbench slots
44-
* @param data the container data used for syncing additional numeric state
43+
* @param container backing container for the workbench slots
44+
* @param data container data used to sync numeric state
45+
* @param blockEntity optional block entity this menu is bound to, or `null` if not bound
4546
*/
4647
public WorkbenchWorkbenchMenu(int syncId, Inventory playerInventory, Container container, ContainerData data, @Nullable AbstractWorkbenchEntity blockEntity) {
4748
super(ModMenuTypes.WORKBENCH_WORKBENCH_MENU, syncId, container, data, containerDataSize, playerInventory, Constants.INPUT_START + 1, 6);
4849
this.blockEntity = blockEntity;
4950
}
5051

52+
/**
53+
* Accesses the block entity bound to this menu, if present.
54+
*
55+
* @return the bound AbstractWorkbenchEntity, or {@code null} if this menu is not bound to a block entity
56+
*/
5157
@Override
5258
public @Nullable AbstractWorkbenchEntity getBlockEntity() {
5359
return this.blockEntity;
5460
}
5561

62+
/**
63+
* Populate the provided StackedItemContents with the items currently present in this menu's crafting slots so the recipe book can evaluate available recipes.
64+
*
65+
* @param stackedItemContents container to be filled with consolidated item counts from the menu's crafting/container slots
66+
*/
5667
@Override
5768
public void fillCraftSlotsStackedContents(StackedItemContents stackedItemContents) {
5869
// This is vital for the recipe book to "see" what is currently in your furnace.
@@ -62,11 +73,23 @@ public void fillCraftSlotsStackedContents(StackedItemContents stackedItemContent
6273
}
6374
}
6475

76+
/**
77+
* Identifies the recipe book category used by this menu.
78+
*
79+
* @return the crafting recipe book type, `RecipeBookType.CRAFTING`.
80+
*/
6581
@Override
6682
public RecipeBookType getRecipeBookType() {
6783
return RecipeBookType.CRAFTING;
6884
}
6985

86+
/**
87+
* Creates a WorkbenchRecipeInput using the current items in the menu's left and right input slots.
88+
*
89+
* The left input is read from index {@code Constants.INPUT_START} and the right input from {@code inputEnd}.
90+
*
91+
* @return a WorkbenchRecipeInput containing the items currently in the left and right input slots
92+
*/
7093
@Override
7194
public WorkbenchRecipeInput createRecipeInput() {
7295
// We grab the items currently sitting in the container at indices 0 and 1

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ public class ModBlockEntities {
2626
ModBlocks.WORKBENCH_WORKBENCH_BLOCK
2727
);
2828

29-
// Helper method to register AND add to map simultaneously
29+
/**
30+
* Register a BlockEntityType for the given furnace tier and store it in the tier map.
31+
*
32+
* @param tier the furnace tier whose BlockEntityType will be registered
33+
* @param block the block to associate with the registered BlockEntityType; must not be null
34+
* @return the registered BlockEntityType for the specified furnace tier
35+
* @throws IllegalStateException if {@code block} is null
36+
*/
3037
private static BlockEntityType<FurnaceWorkbenchEntity> registerTier(ModTiers.FurnaceTier tier, Block block) {
3138
// If 'block' is null here, the game WILL crash later.
3239
// We can check it now to prove the theory:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ public class ModBlocks {
9090
public static final Block WILD_WISTERIA_WOOD = register("wild_wisteria_wood", RotatedPillarBlock::new, BlockBehaviour.Properties.of().mapColor(MapColor.DIRT).instrument(NoteBlockInstrument.BASS).strength(2.0F).sound(SoundType.WOOD).ignitedByLava(), true);
9191

9292
/**
93-
* Registers this mod's blocks into the Functional Blocks creative tab and records the registration.
93+
* Registers the mod's workbench and furnace blocks into the Functional Blocks creative tab and logs the registration.
9494
*
95-
* Adds CAMPFIRE_WORKBENCH_BLOCK and FURNACE_WORKBENCH_BLOCK to CreativeModeTabs.FUNCTIONAL_BLOCKS and prints a registration message including the mod ID.
95+
* Specifically registers CAMPFIRE_WORKBENCH_BLOCK, WORKBENCH_WORKBENCH_BLOCK, FURNACE_WORKBENCH_BLOCK_T1, and FURNACE_WORKBENCH_BLOCK_T2, then prints a message containing the mod ID.
9696
*/
9797
public static void initialize() {
9898
ItemGroupEvents.modifyEntriesEvent(CreativeModeTabs.FUNCTIONAL_BLOCKS).register(entries -> {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public class ModRecipeDisplay {
3333

3434
public static final RecipeBookCategory FURNACE_T1_SEARCH = registerCategory("furnace_t1_recipe_book_category");
3535

36+
/**
37+
* Registers the workbench recipe display type into the built-in recipe display registry.
38+
*
39+
* The registration uses this mod's ID combined with the path "workbench_recipe_display" as the identifier.
40+
*/
3641
public static void initialize() {
3742
// Register the Display TYPE
3843
Registry.register(
@@ -49,4 +54,4 @@ private static RecipeBookCategory registerCategory(String name) {
4954
// Register it in the game's internal registry
5055
return Registry.register(BuiltInRegistries.RECIPE_BOOK_CATEGORY, id, category);
5156
}
52-
}
57+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public class ModRecipes {
2828
public static final RecipeSerializer<WorkbenchRecipe> WORKBENCH_SERIALIZER =
2929
new WorkbenchRecipe.Serializer(WORKBENCH_TYPE);
3030

31+
/**
32+
* Registers the mod's recipe types and their serializers into the game's built-in registries.
33+
*
34+
* Specifically registers the furnace (FURNACE_T1_TYPE), campfire (CAMPFIRE_TYPE),
35+
* and workbench (WORKBENCH_TYPE) recipe types with their corresponding serializers.
36+
*/
3137
public static void initialize() {
3238
// Register the Furnace-flavored version
3339
register(FURNACE_T1_TYPE.toString(), FURNACE_T1_TYPE, FURNACE_SERIALIZER);

0 commit comments

Comments
 (0)