| 1 | package net.minecraft.server.level;
|
| 2 |
|
| 3 | import net.minecraft.world.level.chunk.status.ChunkPyramid;
|
| 4 | import net.minecraft.world.level.chunk.status.ChunkStatus;
|
| 5 | import net.minecraft.world.level.chunk.status.ChunkStep;
|
| 6 | import org.jetbrains.annotations.Contract;
|
| 7 | import org.jspecify.annotations.Nullable;
|
| 8 |
|
| 9 | public class ChunkLevel {
|
| 10 | private static final int FULL_CHUNK_LEVEL = 33;
|
| 11 | private static final int BLOCK_TICKING_LEVEL = 32;
|
| 12 | private static final int ENTITY_TICKING_LEVEL = 31;
|
| 13 | private static final ChunkStep FULL_CHUNK_STEP = ChunkPyramid.GENERATION_PYRAMID.getStepTo(ChunkStatus.FULL);
|
| 14 | public static final int RADIUS_AROUND_FULL_CHUNK = FULL_CHUNK_STEP.accumulatedDependencies().getRadius();
|
| 15 | public static final int MAX_LEVEL = 33 + RADIUS_AROUND_FULL_CHUNK;
|
| 16 |
|
| 17 | public static @Nullable ChunkStatus generationStatus(final int level) {
|
| 18 | return getStatusAroundFullChunk(level - 33, null);
|
| 19 | }
|
| 20 |
|
| 21 | @Contract("_,!null->!null;_,_->_")
|
| 22 | public static @Nullable ChunkStatus getStatusAroundFullChunk(final int distanceToFullChunk, final @Nullable ChunkStatus defaultValue) {
|
| 23 | if (distanceToFullChunk > RADIUS_AROUND_FULL_CHUNK) {
|
| 24 | return defaultValue;
|
| 25 | } else {
|
| 26 | return distanceToFullChunk <= 0 ? ChunkStatus.FULL : FULL_CHUNK_STEP.accumulatedDependencies().get(distanceToFullChunk);
|
| 27 | }
|
| 28 | }
|
| 29 |
|
| 30 | public static ChunkStatus getStatusAroundFullChunk(final int distanceToFullChunk) {
|
| 31 | return getStatusAroundFullChunk(distanceToFullChunk, ChunkStatus.EMPTY);
|
| 32 | }
|
| 33 |
|
| 34 | public static int byStatus(final ChunkStatus status) {
|
| 35 | return 33 + FULL_CHUNK_STEP.getAccumulatedRadiusOf(status);
|
| 36 | }
|
| 37 |
|
| 38 | public static FullChunkStatus fullStatus(final int level) {
|
| 39 | if (level <= 31) {
|
| 40 | return FullChunkStatus.ENTITY_TICKING;
|
| 41 | } else if (level <= 32) {
|
| 42 | return FullChunkStatus.BLOCK_TICKING;
|
| 43 | } else {
|
| 44 | return level <= 33 ? FullChunkStatus.FULL : FullChunkStatus.INACCESSIBLE;
|
| 45 | }
|
| 46 | }
|
| 47 |
|
| 48 | public static int byStatus(final FullChunkStatus status) {
|
| 49 | return switch (status) {
|
| 50 | case INACCESSIBLE -> MAX_LEVEL;
|
| 51 | case FULL -> 33;
|
| 52 | case BLOCK_TICKING -> 32;
|
| 53 | case ENTITY_TICKING -> 31;
|
| 54 | };
|
| 55 | }
|
| 56 |
|
| 57 | public static boolean isEntityTicking(final int level) {
|
| 58 | return level <= 31;
|
| 59 | }
|
| 60 |
|
| 61 | public static boolean isBlockTicking(final int level) {
|
| 62 | return level <= 32;
|
| 63 | }
|
| 64 |
|
| 65 | public static boolean isLoaded(final int level) {
|
| 66 | return level <= MAX_LEVEL;
|
| 67 | }
|
| 68 | }
|
| 69 |
|