Skip to content

Commit 50d3a52

Browse files
Merge pull request #17 from CodeMonkeysMods/coderabbitai/docstrings/32cd980
📝 Add docstrings to `feat/add-furnace-block-basics`
2 parents 32cd980 + 152d88d commit 50d3a52

13 files changed

Lines changed: 440 additions & 22 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import net.minecraft.client.gui.screens.MenuScreens;
88

99
public class MineTaleClient implements ClientModInitializer {
10+
/**
11+
* Registers the screen factory for the furnace workbench menu so the client can create FurnaceWorkbenchScreen instances for that menu type.
12+
*/
1013
@Override
1114
public void onInitializeClient() {
1215
MenuScreens.register(ModMenuTypes.FURNACE_WORKBENCH_MENU, FurnaceWorkbenchScreen::new);

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,48 @@ public class FurnaceWorkbenchScreen extends AbstractContainerScreen<FurnaceWorkb
1414
// Identifier.fromNamespaceAndPath(MineTale.MOD_ID, "textures/gui/container/furnace_workbench.png");
1515
Identifier.withDefaultNamespace("textures/gui/container/furnace.png");
1616

17+
/**
18+
* Creates a new furnace workbench screen for the given menu, player inventory, and title.
19+
*
20+
* @param menu the container menu that provides slots and syncs state for this screen
21+
* @param inventory the player's inventory to display and interact with
22+
* @param title the title component shown at the top of the screen
23+
*/
1724
public FurnaceWorkbenchScreen(FurnaceWorkbenchMenu menu, Inventory inventory, Component title) {
1825
super(menu, inventory, title);
1926
}
2027

28+
/**
29+
* Initializes the screen and centers the title horizontally by setting {@code titleLabelX}.
30+
*/
2131
@Override
2232
protected void init() {
2333
super.init();
2434
this.titleLabelX = (this.imageWidth - this.font.width(this.title)) / 2;
2535
}
2636

27-
protected void renderBg(GuiGraphics guiGraphics, float f, int i, int j) {
37+
/**
38+
* Draws the furnace workbench background texture onto the screen.
39+
*
40+
* @param guiGraphics the graphics context used for drawing
41+
* @param f partial tick time used for interpolation
42+
* @param i current mouse x position
43+
* @param j current mouse y position
44+
*/
45+
protected void renderBg(GuiGraphics guiGraphics, float f, int i, int j) {
2846
int k = this.leftPos;
2947
int l = this.topPos;
3048
guiGraphics.blit(RenderPipelines.GUI_TEXTURED, TEXTURE, k, l, 0.0F, 0.0F, this.imageWidth, this.imageHeight, 256, 256);
3149
}
3250

51+
/**
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+
*/
3359
@Override
3460
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
3561
renderBackground(graphics, mouseX, mouseY, delta);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ public class MineTale implements ModInitializer {
2020
// That way, it's clear which mod wrote info, warnings, and errors.
2121
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
2222

23+
/**
24+
* Initializes and registers the mod's game content and subsystems during Fabric startup.
25+
*
26+
* <p>Triggers initialization for blocks, block entities, menu types, entities, items, and entity
27+
* data serializers so they are registered with the game before gameplay begins.</p>
28+
*/
2329
@Override
2430
public void onInitialize() {
2531
ModBlocks.initialize();

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,23 @@ private boolean isCompatiblePart(BlockState current, BlockState neighbor) {
134134
return true;
135135
}
136136

137+
/**
138+
* Registers the block state properties used by this block.
139+
*
140+
* @param builder the state builder to populate with this block's properties (`FACING`, `HALF`, `TYPE`)
141+
*/
137142
@Override
138143
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
139144
builder.add(FACING, HALF, TYPE);
140145
}
141146

147+
/**
148+
* Create the block entity for the primary anchor of a multipart workbench.
149+
*
150+
* @param pos the position where the block entity would be created
151+
* @param state the block state at the position
152+
* @return the new block entity when this block is the primary anchor (lower half with TYPE `LEFT` or `SINGLE`), or `null` if this block is a secondary part
153+
*/
142154
@Nullable
143155
@Override
144156
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
@@ -158,6 +170,16 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
158170
return null;
159171
}
160172

173+
/**
174+
* Open the workbench menu for the block's master part when a player interacts without an item.
175+
*
176+
* @param state the block state at the clicked position
177+
* @param level the level in which the interaction occurs
178+
* @param pos the position of the block that was interacted with
179+
* @param player the player performing the interaction
180+
* @param hitResult details about the hit (hit position and face)
181+
* @return {@code InteractionResult.CONSUME} if a menu was opened on the server, {@code InteractionResult.SUCCESS} on the client, {@code InteractionResult.PASS} otherwise
182+
*/
161183
@Override
162184
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) {
163185
if (level.isClientSide()) {
@@ -178,6 +200,18 @@ protected InteractionResult useWithoutItem(BlockState state, Level level, BlockP
178200
return InteractionResult.PASS;
179201
}
180202

203+
/**
204+
* Compute the master (bottom-left) anchor position for this workbench block.
205+
*
206+
* The master is the block that serves as the primary anchor for multi-block
207+
* behavior and block-entity placement: if this block is the upper half the
208+
* master is one block below; if this block is the right-side part the master
209+
* is one block to the left relative to the block's facing.
210+
*
211+
* @param state the block state used to determine HALF, TYPE, and FACING
212+
* @param pos the current block position
213+
* @return the position of the master (bottom-left) block for this workbench
214+
*/
181215
public BlockPos getMasterPos(BlockState state, BlockPos pos) {
182216
BlockPos master = pos;
183217
Direction facing = state.getValue(FACING);

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

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,22 @@ public class CampfireWorkbench extends AbstractWorkbench<CampfireWorkbenchEntity
3434
public static final MapCodec<CampfireWorkbench> CODEC = simpleCodec((properties) ->
3535
new CampfireWorkbench(properties, () -> null));
3636

37+
/**
38+
* Creates a CampfireWorkbench configured to use the mod's CAMPFIRE_WORKBENCH_BE block entity type.
39+
*
40+
* @param properties block properties used to construct this workbench
41+
*/
3742
public CampfireWorkbench(Properties properties) {
3843
// Hardcode the supplier and sounds here if they never change
3944
super(properties, () -> ModBlockEntities.CAMPFIRE_WORKBENCH_BE, IS_WIDE, IS_TALL);
4045
}
4146

47+
/**
48+
* Creates a CampfireWorkbench with the given block properties and block-entity type supplier.
49+
*
50+
* @param properties the block's properties
51+
* @param supplier supplier that provides the BlockEntityType for this workbench
52+
*/
4253
public CampfireWorkbench(Properties properties, Supplier<BlockEntityType<? extends CampfireWorkbenchEntity>> supplier) {
4354
// isWide = false, isTall = false (1x1 footprint)
4455
super(properties, supplier, IS_WIDE, IS_TALL);
@@ -49,6 +60,11 @@ protected MapCodec<? extends CampfireWorkbench> codec() {
4960
return CODEC;
5061
}
5162

63+
/**
64+
* Specifies that this block is rendered using its block model.
65+
*
66+
* @return RenderShape.MODEL to render the block using its JSON/model representation.
67+
*/
5268
@Override
5369
public RenderShape getRenderShape(BlockState state) {
5470
// BaseEntityBlock defaults to INVISIBLE.
@@ -58,11 +74,22 @@ public RenderShape getRenderShape(BlockState state) {
5874

5975
private static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 7, 16);
6076

77+
/**
78+
* Gets the block's collision and interaction shape.
79+
*
80+
* @return the voxel shape representing the block's collision and interaction bounds
81+
*/
6182
@Override
6283
public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
6384
return SHAPE;
6485
}
6586

87+
/**
88+
* Creates and returns the block entity for this block only when the block represents the master
89+
* position (the lower half and not of type RIGHT).
90+
*
91+
* @return the created BlockEntity when this block is the master (HALF == LOWER and TYPE != RIGHT), or `null` otherwise
92+
*/
6693
@Nullable
6794
@Override
6895
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
@@ -73,6 +100,20 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
73100
return null;
74101
}
75102

103+
/**
104+
* Handles a player's interaction with the workbench when no item is used.
105+
*
106+
* <p>On the client this acknowledges the interaction. On the server this method
107+
* is a hook for workbench-specific handling; if the workbench processes the
108+
* interaction it will consume it, otherwise the interaction is passed to other handlers.</p>
109+
*
110+
* @param state the block state of the workbench
111+
* @param level the world in which the interaction occurs
112+
* @param pos the position of the interacted block
113+
* @param player the player performing the interaction
114+
* @param hit the hit result describing the interaction point
115+
* @return {@code InteractionResult.SUCCESS} on client, {@code InteractionResult.CONSUME} if handled by the workbench, or {@code InteractionResult.PASS} otherwise
116+
*/
76117
@Override
77118
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hit) {
78119
if (level.isClientSide()) return InteractionResult.SUCCESS;
@@ -89,6 +130,13 @@ protected InteractionResult useWithoutItem(BlockState state, Level level, BlockP
89130
return InteractionResult.PASS;
90131
}
91132

133+
/**
134+
* Compute the master (base) block position for this block based on its state.
135+
*
136+
* @param state the block state of the current block
137+
* @param pos the position of the current block
138+
* @return the position of the master (base) block: if the block is the upper half, the block below is used; if the block's type is `RIGHT`, the position is offset one block counterclockwise from its facing direction; otherwise the original position
139+
*/
92140
public BlockPos getMasterPos(BlockState state, BlockPos pos) {
93141
BlockPos master = pos;
94142
Direction facing = state.getValue(FACING);
@@ -97,4 +145,4 @@ public BlockPos getMasterPos(BlockState state, BlockPos pos) {
97145
return master;
98146
}
99147

100-
}
148+
}

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

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,49 @@ public class FurnaceWorkbench extends AbstractWorkbench<FurnaceWorkbenchEntity>
2424
public static final MapCodec<FurnaceWorkbench> CODEC = simpleCodec(FurnaceWorkbench::new);
2525

2626
/**
27-
* Standard constructor for registration.
27+
* Creates a FurnaceWorkbench using the default furnace workbench block entity type and a 2×2 footprint.
28+
*
29+
* @param properties block properties for this workbench
2830
*/
2931
public FurnaceWorkbench(Properties properties) {
3032
super(properties, () -> ModBlockEntities.FURNACE_WORKBENCH_BE, IS_WIDE, IS_TALL);
3133
}
3234

3335
/**
34-
* Flexible constructor allowing for specialized Block Entity Types.
36+
* Creates a FurnaceWorkbench that uses a custom BlockEntityType supplier and a 2x2 footprint.
37+
*
38+
* @param properties block properties for this workbench
39+
* @param supplier supplies the BlockEntityType to use for the workbench's master block entity
3540
*/
3641
public FurnaceWorkbench(Properties properties, Supplier<BlockEntityType<? extends FurnaceWorkbenchEntity>> supplier) {
3742
super(properties, supplier, IS_WIDE, IS_TALL);
3843
}
3944

45+
/**
46+
* Ensures the block is rendered using its model so the 2x2 workbench model is visible.
47+
*
48+
* @return {@code RenderShape.MODEL} to render the block with its model
49+
*/
4050
@Override
4151
public RenderShape getRenderShape(BlockState state) {
4252
// Essential so that the 2x2 model is visible
4353
return RenderShape.MODEL;
4454
}
4555

56+
/**
57+
* Provides a ticker that drives furnace workbench logic for the master block.
58+
*
59+
* The returned ticker invokes {@link FurnaceWorkbenchEntity#tick(Level, BlockPos, BlockState)} on the master
60+
* workbench block's entity when the supplied `type` matches the furnace workbench block entity type;
61+
* otherwise no ticker is provided.
62+
*
63+
* @param <T> block entity type
64+
* @param level the level in which the ticker will run
65+
* @param state the block state for which the ticker is requested
66+
* @param type the block entity type being ticked
67+
* @return a ticker that calls `FurnaceWorkbenchEntity.tick(...)` for the master furnace workbench entity, or
68+
* `null` if the provided `type` does not match the furnace workbench block entity type
69+
*/
4670
@Nullable
4771
@Override
4872
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
@@ -55,6 +79,11 @@ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, Block
5579
});
5680
}
5781

82+
/**
83+
* Create the block entity for this block; only the master block of the multi-block workbench receives an entity.
84+
*
85+
* @return the created {@link BlockEntity} for the master block, or `null` if this position does not host an entity
86+
*/
5887
@Nullable
5988
@Override
6089
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
@@ -63,9 +92,14 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
6392
return super.newBlockEntity(pos, state);
6493
}
6594

