/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.datafixers.kinds.App * com.mojang.datafixers.kinds.Applicative * com.mojang.serialization.Codec * com.mojang.serialization.codecs.RecordCodecBuilder */ package net.minecraft.advancements.criterion; import com.mojang.datafixers.kinds.App; import com.mojang.datafixers.kinds.Applicative; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; import net.minecraft.advancements.CriteriaTriggers; import net.minecraft.advancements.Criterion; import net.minecraft.advancements.criterion.ContextAwarePredicate; import net.minecraft.advancements.criterion.CriterionValidator; import net.minecraft.advancements.criterion.EntityPredicate; import net.minecraft.advancements.criterion.SimpleCriterionTrigger; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LightningBolt; import net.minecraft.world.level.storage.loot.LootContext; public class LightningStrikeTrigger extends SimpleCriterionTrigger { @Override public Codec codec() { return TriggerInstance.CODEC; } public void trigger(ServerPlayer player, LightningBolt lightning, List entitiesAround) { List entitiesAroundContexts = entitiesAround.stream().map(v -> EntityPredicate.createContext(player, v)).collect(Collectors.toList()); LootContext lightningContext = EntityPredicate.createContext(player, lightning); this.trigger(player, t -> t.matches(lightningContext, entitiesAroundContexts)); } public record TriggerInstance(Optional player, Optional lightning, Optional bystander) implements SimpleCriterionTrigger.SimpleInstance { public static final Codec CODEC = RecordCodecBuilder.create(i -> i.group((App)EntityPredicate.ADVANCEMENT_CODEC.optionalFieldOf("player").forGetter(TriggerInstance::player), (App)EntityPredicate.ADVANCEMENT_CODEC.optionalFieldOf("lightning").forGetter(TriggerInstance::lightning), (App)EntityPredicate.ADVANCEMENT_CODEC.optionalFieldOf("bystander").forGetter(TriggerInstance::bystander)).apply((Applicative)i, TriggerInstance::new)); public static Criterion lightningStrike(Optional lightning, Optional bystander) { return CriteriaTriggers.LIGHTNING_STRIKE.createCriterion(new TriggerInstance(Optional.empty(), EntityPredicate.wrap(lightning), EntityPredicate.wrap(bystander))); } public boolean matches(LootContext bolt, List entitiesAround) { if (this.lightning.isPresent() && !this.lightning.get().matches(bolt)) { return false; } if (this.bystander.isPresent()) { if (entitiesAround.stream().noneMatch(this.bystander.get()::matches)) { return false; } } return true; } @Override public void validate(CriterionValidator validator) { SimpleCriterionTrigger.SimpleInstance.super.validate(validator); validator.validateEntity(this.lightning, "lightning"); validator.validateEntity(this.bystander, "bystander"); } } }