BlockLootSubProvider .java

net.minecraft.data.loot.BlockLootSubProvider (class): members: createSilkTouchOrShearsDispatchTable, createSingleItemTableWithSilkTouch, noDrop, dropSelf.

net.minecraft.data.lootclass889 linescommon32.5 KB

Implements

API Surface (58)

Holder<LootItemCondition> hasSilkTouch()
LootItemCondition.Builder doesNotHaveSilkTouch()
Holder<LootItemCondition> hasShears()
LootItemCondition.Builder hasShearsOrSilkTouch()
LootItemCondition.Builder doesNotHaveShearsOrSilkTouch()
<T extends FunctionUserBuilder<T>> T applyExplosionDecay(final ItemLike type, final FunctionUserBuilder<T> builder)
<T extends ConditionUserBuilder<T>> T applyExplosionCondition(final ItemLike type, final ConditionUserBuilder<T> builder)
LootTable.Builder createSingleItemTable(final ItemLike drop)
LootTable.Builder createSelfDropDispatchTable(final Block original, final Holder<LootItemCondition> condition, final LootPoolEntryContainer.Builder<?> entry)
LootTable.Builder createSilkTouchDispatchTable(final Block original, final LootPoolEntryContainer.Builder<?> entry)
LootTable.Builder createShearsDispatchTable(final Block original, final LootPoolEntryContainer.Builder<?> entry)
LootTable.Builder createSilkTouchOrShearsDispatchTable(final Block original, final LootPoolEntryContainer.Builder<?> entry)
LootTable.Builder createSingleItemTableWithSilkTouch(final Block original, final ItemLike drop)
LootTable.Builder createSingleItemTable(final ItemLike drop, final Holder<ContextIntProvider> count)
LootTable.Builder createSingleItemTableWithSilkTouch(final Block original, final ItemLike drop, final Holder<ContextIntProvider> count)
LootTable.Builder createSilkTouchOnlyTable(final ItemLike drop)
LootTable.Builder createPotFlowerItemTable(final ItemLike flower)
LootTable.Builder createSlabItemTable(final Block slab)
LootTable.Builder createNameableBlockEntityTable(final Block drop)
LootTable.Builder createShulkerBoxDrop(final Block shulkerBox)
LootTable.Builder createCopperOreDrops(final Block block)
LootTable.Builder createLapisOreDrops(final Block block)
LootTable.Builder createRedstoneOreDrops(final Block block)
LootTable.Builder createBannerDrop(final Block original)
LootTable.Builder createBeeNestDrop(final Block original)
LootTable.Builder createBeeHiveDrop(final Block original)
LootTable.Builder createCaveVinesDrop(final Block original)
LootTable.Builder createCopperGolemStatueBlock(final Block block)
LootTable.Builder createOreDrop(final Block original, final Item drop)
LootTable.Builder createMushroomBlockDrop(final Block original, final ItemLike drop)
LootTable.Builder createGrassDrops(final Block original)
LootTable.Builder createStemDrops(final Block block, final Item drop)
LootTable.Builder createAttachedStemDrops(final Block block, final Item drop)
LootTable.Builder createShearsOnlyDrop(final ItemLike drop)
LootTable.Builder createShearsOrSilkTouchOnlyDrop(final ItemLike drop)
LootTable.Builder createMultifaceBlockDrops(final Block block, final Holder<LootItemCondition> condition)
LootTable.Builder createMultifaceBlockDrops(final Block block)
LootTable.Builder createMossyCarpetBlockDrops(final Block block)
LootTable.Builder createLeavesDrops(final Block original, final Block sapling, final float... saplingChances)
LootTable.Builder createOakLeavesDrops(final Block original, final Block sapling, final float... saplingChances)
LootTable.Builder createMangroveLeavesDrops(final Block block)
LootTable.Builder createCropDrops(final Block original, final Item cropDrop, final Item seedDrop, final LootItemCondition.Builder isMaxAge)
LootTable.Builder createDoublePlantShearsDrop(final Block block)
LootTable.Builder createDoublePlantWithSeedDrops(final Block block, final Block drop)
LootTable.Builder createCandleDrops(final Block block)
LootTable.Builder createSegmentedBlockDrops(final Block block)
LootTable.Builder createCandleCakeDrops(final Block candle)
LootTable.Builder noDrop()
void run()
void addNetherVinesDropTable(final Block vineBlock, final Block plantBlock)
LootTable.Builder createDoorTable(final Block block)
void dropPottedContents(final Block potted)
void otherWhenSilkTouch(final Block block, final Block other)
void dropOther(final Block block, final ItemLike drop)
void dropWhenSilkTouch(final Block block)
void dropSelf(final Block block)
void add(final Block block, final Function<Block, LootTable.Builder> builder)
void add(final Block block, final LootTable.Builder builder)

Fields & Constants (12)

NORMAL_LEAVES_SAPLING_CHANCES
NORMAL_LEAVES_STICK_CHANCES
output
enchantments
items
blocks
predicates
explosionResistant
enabledFeatures
map
condition
property

String literals (3)

"Created block loot tables for non-blocks: "
"Block "
" does not have loot table"

Code Graph: Dependencies (61)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

