/* * 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.Optional; 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.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; public class DefaultBlockInteractionTrigger extends SimpleCriterionTrigger { @Override public Codec codec() { return TriggerInstance.CODEC; } public void trigger(ServerPlayer player, BlockPos pos) { ServerLevel level = player.level(); BlockState state = level.getBlockState(pos); LootParams params = new LootParams.Builder(level).withParameter(LootContextParams.ORIGIN, pos.getCenter()).withParameter(LootContextParams.THIS_ENTITY, player).withParameter(LootContextParams.BLOCK_STATE, state).create(LootContextParamSets.BLOCK_USE); LootContext context = new LootContext.Builder(params).create(Optional.empty()); this.trigger(player, (T t) -> t.matches(context)); } public record TriggerInstance(Optional player, Optional location) implements SimpleCriterionTrigger.SimpleInstance { public static final Codec CODEC = RecordCodecBuilder.create(i -> i.group((App)EntityPredicate.ADVANCEMENT_CODEC.optionalFieldOf("player").forGetter(TriggerInstance::player), (App)ContextAwarePredicate.CODEC.optionalFieldOf("location").forGetter(TriggerInstance::location)).apply((Applicative)i, TriggerInstance::new)); public boolean matches(LootContext locationContext) { return this.location.isEmpty() || this.location.get().matches(locationContext); } @Override public void validate(CriterionValidator validator) { SimpleCriterionTrigger.SimpleInstance.super.validate(validator); this.location.ifPresent(predicate -> validator.validate((ContextAwarePredicate)predicate, LootContextParamSets.BLOCK_USE, "location")); } } }