package net.minecraft.world.level.block.state.predicate; import com.google.common.collect.Maps; import java.util.Map; import java.util.Map.Entry; import java.util.function.Predicate; import javax.annotation.Nullable; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.Property; public class BlockStatePredicate implements Predicate { public static final Predicate ANY = p_61299_ -> true; private final StateDefinition definition; private final Map, Predicate> properties = Maps.newHashMap(); private BlockStatePredicate(StateDefinition p_61286_) { this.definition = p_61286_; } public static BlockStatePredicate forBlock(Block p_61288_) { return new BlockStatePredicate(p_61288_.getStateDefinition()); } public boolean test(@Nullable BlockState p_61290_) { if (p_61290_ != null && p_61290_.getBlock().equals(this.definition.getOwner())) { if (this.properties.isEmpty()) { return true; } else { for (Entry, Predicate> entry : this.properties.entrySet()) { if (!this.applies(p_61290_, entry.getKey(), entry.getValue())) { return false; } } return true; } } else { return false; } } protected > boolean applies(BlockState p_61292_, Property p_61293_, Predicate p_61294_) { T t = p_61292_.getValue(p_61293_); return p_61294_.test(t); } public > BlockStatePredicate where(Property p_61296_, Predicate p_61297_) { if (!this.definition.getProperties().contains(p_61296_)) { throw new IllegalArgumentException(this.definition + " cannot support property " + p_61296_); } else { this.properties.put(p_61296_, p_61297_); return this; } } }