BlockLootSubProvider.java889 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.data.loot;
2
3
import java.util.HashMap;
4
import java.util.HashSet;
5
import java.util.List;
6
import java.util.Locale;
7
import java.util.Map;
8
import java.util.Set;
9
import java.util.function.Function;
10
import java.util.stream.IntStream;
11
import net.fabricmc.fabric.api.datagen.v1.loot.FabricBlockLootSubProvider;
12
import net.minecraft.advancements.predicates.BlockPredicate;
13
import net.minecraft.advancements.predicates.LocationPredicate;
14
import net.minecraft.advancements.predicates.StatePropertiesPredicate;
15
import net.minecraft.core.Direction;
16
import net.minecraft.core.Holder;
17
import net.minecraft.core.HolderGetter;
18
import net.minecraft.core.component.DataComponents;
19
import net.minecraft.core.registries.BuiltInRegistries;
20
import net.minecraft.core.registries.Registries;
21
import net.minecraft.resources.ResourceKey;
22
import net.minecraft.util.StringRepresentable;
23
import net.minecraft.world.flag.FeatureFlagSet;
24
import net.minecraft.world.item.Item;
25
import net.minecraft.world.item.Items;
26
import net.minecraft.world.item.enchantment.Enchantment;
27
import net.minecraft.world.item.enchantment.Enchantments;
28
import net.minecraft.world.level.ItemLike;
29
import net.minecraft.world.level.block.BeehiveBlock;
30
import net.minecraft.world.level.block.Block;
31
import net.minecraft.world.level.block.Blocks;
32
import net.minecraft.world.level.block.CandleBlock;
33
import net.minecraft.world.level.block.CaveVines;
34
import net.minecraft.world.level.block.CopperGolemStatueBlock;
35
import net.minecraft.world.level.block.DoorBlock;
36
import net.minecraft.world.level.block.DoublePlantBlock;
37
import net.minecraft.world.level.block.FlowerPotBlock;
38
import net.minecraft.world.level.block.MossyCarpetBlock;
39
import net.minecraft.world.level.block.MultifaceBlock;
40
import net.minecraft.world.level.block.SegmentableBlock;
41
import net.minecraft.world.level.block.SlabBlock;
42
import net.minecraft.world.level.block.StemBlock;
43
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
44
import net.minecraft.world.level.block.state.properties.Property;
45
import net.minecraft.world.level.block.state.properties.SlabType;
46
import net.minecraft.world.level.storage.loot.IntLimit;
47
import net.minecraft.world.level.storage.loot.LootPool;
48
import net.minecraft.world.level.storage.loot.LootTable;
49
import net.minecraft.world.level.storage.loot.entries.LootItem;
50
import net.minecraft.world.level.storage.loot.entries.LootPoolEntryContainer;
51
import net.minecraft.world.level.storage.loot.entries.UniformContainerBase;
52
import net.minecraft.world.level.storage.loot.functions.ApplyBonusCount;
53
import net.minecraft.world.level.storage.loot.functions.ApplyExplosionDecay;
54
import net.minecraft.world.level.storage.loot.functions.CopyBlockState;
55
import net.minecraft.world.level.storage.loot.functions.CopyComponentsFunction;
56
import net.minecraft.world.level.storage.loot.functions.FunctionUserBuilder;
57
import net.minecraft.world.level.storage.loot.functions.LimitCount;
58
import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction;
59
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
60
import net.minecraft.world.level.storage.loot.predicates.AnyOfCondition;
61
import net.minecraft.world.level.storage.loot.predicates.BonusLevelTableCondition;
62
import net.minecraft.world.level.storage.loot.predicates.ConditionUserBuilder;
63
import net.minecraft.world.level.storage.loot.predicates.ExplosionCondition;
64
import net.minecraft.world.level.storage.loot.predicates.InvertedLootItemCondition;
65
import net.minecraft.world.level.storage.loot.predicates.LocationCheck;
66
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
67
import net.minecraft.world.level.storage.loot.predicates.LootItemRandomChanceCondition;
68
import net.minecraft.world.level.storage.loot.predicates.LootPredicates;
69
import net.minecraft.world.level.storage.loot.predicates.MatchBlock;
70
import net.minecraft.world.level.storage.loot.providers.number.ints.ContextIntProvider;
71
import net.minecraft.world.level.storage.loot.providers.number.ints.ContextIntProviders;
72
73
/**
74
 * Access widened by fabric-data-generation-api-v1 to accessible
75
 */
