72 lines
3.8 KiB
Java
72 lines
3.8 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
|
|
* org.jspecify.annotations.Nullable
|
|
*/
|
|
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.Optional;
|
|
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.DistancePredicate;
|
|
import net.minecraft.advancements.criterion.EntityPredicate;
|
|
import net.minecraft.advancements.criterion.LocationPredicate;
|
|
import net.minecraft.advancements.criterion.SimpleCriterionTrigger;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.level.storage.loot.LootContext;
|
|
import net.minecraft.world.phys.Vec3;
|
|
import org.jspecify.annotations.Nullable;
|
|
|
|
public class FallAfterExplosionTrigger
|
|
extends SimpleCriterionTrigger<TriggerInstance> {
|
|
@Override
|
|
public Codec<TriggerInstance> codec() {
|
|
return TriggerInstance.CODEC;
|
|
}
|
|
|
|
public void trigger(ServerPlayer player, Vec3 startPosition, @Nullable Entity cause) {
|
|
Vec3 playerPosition = player.position();
|
|
LootContext wrappedCause = cause != null ? EntityPredicate.createContext(player, cause) : null;
|
|
this.trigger(player, t -> t.matches(player.level(), startPosition, playerPosition, wrappedCause));
|
|
}
|
|
|
|
public record TriggerInstance(Optional<ContextAwarePredicate> player, Optional<LocationPredicate> startPosition, Optional<DistancePredicate> distance, Optional<ContextAwarePredicate> cause) implements SimpleCriterionTrigger.SimpleInstance
|
|
{
|
|
public static final Codec<TriggerInstance> CODEC = RecordCodecBuilder.create(i -> i.group((App)EntityPredicate.ADVANCEMENT_CODEC.optionalFieldOf("player").forGetter(TriggerInstance::player), (App)LocationPredicate.CODEC.optionalFieldOf("start_position").forGetter(TriggerInstance::startPosition), (App)DistancePredicate.CODEC.optionalFieldOf("distance").forGetter(TriggerInstance::distance), (App)EntityPredicate.ADVANCEMENT_CODEC.optionalFieldOf("cause").forGetter(TriggerInstance::cause)).apply((Applicative)i, TriggerInstance::new));
|
|
|
|
public static Criterion<TriggerInstance> fallAfterExplosion(DistancePredicate distance, EntityPredicate.Builder cause) {
|
|
return CriteriaTriggers.FALL_AFTER_EXPLOSION.createCriterion(new TriggerInstance(Optional.empty(), Optional.empty(), Optional.of(distance), Optional.of(EntityPredicate.wrap(cause))));
|
|
}
|
|
|
|
@Override
|
|
public void validate(CriterionValidator validator) {
|
|
SimpleCriterionTrigger.SimpleInstance.super.validate(validator);
|
|
validator.validateEntity(this.cause(), "cause");
|
|
}
|
|
|
|
public boolean matches(ServerLevel level, Vec3 enteredPosition, Vec3 playerPosition, @Nullable LootContext cause) {
|
|
if (this.startPosition.isPresent() && !this.startPosition.get().matches(level, enteredPosition.x, enteredPosition.y, enteredPosition.z)) {
|
|
return false;
|
|
}
|
|
if (this.distance.isPresent() && !this.distance.get().matches(enteredPosition.x, enteredPosition.y, enteredPosition.z, playerPosition.x, playerPosition.y, playerPosition.z)) {
|
|
return false;
|
|
}
|
|
return !this.cause.isPresent() || cause != null && this.cause.get().matches(cause);
|
|
}
|
|
}
|
|
}
|
|
|