VanillaShearingLoot .java

net.minecraft.data.loot.packs.VanillaShearingLoot (class, 102 lines): members: lootTables, output, run. imports: EntityLootSubProvider, AlternativesEntry.

net.minecraft.data.loot.packsclass102 linescommon4.3 KB

Implements

API Surface (1)

void run()

Fields & Constants (2)

output
lootTables

Full Source

VanillaShearingLoot.java102 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.data.loot.packs;
2
3
import net.minecraft.advancements.predicates.entity.EntityPredicate;
4
import net.minecraft.core.Holder;
5
import net.minecraft.core.HolderGetter;
6
import net.minecraft.core.component.DataComponentExactPredicate;
7
import net.minecraft.core.component.DataComponents;
8
import net.minecraft.core.registries.Registries;
9
import net.minecraft.data.loot.EntityLootSubProvider;
10
import net.minecraft.data.loot.LootTableSubProvider;
11
import net.minecraft.world.entity.animal.cow.MushroomCow;
12
import net.minecraft.world.item.Items;
13
import net.minecraft.world.level.block.Blocks;
14
import net.minecraft.world.level.block.ColorCollection;
15
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
16
import net.minecraft.world.level.storage.loot.LootContext;
17
import net.minecraft.world.level.storage.loot.LootPool;
18
import net.minecraft.world.level.storage.loot.LootTable;
19
import net.minecraft.world.level.storage.loot.entries.AlternativesEntry;
20
import net.minecraft.world.level.storage.loot.entries.LootItem;
21
import net.minecraft.world.level.storage.loot.entries.NestedLootTable;
22
import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction;
23
import net.minecraft.world.level.storage.loot.predicates.LootItemEntityPropertyCondition;
24
import net.minecraft.world.level.storage.loot.providers.number.ints.ContextIntProviders;
25
26
public class VanillaShearingLoot implements LootTableSubProvider {
27
	private final LootTableSubProvider.Context output;
28
	private final HolderGetter<LootTable> lootTables;
29
30
	public VanillaShearingLoot(final LootTableSubProvider.Context output) {
31
		this.output = output;
32
		this.lootTables = output.lookup(Registries.LOOT_TABLE);
33
	}
34
35
	@Override
36
	public void run() {
37
		this.output
38
			.accept(
39
				BuiltInLootTables.BOGGED_SHEAR,
40
				LootTable.lootTable()
41
					.withPool(
42
						LootPool.lootPool()
43
							.setRolls(ContextIntProviders.exactly(2))
44
							.add(LootItem.lootTableItem(Items.BROWN_MUSHROOM).apply(SetItemCountFunction.setCount(ContextIntProviders.exactly(1))))
45
							.add(LootItem.lootTableItem(Items.RED_MUSHROOM).apply(SetItemCountFunction.setCount(ContextIntProviders.exactly(1))))
46
					)
47
			);
48
		ColorCollection.zipApply(
49
			BuiltInLootTables.SHEAR_DYED_SHEEP,
50
			Blocks.WOOL,
51
			(dyedSheep, wool) -> this.output
52
				.accept(dyedSheep, LootTable.lootTable().withPool(LootPool.lootPool().setRolls(ContextIntProviders.between(1, 3)).add(LootItem.lootTableItem(wool))))
53
		);
54
		this.output
55
			.accept(
56
				BuiltInLootTables.SHEAR_SHEEP,
57
				LootTable.lootTable().withPool(EntityLootSubProvider.createSheepDispatchPool(BuiltInLootTables.SHEAR_DYED_SHEEP.map(this.lootTables::getOrThrow)))
58
			);
59
		Holder.Reference<LootTable> shearRedMooshroom = this.output
60
			.accept(
61
				BuiltInLootTables.SHEAR_RED_MOOSHROOM,
62
				LootTable.lootTable().withPool(LootPool.lootPool().setRolls(ContextIntProviders.exactly(5)).add(LootItem.lootTableItem(Items.RED_MUSHROOM)))
63
			);
64
		Holder.Reference<LootTable> sheadBrownMooshroom = this.output
65
			.accept(
66
				BuiltInLootTables.SHEAR_BROWN_MOOSHROOM,
67
				LootTable.lootTable().withPool(LootPool.lootPool().setRolls(ContextIntProviders.exactly(5)).add(LootItem.lootTableItem(Items.BROWN_MUSHROOM)))
68
			);
69
		this.output
70
			.accept(
71
				BuiltInLootTables.SHEAR_MOOSHROOM,
72
				LootTable.lootTable()
73
					.withPool(
74
						LootPool.lootPool()
75
							.add(
76
								AlternativesEntry.alternatives(
77
									NestedLootTable.lootTableReference(shearRedMooshroom)
78
										.when(
79
											LootItemEntityPropertyCondition.hasProperties(
80
												LootContext.EntityTarget.THIS,
81
												EntityPredicate.Builder.entity().components(DataComponentExactPredicate.expect(DataComponents.MOOSHROOM_VARIANT, MushroomCow.Variant.RED))
82
											)
83
										),
84
									NestedLootTable.lootTableReference(sheadBrownMooshroom)
85
										.when(
86
											LootItemEntityPropertyCondition.hasProperties(
87
												LootContext.EntityTarget.THIS,
88
												EntityPredicate.Builder.entity().components(DataComponentExactPredicate.expect(DataComponents.MOOSHROOM_VARIANT, MushroomCow.Variant.BROWN))
89
											)
90
										)
91
								)
92
							)
93
					)
94
			);
95
		this.output
96
			.accept(
97
				BuiltInLootTables.SHEAR_SNOW_GOLEM,
98
				LootTable.lootTable().withPool(LootPool.lootPool().setRolls(ContextIntProviders.exactly(1)).add(LootItem.lootTableItem(Items.CARVED_PUMPKIN)))
99
			);
100
	}
101
}
102

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