Skip to content

Commit ef31203

Browse files
📝 Add docstrings to feat/add-furnace-block-basics
Docstrings generation was requested by @The-Code-Monkey. * #18 (comment) The following files were modified: * `src/client/java/com/tcm/MineTale/MineTaleClient.java` * `src/client/java/com/tcm/MineTale/block/workbenches/screen/CampfireWorkbenchScreen.java` * `src/main/java/com/tcm/MineTale/block/workbenches/CampfireWorkbench.java` * `src/main/java/com/tcm/MineTale/block/workbenches/entity/AbstractWorkbenchEntity.java` * `src/main/java/com/tcm/MineTale/block/workbenches/entity/CampfireWorkbenchEntity.java` * `src/main/java/com/tcm/MineTale/block/workbenches/entity/FurnaceWorkbenchEntity.java` * `src/main/java/com/tcm/MineTale/block/workbenches/menu/AbstractWorkbenchContainerMenu.java` * `src/main/java/com/tcm/MineTale/block/workbenches/menu/CampfireWorkbenchMenu.java` * `src/main/java/com/tcm/MineTale/block/workbenches/menu/FurnaceWorkbenchMenu.java` * `src/main/java/com/tcm/MineTale/datagen/ModDataGenerator.java` * `src/main/java/com/tcm/MineTale/datagen/ModRecipeProvider.java` * `src/main/java/com/tcm/MineTale/datagen/builders/WorkbenchRecipeBuilder.java` * `src/main/java/com/tcm/MineTale/recipe/WorkbenchRecipe.java` * `src/main/java/com/tcm/MineTale/recipe/WorkbenchRecipeInput.java` * `src/main/java/com/tcm/MineTale/registry/ModRecipes.java` * `src/main/java/com/tcm/MineTale/util/Constants.java`
1 parent d0b26c3 commit ef31203

16 files changed

Lines changed: 421 additions & 62 deletions

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
import net.minecraft.client.gui.screens.MenuScreens;
99

