VanillaFishingLoot .java

net.minecraft.data.loot.packs.VanillaFishingLoot (class): members: fishingFishLootTable, biomes, enchantments, output, run. imports: FishingHookPredicate.

net.minecraft.data.loot.packsclass134 linescommon6.0 KB

Implements

API Surface (2)

void run()
LootTable.Builder fishingFishLootTable()

Fields & Constants (3)

output
biomes
enchantments

Full Source

VanillaFishingLoot.java134 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.data.loot.packs;
2
3
import net.minecraft.advancements.predicates.LocationPredicate;
4
import net.minecraft.advancements.predicates.entity.EntityPredicate;
5
import net.minecraft.advancements.predicates.entity.FishingHookPredicate;
6
import net.minecraft.core.Holder;
7
import net.minecraft.core.HolderGetter;
8
import net.minecraft.core.HolderSet;
9
import net.minecraft.core.registries.Registries;
10
import net.minecraft.data.loot.LootTableSubProvider;
11
import net.minecraft.world.item.Items;
12
import net.minecraft.world.item.alchemy.Potions;
13
import net.minecraft.world.item.enchantment.Enchantment;
14
import net.minecraft.world.level.biome.Biome;
15
import net.minecraft.world.level.biome.Biomes;
16
import net.minecraft.world.level.block.Blocks;
17
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
18
import net.minecraft.world.level.storage.loot.LootContext;
19
import net.minecraft.world.level.storage.loot.LootPool;
20
import net.minecraft.world.level.storage.loot.LootTable;
21
import net.minecraft.world.level.storage.loot.entries.LootItem;
22
import net.minecraft.world.level.storage.loot.entries.NestedLootTable;
23
import net.minecraft.world.level.storage.loot.functions.EnchantWithLevelsFunction;
24
import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction;
25
import net.minecraft.world.level.storage.loot.functions.SetItemDamageFunction;
26
import net.minecraft.world.level.storage.loot.functions.SetPotionFunction;
27
import net.minecraft.world.level.storage.loot.predicates.LocationCheck;
28
import net.minecraft.world.level.storage.loot.predicates.LootItemEntityPropertyCondition;
29
import net.minecraft.world.level.storage.loot.providers.number.floats.ContextFloatProviders;
30
import net.minecraft.world.level.storage.loot.providers.number.ints.ContextIntProviders;
31
32
public class VanillaFishingLoot implements LootTableSubProvider {
33
	private final LootTableSubProvider.Context output;
34
	private final HolderGetter<Biome> biomes;
35
	private final HolderGetter<Enchantment> enchantments;
36
37
	public VanillaFishingLoot(final LootTableSubProvider.Context output) {
38
		this.output = output;
39
		this.biomes = output.lookup(Registries.BIOME);
40
		this.enchantments = output.lookup(Registries.ENCHANTMENT);
41
	}
42
43
	@Override
44
	public void run() {
45
		Holder.Reference<LootTable> fishTable = this.output.accept(BuiltInLootTables.FISHING_FISH, fishingFishLootTable());
46
		Holder.Reference<LootTable> junkTable = this.output
47
			.accept(
48
				BuiltInLootTables.FISHING_JUNK,
49
				LootTable.lootTable()
50
					.withPool(
51
						LootPool.lootPool()
52
							.add(LootItem.lootTableItem(Blocks.LILY_PAD).setWeight(17))
53
							.add(LootItem.lootTableItem(Items.LEATHER_BOOTS).setWeight(10).apply(SetItemDamageFunction.setDamage(ContextFloatProviders.between(0.0F, 0.9F))))
54
							.add(LootItem.lootTableItem(Items.LEATHER).setWeight(10))
55
							.add(LootItem.lootTableItem(Items.BONE).setWeight(10))
56
							.add(LootItem.lootTableItem(Items.POTION).setWeight(10).apply(SetPotionFunction.setPotion(Potions.WATER)))
57
							.add(LootItem.lootTableItem(Items.STRING).setWeight(5))
58
							.add(LootItem.lootTableItem(Items.FISHING_ROD).setWeight(2).apply(SetItemDamageFunction.setDamage(ContextFloatProviders.between(0.0F, 0.9F))))
59
							.add(LootItem.lootTableItem(Items.BOWL).setWeight(10))
60
							.add(LootItem.lootTableItem(Items.STICK).setWeight(5))
61
							.add(LootItem.lootTableItem(Items.INK_SAC).setWeight(1).apply(SetItemCountFunction.setCount(ContextIntProviders.exactly(10))))
62
							.add(LootItem.lootTableItem(Blocks.TRIPWIRE_HOOK).setWeight(10))
63
							.add(LootItem.lootTableItem(Items.ROTTEN_FLESH).setWeight(10))
64
							.add(
65
								LootItem.lootTableItem(Blocks.BAMBOO)
66
									.when(
67
										LocationCheck.checkLocation(
68
											LocationPredicate.Builder.location()
69
												.setBiomes(
70
													HolderSet.direct(this.biomes.getOrThrow(Biomes.JUNGLE), this.biomes.getOrThrow(Biomes.SPARSE_JUNGLE), this.biomes.getOrThrow(Biomes.BAMBOO_JUNGLE))
71
												)
72
										)
73
									)
74
									.setWeight(10)
75
							)
76
					)
77
			);
78
		Holder.Reference<LootTable> treasureTable = this.output
79
			.accept(
80
				BuiltInLootTables.FISHING_TREASURE,
81
				LootTable.lootTable()
82
					.withPool(
83
						LootPool.lootPool()
84
							.add(LootItem.lootTableItem(Items.NAME_TAG))
85
							.add(LootItem.lootTableItem(Items.SADDLE))
86
							.add(
87
								LootItem.lootTableItem(Items.BOW)
88
									.apply(SetItemDamageFunction.setDamage(ContextFloatProviders.between(0.0F, 0.25F)))
89
									.apply(EnchantWithLevelsFunction.enchantWithLevels(this.enchantments, ContextIntProviders.exactly(30)))
90
							)
91
							.add(
92
								LootItem.lootTableItem(Items.FISHING_ROD)
93
									.apply(SetItemDamageFunction.setDamage(ContextFloatProviders.between(0.0F, 0.25F)))
94
									.apply(EnchantWithLevelsFunction.enchantWithLevels(this.enchantments, ContextIntProviders.exactly(30)))
95
							)
96
							.add(LootItem.lootTableItem(Items.BOOK).apply(EnchantWithLevelsFunction.enchantWithLevels(this.enchantments, ContextIntProviders.exactly(30))))
97
							.add(LootItem.lootTableItem(Items.NAUTILUS_SHELL))
98
					)
99
			);
100
		this.output
101
			.accept(
102
				BuiltInLootTables.FISHING,
103
				LootTable.lootTable()
104
					.withPool(
105
						LootPool.lootPool()
106
							.setRolls(ContextIntProviders.exactly(1))
107
							.add(NestedLootTable.lootTableReference(junkTable).setWeight(10).setQuality(-2))
108
							.add(
109
								NestedLootTable.lootTableReference(treasureTable)
110
									.setWeight(5)
111
									.setQuality(2)
112
									.when(
113
										LootItemEntityPropertyCondition.hasProperties(
114
											LootContext.EntityTarget.THIS, EntityPredicate.Builder.entity().fishingHook(FishingHookPredicate.inOpenWater(true))
115
										)
116
									)
117
							)
118
							.add(NestedLootTable.lootTableReference(fishTable).setWeight(85).setQuality(-1))
119
					)
120
			);
121
	}
122
123
	public static LootTable.Builder fishingFishLootTable() {
124
		return LootTable.lootTable()
125
			.withPool(
126
				LootPool.lootPool()
127
					.add(LootItem.lootTableItem(Items.COD).setWeight(60))
128
					.add(LootItem.lootTableItem(Items.SALMON).setWeight(25))
129
					.add(LootItem.lootTableItem(Items.TROPICAL_FISH).setWeight(2))
130
					.add(LootItem.lootTableItem(Items.PUFFERFISH).setWeight(13))
131
			);
132
	}
133
}
134

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