@@ -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 ++) {
0 commit comments