Skip to content

Commit a61e73c

Browse files
Merge pull request #50 from CodeMonkeysMods/coderabbitai/docstrings/f1072ef
📝 Add docstrings to `Loot-Table-Update`
2 parents f1072ef + 195cb1f commit a61e73c

6 files changed

Lines changed: 89 additions & 12 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
public class MineTaleDataGen implements DataGeneratorEntrypoint {
99

1010
/**
11-
* Initialize a data pack and register the mod's data providers.
11+
* Initialize a data pack and register the mod's data providers for data generation.
1212
*
13-
* Creates a data pack from the given Fabric data generator and adds the language
14-
* and model providers so they will run during data generation.
13+
* Registers language, model, recipe, block tag, and loot table providers so they
14+
* will run as part of the Fabric data generation pack created from the given generator.
1515
*
1616
* @param fabricDataGenerator the Fabric data generator used to create the data pack
1717
*/

src/client/java/com/tcm/MineTale/datagen/ModBlockTagProvider.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ public ModBlockTagProvider(FabricDataOutput output, CompletableFuture<HolderLook
2121
}
2222

2323
/**
24-
* Populates the BlockTags.LOGS tag with this mod's log blocks.
24+
* Populate block tags with this mod's blocks.
2525
*
26-
* Registers each mod-defined log block so they are included in the game's LOGS tag mapping.
26+
* Adds mod-defined blocks to relevant vanilla block tags (for example
27+
* MINEABLE_WITH_PICKAXE, MINEABLE_WITH_AXE, and LOGS) so they are included
28+
* in the game's tag mappings.
2729
*
28-
* @param provider a registry lookup provider used to resolve holders during tag population
30+
* @param provider registry lookup provider used to resolve holders during tag population
2931
*/
3032
@Override
3133
protected void addTags(HolderLookup.Provider provider) {

src/client/java/com/tcm/MineTale/datagen/ModLootTableProvider.java

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,25 @@
2828
import java.util.concurrent.CompletableFuture;
2929

3030
public class ModLootTableProvider extends FabricBlockLootTableProvider {
31+
/**
32+
* Creates a ModLootTableProvider used to generate the mod's block loot tables.
33+
*
34+
* Initializes the provider with the data output target and a future registry lookup used to resolve game registries during loot table generation.
35+
*
36+
* @param dataOutput the data output target for generated data
37+
* @param registryLookup a future that provides a HolderLookup.Provider for resolving registries needed while generating loot tables
38+
*/
3139
public ModLootTableProvider(FabricDataOutput dataOutput, CompletableFuture<HolderLookup.Provider> registryLookup) {
3240
super(dataOutput, registryLookup);
3341
}
3442

43+
/**
44+
* Registers loot tables for the mod's workbench blocks.
45+
*
46+
* Each added loot table causes the block to drop itself (one item) only when the block's state
47+
* matches the required DoubleBlockHalf (LOWER) and ChestType (LEFT or SINGLE) for that block,
48+
* and the drop is subject to explosion survival/decay.
49+
*/
3550
@Override
3651
public void generate() {
3752
///Block Drops Itself
@@ -113,27 +128,50 @@ public void generate() {
113128

114129

115130
/// For Ore Drops
116-
/** Ex:
117-
* add(ModBlocks.IRON_ORE_SHALE, AverageOreDrops(ModBlocks.IRON_ORE_SHALE, Items.RAW_IRON));
118-
* **/
131+
/**
132+
* Create a loot table builder that drops the specified item in multiple quantities with Silk Touch, Fortune bonus, and explosion decay applied.
133+
*
134+
* @param drop the source block used for Silk Touch dispatch and explosion-decay context
135+
* @param item the item to drop from the ore
136+
* @return a LootTable.Builder that drops `item` in a base count between 2 and 5, augmented by the Fortune enchantment, with Silk Touch handling and explosion decay applied
137+
*/
119138
public LootTable.Builder AverageOreDrops(Block drop, Item item) {
120139
HolderLookup.RegistryLookup<Enchantment> impl = this.registries.lookupOrThrow(Registries.ENCHANTMENT);
121140
return this.createSilkTouchDispatchTable(drop, this.applyExplosionDecay(drop, ((LootPoolSingletonContainer.Builder<?>)
122141
LootItem.lootTableItem(item).apply(SetItemCountFunction.setCount(UniformGenerator.between(2, 5))))
123142
.apply(ApplyBonusCount.addOreBonusCount(impl.getOrThrow(Enchantments.FORTUNE)))));
124143
}
125144

145+
/**
146+
* Creates a loot table builder for an ore that yields the specified item with Silk Touch and Fortune handling.
147+
*
148+
* The table gives a base drop count of exactly 1 (before Fortune), increases the count with Fortune, returns the
149+
* ore block when mined with Silk Touch, and applies explosion decay to the drop.
150+
*
151+
* @param drop the ore block (returned when Silk Touch is used)
152+
* @param item the item to drop when the ore is mined without Silk Touch
153+
* @return a LootTable.Builder configured to drop the specified item with Fortune bonuses, Silk Touch dispatch,
154+
* and explosion decay
155+
*/
126156
public LootTable.Builder SingleOreDrops(Block drop, Item item) {
127157
HolderLookup.RegistryLookup<Enchantment> impl = this.registries.lookupOrThrow(Registries.ENCHANTMENT);
128158
return this.createSilkTouchDispatchTable(drop, this.applyExplosionDecay(drop, ((LootPoolSingletonContainer.Builder<?>)
129159
LootItem.lootTableItem(item).apply(SetItemCountFunction.setCount(ConstantValue.exactly(1))))
130160
.apply(ApplyBonusCount.addOreBonusCount(impl.getOrThrow(Enchantments.FORTUNE)))));
131161
}
132162

163+
/**
164+
* Builds a loot table for a "light" ore block that supports Silk Touch, Fortune bonuses, and explosion decay.
165+
*
166+
* @param drop the ore block whose loot table is being created
167+
* @param item the item to drop from the ore when not Silk Touched
168+
* @return a LootTable.Builder that drops {@code item} in quantities of 1–2 (before Fortune), applies Fortune bonus,
169+
* dispatches to Silk Touch drops when applicable, and respects explosion decay
170+
*/
133171
public LootTable.Builder LightOreDrops(Block drop, Item item) {
134172
HolderLookup.RegistryLookup<Enchantment> impl = this.registries.lookupOrThrow(Registries.ENCHANTMENT);
135173
return this.createSilkTouchDispatchTable(drop, this.applyExplosionDecay(drop, ((LootPoolSingletonContainer.Builder<?>)
136174
LootItem.lootTableItem(item).apply(SetItemCountFunction.setCount(UniformGenerator.between(1, 2))))
137175
.apply(ApplyBonusCount.addOreBonusCount(impl.getOrThrow(Enchantments.FORTUNE)))));
138176
}
139-
}
177+
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,16 @@ public void onInitialize() {
135135
LOGGER.info("MineTale Loaded!");
136136
}
137137

138-
private boolean hasIngredients(ServerPlayer player, WorkbenchRecipe recipe) {
138+
/**
139+
* Determines whether the player (and nearby pullable chests, if the workbench allows) collectively contain all item ingredients required by the given workbench recipe.
140+
*
141+
* This check requires the player's open container to be an AbstractWorkbenchContainerMenu; if it is not, the method returns `false`. It examines the player's non-equipment inventory and, when the workbench permits pulling, the contents of nearby inventories. Each recipe ingredient must be satisfied by a distinct matching item instance from those inventories.
142+
*
143+
* @param player the server player whose inventories are checked
144+
* @param recipe the workbench recipe whose ingredient requirements are being validated
145+
* @return `true` if all ingredients of the recipe can be satisfied from the player and allowed nearby inventories, `false` otherwise
146+
*/
147+
private boolean hasIngredients(ServerPlayer player, WorkbenchRecipe recipe) {
139148
if (!(player.containerMenu instanceof AbstractWorkbenchContainerMenu menu)) return false;
140149
AbstractWorkbenchEntity be = menu.getBlockEntity();
141150

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,24 @@ protected float getShadeBrightness(BlockState state, BlockGetter level, BlockPos
355355
return 1.0F;
356356
}
357357

358+
/**
359+
* Handle teardown of a multi-block workbench when a player destroys one of its parts,
360+
* ensuring the master/slave parts are removed consistently and loot is produced exactly once.
361+
*
362+
* <p>Server-side behavior:
363+
* - Computes the master (bottom-left) position for the workbench and whether the broken part is the master.
364+
* - Iterates the workbench footprint (2x2 if wide and tall, or the corresponding subset) and removes other parts:
365+
* - If the master is broken, other parts are removed silently (no drops).
366+
* - If a slave is broken, the master is destroyed (producing drops unless the player is in creative) and other slaves are removed silently.
367+
* - Emits GameEvent.BLOCK_DESTROY for each part that is removed.
368+
* - If a slave was broken by a non-creative player, prevents the slave part itself from dropping to avoid duplicate loot.
369+
*
370+
* @param level the world where the destruction occurs
371+
* @param pos the position of the part being destroyed
372+
* @param state the block state of the part being destroyed (may be modified to suppress drops)
373+
* @param player the player performing the destruction
374+
* @return the BlockState returned by the superclass implementation after custom teardown handling
375+
*/
358376
@Override
359377
public BlockState playerWillDestroy(Level level, BlockPos pos, BlockState state, Player player) {
360378
if (!level.isClientSide()) {

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ public class ModLootTableModifiers {
1313
private static final Identifier SHORT_GRASS_ID = Identifier.fromNamespaceAndPath("minecraft", "blocks/short_grass");
1414
private static final Identifier TALL_GRASS_ID = Identifier.fromNamespaceAndPath("minecraft", "blocks/tall_grass");
1515

16+
/**
17+
* Registers a listener that modifies the loot tables for short and tall grass.
18+
*
19+
* <p>When the listener sees the short grass loot table, it replaces its pools with a single-roll
20+
* pool that can produce AIR (count exactly 1) and STICK (count between 1 and 3). When the listener
21+
* sees the tall grass loot table, it replaces its pools with a single-roll pool that can produce
22+
* STICK (weight 1, count between 1 and 4).
23+
*
24+
* <p>This method registers the modification via LootTableEvents.MODIFY.
25+
*/
1626
public static void modifyLootTables() {
1727
LootTableEvents.MODIFY.register((key, tableBuilder, sources, registry) -> {
1828
if (SHORT_GRASS_ID.equals(key.identifier())) {
@@ -34,4 +44,4 @@ public static void modifyLootTables() {
3444
}
3545
});
3646
}
37-
}
47+
}

0 commit comments

Comments
 (0)