VanillaEquipmentLoot .java

net.minecraft.data.loot.packs.VanillaEquipmentLoot (class): members: trialChamberEquipment, trimMaterials, trimPatterns, enchantments, output, run.

net.minecraft.data.loot.packsclass131 linescommon6.2 KB

Implements

API Surface (2)

void run()
LootTable.Builder trialChamberEquipment(final Item helmet, final Item chestplate, final ArmorTrim trim)

Fields & Constants (4)

output
trimPatterns
trimMaterials
enchantments

Full Source

VanillaEquipmentLoot.java131 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.data.loot.packs;
2
3
import net.minecraft.core.Holder;
4
import net.minecraft.core.HolderGetter;
5
import net.minecraft.core.component.DataComponents;
6
import net.minecraft.core.registries.Registries;
7
import net.minecraft.data.loot.LootTableSubProvider;
8
import net.minecraft.world.item.Item;
9
import net.minecraft.world.item.Items;
10
import net.minecraft.world.item.enchantment.Enchantment;
11
import net.minecraft.world.item.enchantment.Enchantments;
12
import net.minecraft.world.item.equipment.trim.ArmorTrim;
13
import net.minecraft.world.item.equipment.trim.TrimMaterial;
14
import net.minecraft.world.item.equipment.trim.TrimMaterials;
15
import net.minecraft.world.item.equipment.trim.TrimPattern;
16
import net.minecraft.world.item.equipment.trim.TrimPatterns;
17
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
18
import net.minecraft.world.level.storage.loot.LootPool;
19
import net.minecraft.world.level.storage.loot.LootTable;
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.SetComponentsFunction;
23
import net.minecraft.world.level.storage.loot.functions.SetEnchantmentsFunction;
24
import net.minecraft.world.level.storage.loot.predicates.LootItemRandomChanceCondition;
25
import net.minecraft.world.level.storage.loot.providers.number.ints.ContextIntProviders;
26
27
public class VanillaEquipmentLoot implements LootTableSubProvider {
28
	private final LootTableSubProvider.Context output;
29
	private final HolderGetter<TrimPattern> trimPatterns;
30
	private final HolderGetter<TrimMaterial> trimMaterials;
31
	private final HolderGetter<Enchantment> enchantments;
32
33
	public VanillaEquipmentLoot(final LootTableSubProvider.Context output) {
34
		this.output = output;
35
		this.trimPatterns = output.lookup(Registries.TRIM_PATTERN);
36
		this.trimMaterials = output.lookup(Registries.TRIM_MATERIAL);
37
		this.enchantments = output.lookup(Registries.ENCHANTMENT);
38
	}
39
40
	@Override
41
	public void run() {
42
		ArmorTrim flowTrim = new ArmorTrim(this.trimMaterials.getOrThrow(TrimMaterials.COPPER), this.trimPatterns.getOrThrow(TrimPatterns.FLOW));
43
		ArmorTrim boltTrim = new ArmorTrim(this.trimMaterials.getOrThrow(TrimMaterials.COPPER), this.trimPatterns.getOrThrow(TrimPatterns.BOLT));
44
		Holder.Reference<LootTable> equipmentTrialChamblerTable = this.output
45
			.accept(
46
				BuiltInLootTables.EQUIPMENT_TRIAL_CHAMBER,
47
				LootTable.lootTable()
48
					.withPool(
49
						LootPool.lootPool()
50
							.setRolls(ContextIntProviders.exactly(1))
51
							.add(NestedLootTable.inlineLootTable(this.trialChamberEquipment(Items.CHAINMAIL_HELMET, Items.CHAINMAIL_CHESTPLATE, boltTrim).build()).setWeight(4))
52
							.add(NestedLootTable.inlineLootTable(this.trialChamberEquipment(Items.IRON_HELMET, Items.IRON_CHESTPLATE, flowTrim).build()).setWeight(2))
53
							.add(NestedLootTable.inlineLootTable(this.trialChamberEquipment(Items.DIAMOND_HELMET, Items.DIAMOND_CHESTPLATE, flowTrim).build()).setWeight(1))
54
					)
55
			);
56
		this.output
57
			.accept(
58
				BuiltInLootTables.EQUIPMENT_TRIAL_CHAMBER_MELEE,
59
				LootTable.lootTable()
60
					.withPool(LootPool.lootPool().setRolls(ContextIntProviders.exactly(1)).add(NestedLootTable.lootTableReference(equipmentTrialChamblerTable)))
61
					.withPool(
62
						LootPool.lootPool()
63
							.setRolls(ContextIntProviders.exactly(1))
64
							.add(LootItem.lootTableItem(Items.IRON_SWORD).setWeight(4))
65
							.add(
66
								LootItem.lootTableItem(Items.IRON_SWORD)
67
									.apply(new SetEnchantmentsFunction.Builder().withEnchantment(this.enchantments.getOrThrow(Enchantments.SHARPNESS), ContextIntProviders.exactly(1)))
68
							)
69
							.add(
70
								LootItem.lootTableItem(Items.IRON_SWORD)
71
									.apply(new SetEnchantmentsFunction.Builder().withEnchantment(this.enchantments.getOrThrow(Enchantments.KNOCKBACK), ContextIntProviders.exactly(1)))
72
							)
73
							.add(LootItem.lootTableItem(Items.DIAMOND_SWORD))
74
					)
75
			);
76
		this.output
77
			.accept(
78
				BuiltInLootTables.EQUIPMENT_TRIAL_CHAMBER_RANGED,
79
				LootTable.lootTable()
80
					.withPool(LootPool.lootPool().setRolls(ContextIntProviders.exactly(1)).add(NestedLootTable.lootTableReference(equipmentTrialChamblerTable)))
81
					.withPool(
82
						LootPool.lootPool()
83
							.setRolls(ContextIntProviders.exactly(1))
84
							.add(LootItem.lootTableItem(Items.BOW).setWeight(2))
85
							.add(
86
								LootItem.lootTableItem(Items.BOW)
87
									.apply(new SetEnchantmentsFunction.Builder().withEnchantment(this.enchantments.getOrThrow(Enchantments.POWER), ContextIntProviders.exactly(1)))
88
							)
89
							.add(
90
								LootItem.lootTableItem(Items.BOW)
91
									.apply(new SetEnchantmentsFunction.Builder().withEnchantment(this.enchantments.getOrThrow(Enchantments.PUNCH), ContextIntProviders.exactly(1)))
92
							)
93
					)
94
			);
95
	}
96
97
	public LootTable.Builder trialChamberEquipment(final Item helmet, final Item chestplate, final ArmorTrim trim) {
98
		return LootTable.lootTable()
99
			.withPool(
100
				LootPool.lootPool()
101
					.setRolls(ContextIntProviders.exactly(1))
102
					.when(LootItemRandomChanceCondition.randomChance(0.5F))
103
					.add(
104
						LootItem.lootTableItem(helmet)
105
							.apply(SetComponentsFunction.setComponent(DataComponents.TRIM, trim))
106
							.apply(
107
								new SetEnchantmentsFunction.Builder()
108
									.withEnchantment(this.enchantments.getOrThrow(Enchantments.PROTECTION), ContextIntProviders.exactly(4))
109
									.withEnchantment(this.enchantments.getOrThrow(Enchantments.PROJECTILE_PROTECTION), ContextIntProviders.exactly(4))
110
									.withEnchantment(this.enchantments.getOrThrow(Enchantments.FIRE_PROTECTION), ContextIntProviders.exactly(4))
111
							)
112
					)
113
			)
114
			.withPool(
115
				LootPool.lootPool()
116
					.setRolls(ContextIntProviders.exactly(1))
117
					.when(LootItemRandomChanceCondition.randomChance(0.5F))
118
					.add(
119
						LootItem.lootTableItem(chestplate)
120
							.apply(SetComponentsFunction.setComponent(DataComponents.TRIM, trim))
121
							.apply(
122
								new SetEnchantmentsFunction.Builder()
123
									.withEnchantment(this.enchantments.getOrThrow(Enchantments.PROTECTION), ContextIntProviders.exactly(4))
124
									.withEnchantment(this.enchantments.getOrThrow(Enchantments.PROJECTILE_PROTECTION), ContextIntProviders.exactly(4))
125
									.withEnchantment(this.enchantments.getOrThrow(Enchantments.FIRE_PROTECTION), ContextIntProviders.exactly(4))
126
							)
127
					)
128
			);
129
	}
130
}
131

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