76
public abstract class BlockLootSubProvider implements LootTableSubProvider, FabricBlockLootSubProvider {
77
	protected final LootTableSubProvider.Context output;
78
	protected final HolderGetter<Enchantment> enchantments;
79
	protected final HolderGetter<Item> items;
80
	protected final HolderGetter<Block> blocks;
81
	protected final HolderGetter<LootItemCondition> predicates;
82
	private final Set<Item> explosionResistant;
83
	private final FeatureFlagSet enabledFeatures;
84
	private final Map<ResourceKey<LootTable>, LootTable.Builder> map = new HashMap<>();
85
	protected static final float[] NORMAL_LEAVES_SAPLING_CHANCES = new float[]{0.05F, 0.0625F, 0.083333336F, 0.1F};
86
	private static final float[] NORMAL_LEAVES_STICK_CHANCES = new float[]{0.02F, 0.022222223F, 0.025F, 0.033333335F, 0.1F};
87
88
	protected BlockLootSubProvider(final Set<Item> explosionResistant, final FeatureFlagSet enabledFeatures, final LootTableSubProvider.Context output) {
89
		this.explosionResistant = explosionResistant;
90
		this.enabledFeatures = enabledFeatures;
91
		this.output = output;
92
		this.enchantments = output.lookup(Registries.ENCHANTMENT);
93
		this.items = output.lookup(Registries.ITEM);
94
		this.blocks = output.lookup(Registries.BLOCK);
95
		this.predicates = output.lookup(Registries.PREDICATE);
96
	}
97
98
	/**
99
	 * Access widened by fabric-data-generation-api-v1 to accessible
100
	 */
101
	public Holder<LootItemCondition> hasSilkTouch() {
102
		return this.predicates.getOrThrow(LootPredicates.TOOL_CAN_SILK_TOUCH);
103
	}
104
105
	/**
106
	 * Access widened by fabric-data-generation-api-v1 to accessible
107
	 */
108
	public LootItemCondition.Builder doesNotHaveSilkTouch() {
109
		return InvertedLootItemCondition.invert(this.hasSilkTouch());
110
	}
111
112
	/**
113
	 * Access widened by fabric-data-generation-api-v1 to accessible
114
	 */
115
	public Holder<LootItemCondition> hasShears() {
116
		return this.predicates.getOrThrow(LootPredicates.TOOL_CAN_SHEAR);
117
	}
118
119
	/**
120
	 * Access widened by fabric-data-generation-api-v1 to accessible
121
	 */
122
	public final LootItemCondition.Builder hasShearsOrSilkTouch() {
123
		return new AnyOfCondition.Builder().or(this.hasShears()).or(this.hasSilkTouch());
124
	}
125
126
	/**
127
	 * Access widened by fabric-data-generation-api-v1 to accessible
128
	 */
129
	public final LootItemCondition.Builder doesNotHaveShearsOrSilkTouch() {
130
		return this.hasShearsOrSilkTouch().invert();
131
	}
132
133
	/**
134
	 * Access widened by fabric-data-generation-api-v1 to accessible
135
	 */
136
	public <T extends FunctionUserBuilder<T>> T applyExplosionDecay(final ItemLike type, final FunctionUserBuilder<T> builder) {
137
		return !this.explosionResistant.contains(type.asItem()) ? builder.apply(ApplyExplosionDecay.explosionDecay()) : builder.unwrap();
138
	}
139
140
	/**
141
	 * Access widened by fabric-data-generation-api-v1 to accessible
142
	 */
143
	public <T extends ConditionUserBuilder<T>> T applyExplosionCondition(final ItemLike type, final ConditionUserBuilder<T> builder) {
144
		return !this.explosionResistant.contains(type.asItem()) ? builder.when(ExplosionCondition.survivesExplosion()) : builder.unwrap();
145
	}
146
147
	public LootTable.Builder createSingleItemTable(final ItemLike drop) {
148
		return LootTable.lootTable()
149
			.withPool(this.applyExplosionCondition(drop, LootPool.lootPool().setRolls(ContextIntProviders.exactly(1)).add(LootItem.lootTableItem(drop))));
150
	}
151
152
	/**
153
	 * Access widened by fabric-data-generation-api-v1 to accessible
154
	 */
155
	public static LootTable.Builder createSelfDropDispatchTable(
156
		final Block original, final Holder<LootItemCondition> condition, final LootPoolEntryContainer.Builder<?> entry
157
	) {
158
		return LootTable.lootTable()
159
			.withPool(LootPool.lootPool().setRolls(ContextIntProviders.exactly(1)).add(LootItem.lootTableItem(original).when(condition).otherwise(entry)));
160
	}
161
162
	/**
163
	 * Access widened by fabric-data-generation-api-v1 to accessible
164
	 */
165
	public LootTable.Builder createSilkTouchDispatchTable(final Block original, final LootPoolEntryContainer.Builder<?> entry) {
166
		return createSelfDropDispatchTable(original, this.hasSilkTouch(), entry);
167
	}
168
169
	/**
170
	 * Access widened by fabric-data-generation-api-v1 to accessible
171
	 */
172
	public LootTable.Builder createShearsDispatchTable(final Block original, final LootPoolEntryContainer.Builder<?> entry) {
173
		return createSelfDropDispatchTable(original, this.hasShears(), entry);
174
	}
175
176
	/**
177
	 * Access widened by fabric-data-generation-api-v1 to accessible
178
	 */
179
	public LootTable.Builder createSilkTouchOrShearsDispatchTable(final Block original, final LootPoolEntryContainer.Builder<?> entry) {
180
		return createSelfDropDispatchTable(original, Holder.direct(this.hasShearsOrSilkTouch().build()), entry);
181
	}
182
183
	/**
184
	 * Access widened by fabric-data-generation-api-v1 to accessible
185
	 */
186
	public LootTable.Builder createSingleItemTableWithSilkTouch(final Block original, final ItemLike drop) {
187
		return this.createSilkTouchDispatchTable(original, (LootPoolEntryContainer.Builder<?>)this.applyExplosionCondition(original, LootItem.lootTableItem(drop)));
188
	}
189
190
	/**
191
	 * Access widened by fabric-data-generation-api-v1 to accessible
192
	 */
193
	public LootTable.Builder createSingleItemTable(final ItemLike drop, final Holder<ContextIntProvider> count) {
194
		return LootTable.lootTable()
195
			.withPool(
196
				LootPool.lootPool()
197
					.setRolls(ContextIntProviders.exactly(1))
198
					.add((LootPoolEntryContainer.Builder<?>)this.applyExplosionDecay(drop, LootItem.lootTableItem(drop).apply(SetItemCountFunction.setCount(count))))
199
			);
200
	}
201
202
	/**
203
	 * Access widened by fabric-data-generation-api-v1 to accessible
204
	 */
205
	public LootTable.Builder createSingleItemTableWithSilkTouch(final Block original, final ItemLike drop, final Holder<ContextIntProvider> count) {
206
		return this.createSilkTouchDispatchTable(
207
			original, (LootPoolEntryContainer.Builder<?>)this.applyExplosionDecay(original, LootItem.lootTableItem(drop).apply(SetItemCountFunction.setCount(count)))
208
		);
209
	}
210
211
	/**
212
	 * Access widened by fabric-data-generation-api-v1 to accessible
213
	 */
214
	public final LootTable.Builder createSilkTouchOnlyTable(final ItemLike drop) {
215
		return LootTable.lootTable()
216
			.withPool(LootPool.lootPool().when(this.hasSilkTouch()).setRolls(ContextIntProviders.exactly(1)).add(LootItem.lootTableItem(drop)));
217
	}
218
219
	/**
220
	 * Access widened by fabric-data-generation-api-v1 to accessible
221
	 */
222
	public final LootTable.Builder createPotFlowerItemTable(final ItemLike flower) {
223
		return LootTable.lootTable()
224
			.withPool(
225
				this.applyExplosionCondition(Blocks.FLOWER_POT, LootPool.lootPool().setRolls(ContextIntProviders.exactly(1)).add(LootItem.lootTableItem(Blocks.FLOWER_POT)))
226
			)
227
			.withPool(this.applyExplosionCondition(flower, LootPool.lootPool().setRolls(ContextIntProviders.exactly(1)).add(LootItem.lootTableItem(flower))));
228
	}
229
230
	/**
231
	 * Access widened by fabric-data-generation-api-v1 to accessible
232
	 */
233
	public LootTable.Builder createSlabItemTable(final Block slab) {
234
		return LootTable.lootTable()
235
			.withPool(
236
				LootPool.lootPool()
237
					.setRolls(ContextIntProviders.exactly(1))
238
					.add(
239
						(LootPoolEntryContainer.Builder<?>)this.applyExplosionDecay(
240
							slab,
241
							LootItem.lootTableItem(slab)
242
								.apply(
243
									SetItemCountFunction.setCount(ContextIntProviders.exactly(2))
244
										.when(MatchBlock.blockMatches(this.blocks, slab, StatePropertiesPredicate.Builder.properties().hasProperty(SlabBlock.TYPE, SlabType.DOUBLE)))
245
								)
246
						)
247
					)
248
			);
249
	}
250
251
	/**
252
	 * Access widened by fabric-data-generation-api-v1 to accessible
253
	 */
254
	public <T extends Comparable<T> & StringRepresentable> LootTable.Builder createSinglePropConditionTable(
255
		final Block drop, final Property<T> property, final T value
256
	) {
257
		return LootTable.lootTable()
258
			.withPool(
259
				this.applyExplosionCondition(
260
					drop,
261
					LootPool.lootPool()
262
						.setRolls(ContextIntProviders.exactly(1))
263
						.add(
264
							LootItem.lootTableItem(drop)
265
								.when(MatchBlock.blockMatches(this.blocks, drop, StatePropertiesPredicate.Builder.properties().hasProperty(property, value)))
266
						)
267
				)
268
			);
269
	}
270
271
	/**
272
	 * Access widened by fabric-data-generation-api-v1 to accessible
273
	 */
274
	public LootTable.Builder createNameableBlockEntityTable(final Block drop) {
275
		return LootTable.lootTable()
276
			.withPool(
277
				this.applyExplosionCondition(
278
					drop,
279
					LootPool.lootPool()
280
						.setRolls(ContextIntProviders.exactly(1))
281
						.add(
282
							LootItem.lootTableItem(drop)
283
								.apply(CopyComponentsFunction.copyComponentsFromBlockEntity(LootContextParams.BLOCK_ENTITY).include(DataComponents.CUSTOM_NAME))
284
						)
285
				)
286
			);
287
	}
288
289
	/**
290
	 * Access widened by fabric-data-generation-api-v1 to accessible
291
	 */
292
	public LootTable.Builder createShulkerBoxDrop(final Block shulkerBox) {
293
		return LootTable.lootTable()
294
			.withPool(
295
				this.applyExplosionCondition(
296
					shulkerBox,
297
					LootPool.lootPool()
298
						.setRolls(ContextIntProviders.exactly(1))
299
						.add(
300
							LootItem.lootTableItem(shulkerBox)
301
								.apply(
302
									CopyComponentsFunction.copyComponentsFromBlockEntity(LootContextParams.BLOCK_ENTITY)
303
										.include(DataComponents.CUSTOM_NAME)
304
										.include(DataComponents.CONTAINER)
305
										.include(DataComponents.LOCK)
306
										.include(DataComponents.CONTAINER_LOOT)
307
								)
308
						)
309
				)
310
			);
311
	}
312
313
	/**
314
	 * Access widened by fabric-data-generation-api-v1 to accessible
315
	 */
316
	public LootTable.Builder createCopperOreDrops(final Block block) {
317
		return this.createSilkTouchDispatchTable(
318
			block,
319
			(LootPoolEntryContainer.Builder<?>)this.applyExplosionDecay(
320
				block,
321
				LootItem.lootTableItem(Items.RAW_COPPER)
322
					.apply(SetItemCountFunction.setCount(ContextIntProviders.between(2, 5)))
323
					.apply(ApplyBonusCount.addOreBonusCount(this.enchantments.getOrThrow(Enchantments.FORTUNE)))
324
			)
325
		);
326
	}
327
328
	/**
329
	 * Access widened by fabric-data-generation-api-v1 to accessible
330
	 */
331
	public LootTable.Builder createLapisOreDrops(final Block block) {
332
		return this.createSilkTouchDispatchTable(
333
			block,
334
			(LootPoolEntryContainer.Builder<?>)this.applyExplosionDecay(
335
				block,
336
				LootItem.lootTableItem(Items.LAPIS_LAZULI)
337
					.apply(SetItemCountFunction.setCount(ContextIntProviders.between(4, 9)))
338
					.apply(ApplyBonusCount.addOreBonusCount(this.enchantments.getOrThrow(Enchantments.FORTUNE)))
339
			)
340
		);
341
	}
342
343
	/**
344
	 * Access widened by fabric-data-generation-api-v1 to accessible
345
	 */
346
	public LootTable.Builder createRedstoneOreDrops(final Block block) {
347
		return this.createSilkTouchDispatchTable(
348
			block,
349
			(LootPoolEntryContainer.Builder<?>)this.applyExplosionDecay(
350
				block,
351
				LootItem.lootTableItem(Items.REDSTONE)
352
					.apply(SetItemCountFunction.setCount(ContextIntProviders.between(4, 5)))
353
					.apply(ApplyBonusCount.addUniformBonusCount(this.enchantments.getOrThrow(Enchantments.FORTUNE)))
354
			)
355
		);
356
	}
357
358
	/**
359
	 * Access widened by fabric-data-generation-api-v1 to accessible
360
	 */
361
	public LootTable.Builder createBannerDrop(final Block original) {
362
		return LootTable.lootTable()
363
			.withPool(
364
				this.applyExplosionCondition(
365
					original,
366
					LootPool.lootPool()
367
						.setRolls(ContextIntProviders.exactly(1))
368
						.add(
369
							LootItem.lootTableItem(original)
370
								.apply(
371
									CopyComponentsFunction.copyComponentsFromBlockEntity(LootContextParams.BLOCK_ENTITY)
372
										.include(DataComponents.CUSTOM_NAME)
373
										.include(DataComponents.ITEM_NAME)
374
										.include(DataComponents.TOOLTIP_DISPLAY)
375
										.include(DataComponents.BANNER_PATTERNS)
376
										.include(DataComponents.RARITY)
377
								)
378
						)
379
				)
380
			);
381
	}
382
383
	/**
384
	 * Access widened by fabric-data-generation-api-v1 to accessible
385
	 */
386
	public LootTable.Builder createBeeNestDrop(final Block original) {
387
		return LootTable.lootTable()
388
			.withPool(
389
				LootPool.lootPool()
390
					.when(this.hasSilkTouch())
391
					.setRolls(ContextIntProviders.exactly(1))
392
					.add(
393
						LootItem.lootTableItem(original)
394
							.apply(CopyComponentsFunction.copyComponentsFromBlockEntity(LootContextParams.BLOCK_ENTITY).include(DataComponents.BEES))
395
							.apply(CopyBlockState.copyState(original).copy(BeehiveBlock.HONEY_LEVEL))
396
					)
397
			);
398
	}
399
400
	/**
401
	 * Access widened by fabric-data-generation-api-v1 to accessible
402
	 */
403
	public LootTable.Builder createBeeHiveDrop(final Block original) {
404
		return LootTable.lootTable()
405
			.withPool(
406
				LootPool.lootPool()
407
					.setRolls(ContextIntProviders.exactly(1))
408
					.add(
409
						LootItem.lootTableItem(original)
410
							.when(this.hasSilkTouch())
411
							.apply(CopyComponentsFunction.copyComponentsFromBlockEntity(LootContextParams.BLOCK_ENTITY).include(DataComponents.BEES))
412
							.apply(CopyBlockState.copyState(original).copy(BeehiveBlock.HONEY_LEVEL))
413
							.otherwise(LootItem.lootTableItem(original))
414
					)
415
			);
416
	}
417
418
	/**
419
	 * Access widened by fabric-data-generation-api-v1 to accessible
420
	 */
421
	public LootTable.Builder createCaveVinesDrop(final Block original) {
422
		return LootTable.lootTable()
423
			.withPool(
424
				LootPool.lootPool()
425
					.add(LootItem.lootTableItem(Items.GLOW_BERRIES))
426
					.when(MatchBlock.blockMatches(this.blocks, original, StatePropertiesPredicate.Builder.properties().hasProperty(CaveVines.BERRIES, true)))
427
			);
428
	}
429
430
	/**
431
	 * Access widened by fabric-data-generation-api-v1 to accessible
432
	 */
433
	public LootTable.Builder createCopperGolemStatueBlock(final Block block) {
434
		return LootTable.lootTable()
435
			.withPool(
436
				this.applyExplosionCondition(
437
					block,
438
					LootPool.lootPool()
439
						.setRolls(ContextIntProviders.exactly(1))
440
						.add(
441
							LootItem.lootTableItem(block)
442
								.apply(CopyComponentsFunction.copyComponentsFromBlockEntity(LootContextParams.BLOCK_ENTITY).include(DataComponents.CUSTOM_NAME))
443
								.apply(CopyBlockState.copyState(block).copy(CopperGolemStatueBlock.POSE))
444
						)
445
				)
446
			);
447
	}
448
449
	/**
450
	 * Access widened by fabric-data-generation-api-v1 to accessible
451
	 */
452
	public LootTable.Builder createOreDrop(final Block original, final Item drop) {
453
		return this.createSilkTouchDispatchTable(
454
			original,
455
			(LootPoolEntryContainer.Builder<?>)this.applyExplosionDecay(
456
				original, LootItem.lootTableItem(drop).apply(ApplyBonusCount.addOreBonusCount(this.enchantments.getOrThrow(Enchantments.FORTUNE)))
457
			)
458
		);
459
	}
460
461
	/**
462
	 * Access widened by fabric-data-generation-api-v1 to accessible
463
	 */
464
	public LootTable.Builder createMushroomBlockDrop(final Block original, final ItemLike drop) {
465
		return this.createSilkTouchDispatchTable(
466
			original,
467
			(LootPoolEntryContainer.Builder<?>)this.applyExplosionDecay(
468
				original,
469
				LootItem.lootTableItem(drop).apply(SetItemCountFunction.setCount(ContextIntProviders.between(-6, 2))).apply(LimitCount.limitCount(IntLimit.lowerBound(0)))
470
			)
471
		);
472
	}
473
474
	/**
475
	 * Access widened by fabric-data-generation-api-v1 to accessible
476
	 */
477
	public LootTable.Builder createGrassDrops(final Block original) {
478
		return this.createShearsDispatchTable(
479
			original,
480
			(LootPoolEntryContainer.Builder<?>)this.applyExplosionDecay(
481
				original,
482
				LootItem.lootTableItem(Items.WHEAT_SEEDS)
483
					.when(LootItemRandomChanceCondition.randomChance(0.125F))
484
					.apply(ApplyBonusCount.addUniformBonusCount(this.enchantments.getOrThrow(Enchantments.FORTUNE), 2))
485
			)
486
		);
487
	}
488
489
	public LootTable.Builder createStemDrops(final Block block, final Item drop) {
490
		return LootTable.lootTable()
491
			.withPool(
492
				this.applyExplosionDecay(
493
					block,
494
					LootPool.lootPool()
495
						.setRolls(ContextIntProviders.exactly(1))
496
						.add(
497
							LootItem.lootTableItem(drop)
498
								.apply(
499
									StemBlock.AGE.getPossibleValues(),
500
									age -> SetItemCountFunction.setCount(ContextIntProviders.binomial(3, (age + 1) / 15.0F))
501
										.when(MatchBlock.blockMatches(this.blocks, block, StatePropertiesPredicate.Builder.properties().hasProperty(StemBlock.AGE, age.intValue())))
502
								)
503
						)
504
				)
505
			);
506
	}
507
508
	public LootTable.Builder createAttachedStemDrops(final Block block, final Item drop) {
509
		return LootTable.lootTable()
510
			.withPool(
511
				this.applyExplosionDecay(
512
					block,
513
					LootPool.lootPool()
514
						.setRolls(ContextIntProviders.exactly(1))
515
						.add(LootItem.lootTableItem(drop).apply(SetItemCountFunction.setCount(ContextIntProviders.binomial(3, 0.53333336F))))
516
				)
517
			);
518
	}
519
520
	/**
521
	 * Access widened by fabric-data-generation-api-v1 to accessible
522
	 */
523
	public LootTable.Builder createShearsOnlyDrop(final ItemLike drop) {
524
		return LootTable.lootTable().withPool(LootPool.lootPool().setRolls(ContextIntProviders.exactly(1)).when(this.hasShears()).add(LootItem.lootTableItem(drop)));
525
	}
526
527
	/**
528
	 * Access widened by fabric-data-generation-api-v1 to accessible
529
	 */
530
	public LootTable.Builder createShearsOrSilkTouchOnlyDrop(final ItemLike drop) {
531
		return LootTable.lootTable()
532
			.withPool(LootPool.lootPool().setRolls(ContextIntProviders.exactly(1)).when(this.hasShearsOrSilkTouch()).add(LootItem.lootTableItem(drop)));
533
	}
534
535
	/**
536
	 * Access widened by fabric-data-generation-api-v1 to accessible
537
	 */
538
	public LootTable.Builder createMultifaceBlockDrops(final Block block, final Holder<LootItemCondition> condition) {
539
		return LootTable.lootTable()
540
			.withPool(
541
				LootPool.lootPool()
542
					.add(
543
						(LootPoolEntryContainer.Builder<?>)this.applyExplosionDecay(
544
							block,
545
							LootItem.lootTableItem(block)
546
								.when(condition)
547
								.apply(
548
									Direction.values(),
549
									dir -> SetItemCountFunction.setCount(ContextIntProviders.exactly(1), true)
550
										.when(
551
											MatchBlock.blockMatches(this.blocks, block, StatePropertiesPredicate.Builder.properties().hasProperty(MultifaceBlock.getFaceProperty(dir), true))
552
										)
553
								)
554
								.apply(SetItemCountFunction.setCount(ContextIntProviders.exactly(-1), true))
555
						)
556
					)
557
			);
558
	}
559
560
	/**
561
	 * Access widened by fabric-data-generation-api-v1 to accessible
562
	 */
563
	public LootTable.Builder createMultifaceBlockDrops(final Block block) {
564
		return LootTable.lootTable()
565
			.withPool(
566
				LootPool.lootPool()
567
					.add(
568
						(LootPoolEntryContainer.Builder<?>)this.applyExplosionDecay(
569
							block,
570
							LootItem.lootTableItem(block)
571
								.apply(
572
									Direction.values(),
573
									dir -> SetItemCountFunction.setCount(ContextIntProviders.exactly(1), true)
574
										.when(
575
											MatchBlock.blockMatches(this.blocks, block, StatePropertiesPredicate.Builder.properties().hasProperty(MultifaceBlock.getFaceProperty(dir), true))
576
										)
577
								)
578
								.apply(SetItemCountFunction.setCount(ContextIntProviders.exactly(-1), true))
579
						)
580
					)
581
			);
582
	}
583
584
	/**
585
	 * Access widened by fabric-data-generation-api-v1 to accessible
586
	 */
587
	public LootTable.Builder createMossyCarpetBlockDrops(final Block block) {
588
		return LootTable.lootTable()
589
			.withPool(
590
				LootPool.lootPool()
591
					.add(
592
						(LootPoolEntryContainer.Builder<?>)this.applyExplosionDecay(
593
							block,
594
							LootItem.lootTableItem(block)
595
								.when(MatchBlock.blockMatches(this.blocks, block, StatePropertiesPredicate.Builder.properties().hasProperty(MossyCarpetBlock.BASE, true)))
596
						)
597
					)
598
			);
599
	}
600
601
	/**
602
	 * Access widened by fabric-data-generation-api-v1 to accessible
603
	 */
604
	public LootTable.Builder createLeavesDrops(final Block original, final Block sapling, final float... saplingChances) {
605
		return this.createSilkTouchOrShearsDispatchTable(
606
				original,
607
				(LootPoolEntryContainer.Builder<?>)((UniformContainerBase.Builder)this.applyExplosionCondition(original, LootItem.lootTableItem(sapling)))
608
					.when(BonusLevelTableCondition.bonusLevelFlatChance(this.enchantments.getOrThrow(Enchantments.FORTUNE), saplingChances))
609
			)
610
			.withPool(
611
				LootPool.lootPool()
612
					.setRolls(ContextIntProviders.exactly(1))
613
					.when(this.doesNotHaveShearsOrSilkTouch())
614
					.add(
615
						(LootPoolEntryContainer.Builder<?>)((UniformContainerBase.Builder)this.applyExplosionDecay(
616
								original, LootItem.lootTableItem(Items.STICK).apply(SetItemCountFunction.setCount(ContextIntProviders.between(1, 2)))
617
							))
618
							.when(BonusLevelTableCondition.bonusLevelFlatChance(this.enchantments.getOrThrow(Enchantments.FORTUNE), NORMAL_LEAVES_STICK_CHANCES))
619
					)
620
			);
621
	}
622
623
	/**
624
	 * Access widened by fabric-data-generation-api-v1 to accessible
625
	 */
626
	public LootTable.Builder createOakLeavesDrops(final Block original, final Block sapling, final float... saplingChances) {
627
		return this.createLeavesDrops(original, sapling, saplingChances)
628
			.withPool(
629
				LootPool.lootPool()
630
					.setRolls(ContextIntProviders.exactly(1))
631
					.when(this.doesNotHaveShearsOrSilkTouch())
632
					.add(
633
						(LootPoolEntryContainer.Builder<?>)((UniformContainerBase.Builder)this.applyExplosionCondition(original, LootItem.lootTableItem(Items.APPLE)))
634
							.when(
635
								BonusLevelTableCondition.bonusLevelFlatChance(this.enchantments.getOrThrow(Enchantments.FORTUNE), 0.005F, 0.0055555557F, 0.00625F, 0.008333334F, 0.025F)
636
							)
637
					)
638
			);
639
	}
640
641
	/**
642
	 * Access widened by fabric-data-generation-api-v1 to accessible
643
	 */
644
	public LootTable.Builder createMangroveLeavesDrops(final Block block) {
645
		return this.createSilkTouchOrShearsDispatchTable(
646
			block,
647
			(LootPoolEntryContainer.Builder<?>)((UniformContainerBase.Builder)this.applyExplosionDecay(
648
					Blocks.MANGROVE_LEAVES, LootItem.lootTableItem(Items.STICK).apply(SetItemCountFunction.setCount(ContextIntProviders.between(1, 2)))
649
				))
650
				.when(BonusLevelTableCondition.bonusLevelFlatChance(this.enchantments.getOrThrow(Enchantments.FORTUNE), NORMAL_LEAVES_STICK_CHANCES))
651
		);
652
	}
653
654
	/**
655
	 * Access widened by fabric-data-generation-api-v1 to accessible
656
	 */
657
	public LootTable.Builder createCropDrops(final Block original, final Item cropDrop, final Item seedDrop, final LootItemCondition.Builder isMaxAge) {
658
		return this.applyExplosionDecay(
659
			original,
660
			LootTable.lootTable()
661
				.withPool(LootPool.lootPool().add(LootItem.lootTableItem(cropDrop).when(isMaxAge).otherwise(LootItem.lootTableItem(seedDrop))))
662
				.withPool(
663
					LootPool.lootPool()
664
						.when(isMaxAge)
665
						.add(
666
							LootItem.lootTableItem(seedDrop)
667
								.apply(ApplyBonusCount.addBonusBinomialDistributionCount(this.enchantments.getOrThrow(Enchantments.FORTUNE), 0.5714286F, 3))
668
						)
669
				)
670
		);
671
	}
672
673
	/**
674
	 * Access widened by fabric-data-generation-api-v1 to accessible
675
	 */
676
	public LootTable.Builder createDoublePlantShearsDrop(final Block block) {
677
		return LootTable.lootTable()
678
			.withPool(LootPool.lootPool().when(this.hasShears()).add(LootItem.lootTableItem(block).apply(SetItemCountFunction.setCount(ContextIntProviders.exactly(2)))));
679
	}
680
681
	/**
682
	 * Access widened by fabric-data-generation-api-v1 to accessible
683
	 */
684
	public LootTable.Builder createDoublePlantWithSeedDrops(final Block block, final Block drop) {
685
		LootPoolEntryContainer.Builder<?> dropEntry = LootItem.lootTableItem(drop)
686
			.apply(SetItemCountFunction.setCount(ContextIntProviders.exactly(2)))
687
			.when(this.hasShears())
688
			.otherwise(
689
				(LootPoolEntryContainer.Builder<?>)((UniformContainerBase.Builder)this.applyExplosionCondition(block, LootItem.lootTableItem(Items.WHEAT_SEEDS)))
690
					.when(LootItemRandomChanceCondition.randomChance(0.125F))
691
			);
692
		return LootTable.lootTable()
693
			.withPool(
694
				LootPool.lootPool()
695
					.add(dropEntry)
696
					.when(MatchBlock.blockMatches(this.blocks, block, StatePropertiesPredicate.Builder.properties().hasProperty(DoublePlantBlock.HALF, DoubleBlockHalf.LOWER)))
697
					.when(
698
						LocationCheck.checkLocation(
699
							LocationPredicate.Builder.location()
700
								.setBlock(
701
									BlockPredicate.Builder.block()
702
										.of(this.blocks, block)
703
										.setProperties(StatePropertiesPredicate.Builder.properties().hasProperty(DoublePlantBlock.HALF, DoubleBlockHalf.UPPER))
704
								),
705
							Direction.UP
706
						)
707
					)
708
			)
709
			.withPool(
710
				LootPool.lootPool()
711
					.add(dropEntry)
712
					.when(MatchBlock.blockMatches(this.blocks, block, StatePropertiesPredicate.Builder.properties().hasProperty(DoublePlantBlock.HALF, DoubleBlockHalf.UPPER)))
713
					.when(
714
						LocationCheck.checkLocation(
715
							LocationPredicate.Builder.location()
716
								.setBlock(
717
									BlockPredicate.Builder.block()
718
										.of(this.blocks, block)
719
										.setProperties(StatePropertiesPredicate.Builder.properties().hasProperty(DoublePlantBlock.HALF, DoubleBlockHalf.LOWER))
720
								),
721
							Direction.DOWN
722
						)
723
					)
724
			);
725
	}
726
727
	/**
728
	 * Access widened by fabric-data-generation-api-v1 to accessible
729
	 */
730
	public LootTable.Builder createCandleDrops(final Block block) {
731
		return LootTable.lootTable()
732
			.withPool(
733
				LootPool.lootPool()
734
					.setRolls(ContextIntProviders.exactly(1))
735
					.add(
736
						(LootPoolEntryContainer.Builder<?>)this.applyExplosionDecay(
737
							block,
738
							LootItem.lootTableItem(block)
739
								.apply(
740
									List.of(2, 3, 4),
741
									count -> SetItemCountFunction.setCount(ContextIntProviders.exactly(count))
742
										.when(MatchBlock.blockMatches(this.blocks, block, StatePropertiesPredicate.Builder.properties().hasProperty(CandleBlock.CANDLES, count.intValue())))
743
								)
744
						)
745
					)
746
			);
747
	}
748
749
	public LootTable.Builder createSegmentedBlockDrops(final Block block) {
750
		return block instanceof SegmentableBlock segmentableBlock
751
			? LootTable.lootTable()
752
				.withPool(
753
					LootPool.lootPool()
754
						.setRolls(ContextIntProviders.exactly(1))
755
						.add(
756
							(LootPoolEntryContainer.Builder<?>)this.applyExplosionDecay(
757
								block,
758
								LootItem.lootTableItem(block)
759
									.apply(
760
										IntStream.rangeClosed(1, 4).boxed().toList(),
761
										count -> SetItemCountFunction.setCount(ContextIntProviders.exactly(count))
762
											.when(
763
												MatchBlock.blockMatches(
764
													this.blocks, block, StatePropertiesPredicate.Builder.properties().hasProperty(segmentableBlock.getSegmentAmountProperty(), count.intValue())
765
												)
766
											)
767
									)
768
							)
769
						)
770
				)
771
			: noDrop();
772
	}
773
774
	/**
775
	 * Access widened by fabric-data-generation-api-v1 to accessible
776
	 */
777
	public static LootTable.Builder createCandleCakeDrops(final Block candle) {
778
		return LootTable.lootTable().withPool(LootPool.lootPool().setRolls(ContextIntProviders.exactly(1)).add(LootItem.lootTableItem(candle)));
779
	}
780
781
	public static LootTable.Builder noDrop() {
782
		return LootTable.lootTable();
783
	}
784
785
	/**
786
	 * Access widened by fabric-data-generation-api-v1 to accessible
787
	 */
788
	public abstract void generate();
789
790
	@Override
791
	public void run() {
792
		this.generate();
793
		Set<ResourceKey<LootTable>> seen = new HashSet<>();
794
795
		for (Block block : BuiltInRegistries.BLOCK) {
796
			if (block.isEnabled(this.enabledFeatures)) {
797
				block.getLootTable()
798
					.ifPresent(
799
						lootTable -> {
800
							if (seen.add((ResourceKey<LootTable>)lootTable)) {
801
								LootTable.Builder builder = this.map.remove(lootTable);
802
								if (builder == null) {
803
									throw new IllegalStateException(
804
										String.format(Locale.ROOT, "Missing loottable '%s' for '%s'", lootTable.identifier(), BuiltInRegistries.BLOCK.getKey(block))
805
									);
806
								}
807
808
								this.output.accept((ResourceKey<LootTable>)lootTable, builder);
809
							}
810
						}
811
					);
812
			}
813
		}
814
815
		if (!this.map.isEmpty()) {
816
			throw new IllegalStateException("Created block loot tables for non-blocks: " + this.map.keySet());
817
		}
818
	}
819
820
	/**
821
	 * Access widened by fabric-data-generation-api-v1 to accessible
822
	 */
823
	public void addNetherVinesDropTable(final Block vineBlock, final Block plantBlock) {
824
		LootTable.Builder builder = this.createSilkTouchOrShearsDispatchTable(
825
			vineBlock,
826
			LootItem.lootTableItem(vineBlock)
827
				.when(BonusLevelTableCondition.bonusLevelFlatChance(this.enchantments.getOrThrow(Enchantments.FORTUNE), 0.33F, 0.55F, 0.77F, 1.0F))
828
		);
829
		this.add(vineBlock, builder);
830
		this.add(plantBlock, builder);
831
	}
832
833
	/**
834
	 * Access widened by fabric-data-generation-api-v1 to accessible
835
	 */
836
	public LootTable.Builder createDoorTable(final Block block) {
837
		return this.createSinglePropConditionTable(block, DoorBlock.HALF, DoubleBlockHalf.LOWER);
838
	}
839
840
	/**
841
	 * Access widened by fabric-data-generation-api-v1 to accessible
842
	 */
843
	public void dropPottedContents(final Block potted) {
844
		this.add(potted, block -> this.createPotFlowerItemTable(((FlowerPotBlock)block).getPotted()));
845
	}
846
847
	/**
848
	 * Access widened by fabric-data-generation-api-v1 to accessible
849
	 */
850
	public void otherWhenSilkTouch(final Block block, final Block other) {
851
		this.add(block, this.createSilkTouchOnlyTable(other));
852
	}
853
854
	/**
855
	 * Access widened by fabric-data-generation-api-v1 to accessible
856
	 */
857
	public void dropOther(final Block block, final ItemLike drop) {
858
		this.add(block, this.createSingleItemTable(drop));
859
	}
860
861
	/**
862
	 * Access widened by fabric-data-generation-api-v1 to accessible
863
	 */
864
	public void dropWhenSilkTouch(final Block block) {
865
		this.otherWhenSilkTouch(block, block);
866
	}
867
868
	/**
869
	 * Access widened by fabric-data-generation-api-v1 to accessible
870
	 */
871
	public void dropSelf(final Block block) {
872
		this.dropOther(block, block);
873
	}
874
875
	/**
876
	 * Access widened by fabric-data-generation-api-v1 to accessible
877
	 */
878
	public void add(final Block block, final Function<Block, LootTable.Builder> builder) {
879
		this.add(block, builder.apply(block));
880
	}
881
882
	/**
883
	 * Access widened by fabric-data-generation-api-v1 to accessible
884
	 */
885
	public void add(final Block block, final LootTable.Builder builder) {
886
		this.map.put(block.getLootTable().orElseThrow(() -> new IllegalStateException("Block " + block + " does not have loot table")), builder);
887
	}
888
}
889

Decompiled Minecraft 26.3 source of BlockLootSubProvider (net/minecraft/data/loot/BlockLootSubProvider.java) with Mojang official mappings, stored verbatim on the site.