BrewedPotionTrigger .java

net.minecraft.advancements.triggers.BrewedPotionTrigger (class, 40 lines): members: TriggerInstance, trigger, codec. strings: "potion", "player".

net.minecraft.advancements.triggersclass40 linescommonextends SimpleCriterionTrigger<BrewedPotionTrigger.TriggerInstance>1.7 KB

API Surface (4)

Codec<BrewedPotionTrigger.TriggerInstance> codec()
void trigger(final ServerPlayer player, final PotionContents potion)
Criterion<BrewedPotionTrigger.TriggerInstance> brewedPotion()
boolean matches(final PotionContents potion)

String literals (2)

"player"
"potion"

Full Source

BrewedPotionTrigger.java40 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.advancements.triggers;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.codecs.RecordCodecBuilder;
5
import java.util.Optional;
6
import net.minecraft.core.Holder;
7
import net.minecraft.core.component.predicates.PotionsPredicate;
8
import net.minecraft.server.level.ServerPlayer;
9
import net.minecraft.world.item.alchemy.PotionContents;
10
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
11
12
public class BrewedPotionTrigger extends SimpleCriterionTrigger<BrewedPotionTrigger.TriggerInstance> {
13
	@Override
14
	public Codec<BrewedPotionTrigger.TriggerInstance> codec() {
15
		return BrewedPotionTrigger.TriggerInstance.CODEC;
16
	}
17
18
	public void trigger(final ServerPlayer player, final PotionContents potion) {
19
		this.trigger(player, t -> t.matches(potion));
20
	}
21
22
	public record TriggerInstance(Optional<Holder<LootItemCondition>> player, Optional<PotionsPredicate> potion) implements SimpleCriterionTrigger.SimpleInstance {
23
		public static final Codec<BrewedPotionTrigger.TriggerInstance> CODEC = RecordCodecBuilder.create(
24
			i -> i.group(
25
					LootItemCondition.CODEC.optionalFieldOf("player").forGetter(BrewedPotionTrigger.TriggerInstance::player),
26
					PotionsPredicate.CODEC.optionalFieldOf("potion").forGetter(BrewedPotionTrigger.TriggerInstance::potion)
27
				)
28
				.apply(i, BrewedPotionTrigger.TriggerInstance::new)
29
		);
30
31
		public static Criterion<BrewedPotionTrigger.TriggerInstance> brewedPotion() {
32
			return CriteriaTriggers.BREWED_POTION.createCriterion(new BrewedPotionTrigger.TriggerInstance(Optional.empty(), Optional.empty()));
33
		}
34
35
		public boolean matches(final PotionContents potion) {
36
			return !this.potion.isPresent() || this.potion.get().matches(potion);
37
		}
38
	}
39
}
40

Decompiled Minecraft 26.3 source of BrewedPotionTrigger (net/minecraft/advancements/triggers/BrewedPotionTrigger.java) with Mojang official mappings, stored verbatim on the site.