VanillaChargedCreeperExplosionLoot .java

net.minecraft.data.loot.packs.VanillaChargedCreeperExplosionLoot (class, 74 lines): members: ENTRIES, entityTypes, Entry, output, run. imports: LootItem.

net.minecraft.data.loot.packsclass74 linescommon3.6 KB

Implements

API Surface (1)

void run()

Fields & Constants (3)

ENTRIES
output
entityTypes

Full Source

VanillaChargedCreeperExplosionLoot.java74 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.data.loot.packs;
2
3
import java.util.ArrayList;
4
import java.util.List;
5
import net.minecraft.advancements.predicates.entity.EntityPredicate;
6
import net.minecraft.advancements.predicates.entity.EntityTypePredicate;
7
import net.minecraft.core.Holder;
8
import net.minecraft.core.HolderGetter;
9
import net.minecraft.core.registries.Registries;
10
import net.minecraft.data.loot.LootTableSubProvider;
11
import net.minecraft.resources.ResourceKey;
12
import net.minecraft.world.entity.EntityType;
13
import net.minecraft.world.entity.EntityTypes;
14
import net.minecraft.world.item.Item;
15
import net.minecraft.world.item.Items;
16
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
17
import net.minecraft.world.level.storage.loot.LootContext;
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.AlternativesEntry;
21
import net.minecraft.world.level.storage.loot.entries.LootItem;
22
import net.minecraft.world.level.storage.loot.entries.LootPoolEntryContainer;
23
import net.minecraft.world.level.storage.loot.entries.NestedLootTable;
24
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
25
import net.minecraft.world.level.storage.loot.predicates.LootItemEntityPropertyCondition;
26
import net.minecraft.world.level.storage.loot.providers.number.ints.ContextIntProviders;
27
28
public class VanillaChargedCreeperExplosionLoot implements LootTableSubProvider {
29
	private static final List<VanillaChargedCreeperExplosionLoot.Entry> ENTRIES = List.of(
30
		new VanillaChargedCreeperExplosionLoot.Entry(BuiltInLootTables.CHARGED_CREEPER_PIGLIN, EntityTypes.PIGLIN, Items.PIGLIN_HEAD),
31
		new VanillaChargedCreeperExplosionLoot.Entry(BuiltInLootTables.CHARGED_CREEPER_CREEPER, EntityTypes.CREEPER, Items.CREEPER_HEAD),
32
		new VanillaChargedCreeperExplosionLoot.Entry(BuiltInLootTables.CHARGED_CREEPER_SKELETON, EntityTypes.SKELETON, Items.SKELETON_SKULL),
33
		new VanillaChargedCreeperExplosionLoot.Entry(BuiltInLootTables.CHARGED_CREEPER_WITHER_SKELETON, EntityTypes.WITHER_SKELETON, Items.WITHER_SKELETON_SKULL),
34
		new VanillaChargedCreeperExplosionLoot.Entry(BuiltInLootTables.CHARGED_CREEPER_ZOMBIE, EntityTypes.ZOMBIE, Items.ZOMBIE_HEAD)
35
	);
36
	private final LootTableSubProvider.Context output;
37
	private final HolderGetter<EntityType<?>> entityTypes;
38
39
	public VanillaChargedCreeperExplosionLoot(final LootTableSubProvider.Context output) {
40
		this.output = output;
41
		this.entityTypes = output.lookup(Registries.ENTITY_TYPE);
42
	}
43
44
	@Override
45
	public void run() {
46
		List<LootPoolEntryContainer.Builder<?>> alternatives = new ArrayList<>(ENTRIES.size());
47
48
		for (VanillaChargedCreeperExplosionLoot.Entry entry : ENTRIES) {
49
			Holder.Reference<LootTable> innerLootTable = this.output
50
				.accept(
51
					entry.lootTable, LootTable.lootTable().withPool(LootPool.lootPool().setRolls(ContextIntProviders.exactly(1)).add(LootItem.lootTableItem(entry.item)))
52
				);
53
			LootItemCondition.Builder predicate = LootItemEntityPropertyCondition.hasProperties(
54
				LootContext.EntityTarget.THIS, EntityPredicate.Builder.entity().entityType(EntityTypePredicate.of(this.entityTypes, entry.entityType))
55
			);
56
			alternatives.add(NestedLootTable.lootTableReference(innerLootTable).when(predicate));
57
		}
58
59
		this.output
60
			.accept(
61
				BuiltInLootTables.CHARGED_CREEPER,
62
				LootTable.lootTable()
63
					.withPool(
64
						LootPool.lootPool()
65
							.setRolls(ContextIntProviders.exactly(1))
66
							.add(AlternativesEntry.alternatives(alternatives.toArray(LootPoolEntryContainer.Builder[]::new)))
67
					)
68
			);
69
	}
70
71
	private record Entry(ResourceKey<LootTable> lootTable, EntityType<?> entityType, Item item) {
72
	}
73
}
74

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