| 1 | package net.minecraft.world.entity;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.tags.FluidTags;
|
| 5 | import net.minecraft.world.level.LevelReader;
|
| 6 | import net.minecraft.world.level.NaturalSpawner;
|
| 7 | import net.minecraft.world.level.block.state.BlockState;
|
| 8 | import net.minecraft.world.level.pathfinder.PathComputationType;
|
| 9 | import org.jspecify.annotations.Nullable;
|
| 10 |
|
| 11 | public interface SpawnPlacementTypes {
|
| 12 | SpawnPlacementType NO_RESTRICTIONS = (level, blockPos, type) -> true;
|
| 13 | SpawnPlacementType IN_WATER = (level, blockPos, type) -> {
|
| 14 | if (type != null && level.getWorldBorder().isWithinBounds(blockPos)) {
|
| 15 | BlockPos above = blockPos.above();
|
| 16 | return level.getFluidState(blockPos).is(FluidTags.WATER) && !level.getBlockState(above).isRedstoneConductor(level, above);
|
| 17 | } else {
|
| 18 | return false;
|
| 19 | }
|
| 20 | };
|
| 21 | SpawnPlacementType IN_LAVA = (level, blockPos, type) -> type != null && level.getWorldBorder().isWithinBounds(blockPos)
|
| 22 | ? level.getFluidState(blockPos).is(FluidTags.LAVA)
|
| 23 | : false;
|
| 24 | SpawnPlacementType ON_GROUND = new SpawnPlacementType() {
|
| 25 | @Override
|
| 26 | public boolean isSpawnPositionOk(final LevelReader level, final BlockPos blockPos, final @Nullable EntityType<?> type) {
|
| 27 | if (type != null && level.getWorldBorder().isWithinBounds(blockPos)) {
|
| 28 | BlockPos above = blockPos.above();
|
| 29 | BlockPos below = blockPos.below();
|
| 30 | BlockState belowState = level.getBlockState(below);
|
| 31 | return !belowState.isValidSpawn(level, below, type)
|
| 32 | ? false
|
| 33 | : this.isValidEmptySpawnBlock(level, blockPos, type) && this.isValidEmptySpawnBlock(level, above, type);
|
| 34 | } else {
|
| 35 | return false;
|
| 36 | }
|
| 37 | }
|
| 38 |
|
| 39 | private boolean isValidEmptySpawnBlock(final LevelReader level, final BlockPos blockPos, final EntityType<?> type) {
|
| 40 | BlockState blockState = level.getBlockState(blockPos);
|
| 41 | return NaturalSpawner.isValidEmptySpawnBlock(level, blockPos, blockState, blockState.getFluidState(), type);
|
| 42 | }
|
| 43 |
|
| 44 | @Override
|
| 45 | public BlockPos adjustSpawnPosition(final LevelReader level, final BlockPos candidate) {
|
| 46 | BlockPos below = candidate.below();
|
| 47 | return level.getBlockState(below).isPathfindable(PathComputationType.LAND) ? below : candidate;
|
| 48 | }
|
| 49 | };
|
| 50 | }
|
| 51 |
|