1010
public class MineTaleClient implements ClientModInitializer {
11+
/**
12+
* Registers client-side screen factories for custom workbench menu types.
13+
*
14+
* Binds the furnace and campfire workbench menu types to their corresponding screen constructors
15+
* so the client can create the appropriate GUI when those menus are opened.
16+
*/
1117
@Override
1218
public void onInitializeClient() {
1319
MenuScreens.register(ModMenuTypes.FURNACE_WORKBENCH_MENU, FurnaceWorkbenchScreen::new);

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public class CampfireWorkbenchScreen extends AbstractContainerScreen<CampfireWor
1515
Identifier.withDefaultNamespace("textures/gui/container/furnace.png");
1616

1717
/**
18-
* Creates a new furnace workbench screen for the given menu, player inventory, and title.
18+
* Creates a campfire workbench screen for the provided menu, player inventory, and title.
1919
*
20-
* @param menu the container menu that provides slots and syncs state for this screen
20+
* @param menu the container menu that provides slots and synchronizes state for this screen
2121
* @param inventory the player's inventory to display and interact with
2222
* @param title the title component shown at the top of the screen
2323
*/
@@ -35,10 +35,10 @@ protected void init() {
3535
}
3636

3737
/**
38-
* Draws the furnace workbench background texture onto the screen.
38+
* Renders the campfire workbench background texture at the screen's top-left position.
3939
*
4040
* @param guiGraphics the graphics context used for drawing
41-
* @param f partial tick time used for interpolation
41+
* @param f partial ticks for interpolation
4242
* @param i current mouse x position
4343
* @param j current mouse y position
4444
*/
@@ -49,13 +49,13 @@ protected void renderBg(GuiGraphics guiGraphics, float f, int i, int j) {
4949
}
5050

5151
/**
52-
* Renders the furnace workbench screen, drawing its background, contents, and tooltips.
53-
*
54-
* @param graphics the graphics context used for rendering
55-
* @param mouseX the current mouse X coordinate
56-
* @param mouseY the current mouse Y coordinate
57-
* @param delta the frame time delta (partial tick) used for animated rendering
58-
*/
52+
* Renders the campfire workbench screen, drawing its background, contents, and tooltips.
53+
*
54+
* @param graphics the graphics context used for rendering
55+
* @param mouseX the current mouse X coordinate
56+
* @param mouseY the current mouse Y coordinate
57+
* @param delta the frame time delta (partial tick) used for animated rendering
58+
*/
5959
@Override
6060
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
6161
renderBackground(graphics, mouseX, mouseY, delta);

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,33 @@ public CampfireWorkbench(Properties properties) {
4343
}
4444

4545
/**
46-
* Creates a CampfireWorkbench with the given block properties and block-entity type supplier.
46+
* Constructs a CampfireWorkbench using the provided block properties and block-entity type supplier.
4747
*
48-
* @param properties the block's properties
49-
* @param supplier supplier that provides the BlockEntityType for this workbench
48+
* @param properties block properties to apply to this workbench
49+
* @param supplier supplier that provides the BlockEntityType for the CampfireWorkbenchEntity
5050
*/
5151
public CampfireWorkbench(Properties properties, Supplier<BlockEntityType<? extends CampfireWorkbenchEntity>> supplier) {
5252
// isWide = false, isTall = false (1x1 footprint)
5353
super(properties, supplier, IS_WIDE, IS_TALL);
5454
}
5555

56-
// In your CampfireWorkbenchBlock.java (The Block class)
56+
/**
57+
* Provides a ticker that updates campfire workbench block entities each tick.
58+
*
59+
* @return a BlockEntityTicker that invokes AbstractWorkbenchEntity.tick for CampfireWorkbenchEntity instances, or `null` if the supplied block entity type does not match the campfire workbench type.
60+
*/
5761
@Nullable
5862
@Override
5963
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
6064
// This connects the Level's ticking system to your static tick method
6165
return createTickerHelper(type, ModBlockEntities.CAMPFIRE_WORKBENCH_BE, AbstractWorkbenchEntity::tick);
6266
}
6367

68+
/**
69+
* The codec used to serialize and deserialize this CampfireWorkbench type.
70+
*
71+
* @return the MapCodec for this CampfireWorkbench
72+
*/
6473
@Override
6574
protected MapCodec<? extends CampfireWorkbench> codec() {
6675
return CODEC;
@@ -91,9 +100,11 @@ public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, Co
91100
}
92101

93102
/**
94-
* Create the block entity for this block; only the master block of the multi-block workbench receives an entity.
103+
* Create a block entity for the master block of this workbench.
104+
*
105+
* Only the master block of the multi-block workbench receives an entity; other positions return {@code null}.
95106
*
96-
* @return the created {@link BlockEntity} for the master block, or `null` if this position does not host an entity
107+
* @return the block entity for the master block ({@link CampfireWorkbenchEntity}), or {@code null} if this position does not host an entity
97108
*/
98109
@Nullable
99110
@Override

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

Lines changed: 87 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,28 @@ public AbstractWorkbenchEntity(BlockEntityType<?> type, BlockPos pos, BlockState
4747
}
4848

4949
/**
50-
* Subclasses (Campfire/Furnace) must define which recipe type they look for.
51-
*/
50+
* Specifies the RecipeType used by this workbench to look up WorkbenchRecipe instances.
51+
*
52+
* Implementations must return the RecipeType corresponding to the recipe family this workbench processes (for example, campfire- or furnace-style recipes).
53+
*
54+
* @return the RecipeType for this workbench's WorkbenchRecipe
55+
*/
5256
public abstract RecipeType<WorkbenchRecipe> getWorkbenchRecipeType();
5357

54-
public static void tick(Level level, BlockPos pos, BlockState state, AbstractWorkbenchEntity entity) {
58+
/**
59+
* Performs a single server-side tick for the given workbench entity: looks up a matching WorkbenchRecipe
60+
* for the entity's input slots and, if possible, advances crafting progress, consumes fuel/inputs,
61+
* inserts results into output slots, and updates block-entity state.
62+
*
63+
* This method will set or reset the entity's progress and maxProgress according to the found recipe,
64+
* invoke craft(...) when progress completes, and call setChanged(...) to mark the block entity as modified.
65+
*
66+
* @param level the world where the workbench resides; must provide a server RecipeManager for recipe lookup
67+
* @param pos the block position of the workbench
68+
* @param state the current block state at the workbench position
69+
* @param entity the workbench block entity to tick; this object is mutated (progress, maxProgress, inventory)
70+
*/
71+
public static void tick(Level level, BlockPos pos, BlockState state, AbstractWorkbenchEntity entity) {
5572
// 1. Create the input wrapper using the internal SimpleContainer
5673
// Slot 1 = Input A, Slot 2 = Input B
5774
WorkbenchRecipeInput input = new WorkbenchRecipeInput(
@@ -125,8 +142,20 @@ public static void tick(Level level, BlockPos pos, BlockState state, AbstractWor
125142
}
126143
}
127144

128-
public ItemStack getItem(int slot) { return this.inventory.getItem(slot); }
145+
/**
146+
* Retrieve the ItemStack stored in the given inventory slot.
147+
*
148+
* @param slot the index of the inventory slot to read
149+
* @return the ItemStack in the specified slot; may be an empty stack if the slot is empty
150+
*/
151+
public ItemStack getItem(int slot) { return this.inventory.getItem(slot); }
129152

153+
/**
154+
* Checks whether all result ItemStacks can be placed into the workbench's output slot range.
155+
*
156+
* @param results the list of result ItemStacks to validate
157+
* @return `true` if every stack in `results` has an available output slot (empty or able to accept the stack), `false` otherwise
158+
*/
130159
public boolean canFitOutputs(List<ItemStack> results) {
131160
for (ItemStack result : results) {
132161
// If we can't find a home for even one of the results, return false
@@ -137,6 +166,17 @@ public boolean canFitOutputs(List<ItemStack> results) {
137166
return true;
138167
}
139168

169+
/**
170+
* Finds a suitable output slot between the given indices (inclusive) for placing the specified result stack.
171+
*
172+
* The method returns the first index that is either empty or already contains the same item with the same
173+
* components and has enough space to accommodate the result's count.
174+
*
175+
* @param result the stack to place into an output slot
176+
* @param start the starting slot index (inclusive)
177+
* @param end the ending slot index (inclusive)
178+
* @return the index of a suitable slot, or -1 if no such slot exists
179+
*/
140180
public int findOutputSlot(ItemStack result, int start, int end) {
141181
for (int i = start; i <= end; i++) {
142182
ItemStack stack = getItem(i);
@@ -151,14 +191,33 @@ public int findOutputSlot(ItemStack result, int start, int end) {
151191
return -1;
152192
}
153193

194+
/**
195+
* Get the number of slots in this entity's internal inventory.
196+
*
197+
* @return the number of slots in the internal inventory
198+
*/
154199
public int getContainerSize() {
155200
return this.inventory.getContainerSize();
156201
}
157202

203+
/**
204+
* Check whether the workbench's internal inventory contains no items.
205+
*
206+
* @return `true` if the internal inventory contains no items, `false` otherwise.
207+
*/
158208
public boolean isEmpty() {
159209
return this.inventory.isEmpty();
160210
}
161211

212+
/**
213+
* Consume one item from each input slot and insert the recipe's results into the workbench output slots.
214+
*
215+
* Each non-empty result is placed into the first suitable output slot in the configured output range:
216+
* if the slot is empty the result is copied into it; if the slot contains the same item the stack is increased.
217+
* Results that cannot be placed (no suitable output slot) are skipped.
218+
*
219+
* @param recipe the WorkbenchRecipe whose results will be produced and placed into outputs
220+
*/
162221
protected void craft(WorkbenchRecipe recipe) {
163222
// 1. Consume 1 from each ingredient slot (Slots 1 and 2)
164223
this.removeItem(Constants.INPUT_1, 1);
@@ -184,6 +243,13 @@ protected void craft(WorkbenchRecipe recipe) {
184243
}
185244
}
186245

246+
/**
247+
* Remove up to the specified number of items from the given inventory slot.
248+
*
249+
* @param slot the index of the slot to remove items from
250+
* @param amount the maximum number of items to remove
251+
* @return the ItemStack removed from the slot, or an empty stack if nothing was removed
252+
*/
187253
public ItemStack removeItem(int slot, int amount) {
188254
// SimpleContainer has its own removeItem logic built-in
189255
ItemStack result = this.inventory.removeItem(slot, amount);
@@ -193,6 +259,12 @@ public ItemStack removeItem(int slot, int amount) {
193259
return result;
194260
}
195261

262+
/**
263+
* Places the given ItemStack into the specified inventory slot, clamps its count to the stack limit, and marks the block entity as changed.
264+
*
265+
* @param slot the index of the inventory slot to set
266+
* @param stack the ItemStack to put into the slot; if its count exceeds the item's max stack size it will be reduced to that maximum
267+
*/
196268
public void setItem(int slot, ItemStack stack) {
197269
// Use setItem(), not set()
198270
this.inventory.setItem(slot, stack);
@@ -204,7 +276,11 @@ public void setItem(int slot, ItemStack stack) {
204276
this.setChanged();
205277
}
206278

207-
// Subclasses handle fuel logic (Campfires might return true always, Furnaces check slot 2)
279+
/**
280+
* Indicates whether this workbench currently has fuel available to perform crafting.
281+
*
282+
* @return `true` if the workbench has fuel available, `false` otherwise.
283+
*/
208284
protected abstract boolean hasFuel();
209285

210286
/**
@@ -254,10 +330,13 @@ public List<Container> getNearbyInventories() {
254330
}
255331

256332
/**
257-
* Finds the first output slot that can accept the given result.
333+
* Locate the first slot in the given inventory range that can accept the provided result stack.
258334
*
259-
* @param result the item stack to place into an output slot
260-
* @return the index of the first suitable output slot between OUTPUT_START and OUTPUT_END, or -1 if none is available
335+
* @param result the stack to place into an output slot
336+
* @param inventory the container to search
337+
* @param start inclusive start index of the search range
338+
* @param end inclusive end index of the search range
339+
* @return the index of a slot that is empty or contains the same item with enough space for the result, or -1 if none found
261340
*/
262341
public int findOutputSlot(ItemStack result, SimpleContainer inventory, int start, int end) {
263342
for (int i = start; i <= end; i++) {

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

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ public int getCount() {
8181
};
8282

8383
/**
84-
* Creates a CampfireWorkbenchEntity at the given position with the provided block state.
84+
* Creates a CampfireWorkbenchEntity for the specified world position and block state.
8585
*
86-
* Initializes the entity's scan radius to 6.0 and tier to 1.
86+
* Sets the entity's scanRadius to 0.0 and tier to 1.
8787
*
8888
* @param blockPos the world position of this block entity
8989
* @param blockState the block state for this block entity
@@ -95,6 +95,12 @@ public CampfireWorkbenchEntity(BlockPos blockPos, BlockState blockState) {
9595
this.tier = 1;
9696
}
9797

98+
/**
99+
* Performs server-side per-tick updates for this workbench.
100+
*
101+
* <p>This method is a no-op on the client and exits immediately; server-side update logic
102+
* should be implemented here.
103+
*/
98104
public void tick(Level level, BlockPos pos, BlockState state) {
99105
if (level.isClientSide()) return;
100106
}
@@ -140,11 +146,12 @@ protected void saveAdditional(ValueOutput valueOutput) {
140146
}
141147

142148
/**
143-
* Restores workbench-specific state from persistent storage and applies defaults when keys are absent.
149+
* Restores workbench-specific state from persistent storage, applying defaults when keys are absent.
144150
*
145-
* Delegates to the superclass load logic, then reads:
146-
* - "WorkbenchTier" (int) into {@code tier}, defaulting to {@code 1} if missing.
147-
* - "ScanRadius" (double) into {@code scanRadius}, defaulting to {@code 5.0} if missing.
151+
* Delegates to the superclass load logic, then:
152+
* - reads "WorkbenchTier" (int) into {@code tier}, defaulting to {@code 1} if missing;
153+
* - reads "ScanRadius" (double) into {@code scanRadius}, defaulting to {@code 0.0} if missing;
154+
* - reads "Inventory" as a list of {@code ItemStack} and populates the internal inventory up to its capacity.
148155
*/
149156
@Override
150157
protected void loadAdditional(ValueInput valueInput) {
@@ -161,16 +168,36 @@ protected void loadAdditional(ValueInput valueInput) {
161168
});
162169
}
163170

171+
/**
172+
* Create the server-side container menu for the campfire workbench UI.
173+
*
174+
* @param syncId window id used to synchronize the menu with the client
175+
* @param playerInventory the opening player's inventory
176+
* @param player the player who opened the menu
177+
* @return a CampfireWorkbenchMenu tied to this workbench's inventory and sync data
178+
*/
164179
@Override
165180
public @Nullable AbstractContainerMenu createMenu(int syncId, Inventory playerInventory, Player player) {
166181
return new CampfireWorkbenchMenu(syncId, playerInventory, this.inventory, this.data);
167182
}
168183

184+
/**
185+
* Specifies which recipe type this workbench uses.
186+
*
187+
* @return the campfire workbench recipe type used to look up and match recipes
188+
*/
169189
@Override
170190
public RecipeType<WorkbenchRecipe> getWorkbenchRecipeType() {
171191
return ModRecipes.CAMPFIRE_TYPE;
172192
}
173193

194+
/**
195+
* Determines whether the workbench currently has fuel available.
196+
*
197+
* Checks that the entity is in a loaded level and that the configured fuel slot contains an item.
198+
*
199+
* @return `true` if the entity is in a loaded level and the fuel slot contains an item, `false` otherwise.
200+
*/
174201
@Override
175202
protected boolean hasFuel() {
176203
if (this.level == null) return false;

0 commit comments

Comments
 (0)