| 1 | package net.minecraft.world.level.levelgen.blockpredicates;
|
| 2 |
|
| 3 | import com.mojang.serialization.Codec;
|
| 4 | import java.util.List;
|
| 5 | import java.util.function.BiPredicate;
|
| 6 | import net.minecraft.core.BlockPos;
|
| 7 | import net.minecraft.core.Direction;
|
| 8 | import net.minecraft.core.Directional;
|
| 9 | import net.minecraft.core.HolderSet;
|
| 10 | import net.minecraft.core.Vec3i;
|
| 11 | import net.minecraft.core.registries.BuiltInRegistries;
|
| 12 | import net.minecraft.tags.BlockTags;
|
| 13 | import net.minecraft.tags.TagKey;
|
| 14 | import net.minecraft.world.level.LevelAccessor;
|
| 15 | import net.minecraft.world.level.block.Block;
|
| 16 | import net.minecraft.world.level.block.Blocks;
|
| 17 | import net.minecraft.world.level.levelgen.VerticalAnchor;
|
| 18 | import net.minecraft.world.level.material.Fluid;
|
| 19 | import net.minecraft.world.level.material.Fluids;
|
| 20 |
|
| 21 | public interface BlockPredicate extends BiPredicate<LevelAccessor, BlockPos> {
|
| 22 | Codec<BlockPredicate> CODEC = BuiltInRegistries.BLOCK_PREDICATE_TYPE.byNameCodec().dispatch(BlockPredicate::type, BlockPredicateType::codec);
|
| 23 | BlockPredicate ONLY_IN_AIR_PREDICATE = matchesTag(BlockTags.AIR);
|
| 24 | BlockPredicate ONLY_IN_AIR_OR_WATER_PREDICATE = anyOf(ONLY_IN_AIR_PREDICATE, matchesBlocks(Blocks.WATER));
|
| 25 |
|
| 26 | BlockPredicateType<?> type();
|
| 27 |
|
| 28 | static BlockPredicate allOf(final List<BlockPredicate> predicates) {
|
| 29 | return new AllOfPredicate(predicates);
|
| 30 | }
|
| 31 |
|
| 32 | static BlockPredicate allOf(final BlockPredicate... predicates) {
|
| 33 | return allOf(List.of(predicates));
|
| 34 | }
|
| 35 |
|
| 36 | static BlockPredicate allOf(final BlockPredicate a, final BlockPredicate b) {
|
| 37 | return allOf(List.of(a, b));
|
| 38 | }
|
| 39 |
|
| 40 | static BlockPredicate anyOf(final List<BlockPredicate> predicates) {
|
| 41 | return new AnyOfPredicate(predicates);
|
| 42 | }
|
| 43 |
|
| 44 | static BlockPredicate anyOf(final BlockPredicate... predicates) {
|
| 45 | return anyOf(List.of(predicates));
|
| 46 | }
|
| 47 |
|
| 48 | static BlockPredicate anyOf(final BlockPredicate a, final BlockPredicate b) {
|
| 49 | return anyOf(List.of(a, b));
|
| 50 | }
|
| 51 |
|
| 52 | static BlockPredicate matchesBlocks(final Vec3i offset, final List<Block> blocks) {
|
| 53 | return new MatchingBlocksPredicate(offset, HolderSet.direct(Block::builtInRegistryHolder, blocks));
|
| 54 | }
|
| 55 |
|
| 56 | static BlockPredicate matchesBlocks(final Directional directional, final Block... blocks) {
|
| 57 | return matchesBlocks(directional.getStep(), List.of(blocks));
|
| 58 | }
|
| 59 |
|
| 60 | static BlockPredicate matchesBlocks(final Block... blocks) {
|
| 61 | return matchesBlocks(Vec3i.ZERO, List.of(blocks));
|
| 62 | }
|
| 63 |
|
| 64 | static BlockPredicate matchesTag(final Vec3i offset, final TagKey<Block> tag) {
|
| 65 | return new MatchingBlockTagPredicate(offset, tag);
|
| 66 | }
|
| 67 |
|
| 68 | static BlockPredicate matchesTag(final Directional directional, final TagKey<Block> tag) {
|
| 69 | return matchesTag(directional.getStep(), tag);
|
| 70 | }
|
| 71 |
|
| 72 | static BlockPredicate matchesTag(final TagKey<Block> tag) {
|
| 73 | return matchesTag(Vec3i.ZERO, tag);
|
| 74 | }
|
| 75 |
|
| 76 | static BlockPredicate matchesFluids(final Directional directional, final Fluid... fluids) {
|
| 77 | return matchesFluids(directional.getStep(), List.of(fluids));
|
| 78 | }
|
| 79 |
|
| 80 | static BlockPredicate matchesFluids(final Vec3i offset, final List<Fluid> fluids) {
|
| 81 | return new MatchingFluidsPredicate(offset, HolderSet.direct(Fluid::builtInRegistryHolder, fluids));
|
| 82 | }
|
| 83 |
|
| 84 | static BlockPredicate matchesFluids(final Fluid... fluids) {
|
| 85 | return matchesFluids(Vec3i.ZERO, List.of(fluids));
|
| 86 | }
|
| 87 |
|
| 88 | static BlockPredicate not(final BlockPredicate predicate) {
|
| 89 | return new NotPredicate(predicate);
|
| 90 | }
|
| 91 |
|
| 92 | static BlockPredicate replaceable() {
|
| 93 | return new ReplaceablePredicate(Vec3i.ZERO);
|
| 94 | }
|
| 95 |
|
| 96 | static BlockPredicate wouldSurvive(final Block block) {
|
| 97 | return new WouldSurvivePredicate(Vec3i.ZERO, block.defaultBlockState());
|
| 98 | }
|
| 99 |
|
| 100 | static BlockPredicate hasSturdyFace(final Direction direction) {
|
| 101 | return new HasSturdyFacePredicate(Vec3i.ZERO, direction);
|
| 102 | }
|
| 103 |
|
| 104 | static BlockPredicate hasSturdyFace(final Directional offset, final Direction direction) {
|
| 105 | return new HasSturdyFacePredicate(offset.getStep(), direction);
|
| 106 | }
|
| 107 |
|
| 108 | static BlockPredicate solid(final Directional directional) {
|
| 109 | return new SolidPredicate(directional.getStep());
|
| 110 | }
|
| 111 |
|
| 112 | static BlockPredicate solid() {
|
| 113 | return new SolidPredicate(Vec3i.ZERO);
|
| 114 | }
|
| 115 |
|
| 116 | static BlockPredicate noFluid() {
|
| 117 | return matchesFluids(Vec3i.ZERO, List.of(Fluids.EMPTY));
|
| 118 | }
|
| 119 |
|
| 120 | static BlockPredicate insideWorld(final Vec3i offset) {
|
| 121 | return new InsideWorldBoundsPredicate(offset);
|
| 122 | }
|
| 123 |
|
| 124 | static BlockPredicate alwaysTrue() {
|
| 125 | return TrueBlockPredicate.INSTANCE;
|
| 126 | }
|
| 127 |
|
| 128 | static BlockPredicate unobstructed() {
|
| 129 | return new UnobstructedPredicate(Vec3i.ZERO);
|
| 130 | }
|
| 131 |
|
| 132 | static BlockPredicate heightRange(final VerticalAnchor minInclusive, final VerticalAnchor maxInclusive) {
|
| 133 | return new HeightRangePredicate(minInclusive, maxInclusive);
|
| 134 | }
|
| 135 |
|
| 136 | static BlockPredicate volumeMatch(final Vec3i min, final Vec3i max, final BlockPredicate match) {
|
| 137 | return new VolumeMatchPredicate(min, max, match);
|
| 138 | }
|
| 139 | }
|
| 140 |
|