2025-11-24 22:52:51 +03:00

73 lines
3.1 KiB
Java

/*
* 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.Collection;
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.level.storage.loot.LootContext;
public class ChanneledLightningTrigger
extends SimpleCriterionTrigger<TriggerInstance> {
@Override
public Codec<TriggerInstance> codec() {
return TriggerInstance.CODEC;
}
@Override
public void trigger(ServerPlayer player, Collection<? extends Entity> victims) {
List victimsContexts = victims.stream().map(v -> EntityPredicate.createContext(player, v)).collect(Collectors.toList());
this.trigger(player, (T t) -> t.matches(victimsContexts));
}
public record TriggerInstance(Optional<ContextAwarePredicate> player, List<ContextAwarePredicate> victims) implements SimpleCriterionTrigger.SimpleInstance
{
public static final Codec<TriggerInstance> CODEC = RecordCodecBuilder.create(i -> i.group((App)EntityPredicate.ADVANCEMENT_CODEC.optionalFieldOf("player").forGetter(TriggerInstance::player), (App)EntityPredicate.ADVANCEMENT_CODEC.listOf().optionalFieldOf("victims", List.of()).forGetter(TriggerInstance::victims)).apply((Applicative)i, TriggerInstance::new));
public static Criterion<TriggerInstance> channeledLightning(EntityPredicate.Builder ... victims) {
return CriteriaTriggers.CHANNELED_LIGHTNING.createCriterion(new TriggerInstance(Optional.empty(), EntityPredicate.wrap(victims)));
}
public boolean matches(Collection<? extends LootContext> victims) {
for (ContextAwarePredicate predicate : this.victims) {
boolean found = false;
for (LootContext lootContext : victims) {
if (!predicate.matches(lootContext)) continue;
found = true;
break;
}
if (found) continue;
return false;
}
return true;
}
@Override
public void validate(CriterionValidator validator) {
SimpleCriterionTrigger.SimpleInstance.super.validate(validator);
validator.validateEntities(this.victims, "victims");
}
}
}