66-
@Override
95+
/**
96+
* Supply the codec used to serialize and deserialize this FurnaceWorkbench.
97+
*
98+
* @return the MapCodec for this FurnaceWorkbench
99+
*/
100+
@Override
67101
protected MapCodec<? extends FurnaceWorkbench> codec() {
68102
return CODEC;
69103
}
70104

71-
}
105+
}

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

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,38 @@ public abstract class AbstractWorkbenchEntity extends BlockEntity implements Men
2121
protected int tier = 1;
2222
protected double scanRadius = 5.0;
2323

24+
/**
25+
* Creates a new workbench block entity instance.
26+
*
27+
* @param type the BlockEntityType for this entity
28+
* @param pos the world position of the block entity
29+
* @param state the block state at the position
30+
*/
2431
public AbstractWorkbenchEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
2532
super(type, pos, state);
2633
}
2734

28-
// --- TIER SYSTEM ---
35+
/**
36+
* Gets the workstation's current tier.
37+
*
38+
* @return the current tier value
39+
*/
2940
public int getTier() { return tier; }
30-
public void setTier(int tier) { this.tier = tier; setChanged(); }
41+
/**
42+
* Sets the workstation's tier and marks the block entity as changed.
43+
*
44+
* @param tier the new tier value for this workstation
45+
*/
46+
public void setTier(int tier) { this.tier = tier; setChanged(); }
3147

32-
// --- CHEST SCANNING ---
48+
/**
49+
* Collects nearby inventory-containing block entities within the configured scan radius and vertical range.
50+
*
51+
* Scans a square area centered on this entity from -scanRadius..+scanRadius on X/Z and -2..+2 on Y, gathers any
52+
* block entities implementing `Container`, and returns them sorted by increasing distance to this entity.
53+
*
54+
* @return a list of nearby `Container` instances sorted by proximity; an empty list if none are found or if the world (`level`) is null
55+
*/
3356
public List<Container> getNearbyInventories() {
3457
List<Container> inventories = new ArrayList<>();
3558
if (level == null) {
@@ -55,20 +78,39 @@ public List<Container> getNearbyInventories() {
5578
return inventories;
5679
}
5780

58-
// --- RECYCLER LOGIC ---
81+
/**
82+
* Attempt to recycle an ItemStack into component items and distribute those components to nearby inventories or drop them at the workbench location.
83+
*
84+
* <p>The base implementation is a no-op; subclasses should override to perform actual recycling. Implementations are expected to insert resulting items into nearby Container block entities when possible and otherwise spawn the items at this entity's world position.</p>
85+
*
86+
* @param stack the ItemStack to recycle
87+
*/
5988
public void attemptRecycle(ItemStack stack) {
6089
// Logic to break down stack.getItem() and return components
6190
// to nearby chests or drop them at worldPosition.
6291
}
6392

93+
/**
94+
* Create the container menu presented to the player when they open this workbench.
95+
*
96+
* @param syncId the window synchronization id provided by the client
97+
* @param playerInventory the player's inventory
98+
* @param player the player opening the menu
99+
* @return the created AbstractContainerMenu, or `null` if no menu should be opened
100+
*/
64101
@Nullable
65102
@Override
66103
public abstract AbstractContainerMenu createMenu(int syncId, Inventory playerInventory, Player player);
67104

105+
/**
106+
* Provides the display name for this workbench block.
107+
*
108+
* @return a translatable Component created from the block's description ID
109+
*/
68110
@Override
69111
public Component getDisplayName() {
70112
return Component.translatable(this.getBlockState().getBlock().getDescriptionId());
71113
}
72114

73115

74-
}
116+
}

0 commit comments

Comments
 (0)