| 1 | package net.minecraft.client.renderer.chunk;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.multiplayer.ClientLevel;
|
| 6 | import net.minecraft.client.renderer.block.BlockAndTintGetter;
|
| 7 | import net.minecraft.core.BlockPos;
|
| 8 | import net.minecraft.core.SectionPos;
|
| 9 | import net.minecraft.world.level.CardinalLighting;
|
| 10 | import net.minecraft.world.level.ColorResolver;
|
| 11 | import net.minecraft.world.level.block.entity.BlockEntity;
|
| 12 | import net.minecraft.world.level.block.state.BlockState;
|
| 13 | import net.minecraft.world.level.lighting.LevelLightEngine;
|
| 14 | import net.minecraft.world.level.material.FluidState;
|
| 15 | import org.jspecify.annotations.Nullable;
|
| 16 |
|
| 17 | @Environment(EnvType.CLIENT)
|
| 18 | public class RenderSectionRegion implements BlockAndTintGetter {
|
| 19 | public static final int RADIUS = 1;
|
| 20 | public static final int SIZE = 3;
|
| 21 | private final int minSectionX;
|
| 22 | private final int minSectionY;
|
| 23 | private final int minSectionZ;
|
| 24 | private final SectionCopy[] sections;
|
| 25 | private final ClientLevel level;
|
| 26 | private final CardinalLighting cardinalLighting;
|
| 27 | private final LevelLightEngine lightEngine;
|
| 28 |
|
| 29 | public RenderSectionRegion(final ClientLevel level, final int minSectionX, final int minSectionY, final int minSectionZ, final SectionCopy[] sections) {
|
| 30 | this.level = level;
|
| 31 | this.minSectionX = minSectionX;
|
| 32 | this.minSectionY = minSectionY;
|
| 33 | this.minSectionZ = minSectionZ;
|
| 34 | this.sections = sections;
|
| 35 | this.cardinalLighting = level.cardinalLighting();
|
| 36 | this.lightEngine = level.getLightEngine();
|
| 37 | }
|
| 38 |
|
| 39 | @Override
|
| 40 | public BlockState getBlockState(final BlockPos pos) {
|
| 41 | return this.getSection(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getY()), SectionPos.blockToSectionCoord(pos.getZ()))
|
| 42 | .getBlockState(pos);
|
| 43 | }
|
| 44 |
|
| 45 | @Override
|
| 46 | public FluidState getFluidState(final BlockPos pos) {
|
| 47 | return this.getSection(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getY()), SectionPos.blockToSectionCoord(pos.getZ()))
|
| 48 | .getBlockState(pos)
|
| 49 | .getFluidState();
|
| 50 | }
|
| 51 |
|
| 52 | @Override
|
| 53 | public CardinalLighting cardinalLighting() {
|
| 54 | return this.cardinalLighting;
|
| 55 | }
|
| 56 |
|
| 57 | @Override
|
| 58 | public LevelLightEngine getLightEngine() {
|
| 59 | return this.lightEngine;
|
| 60 | }
|
| 61 |
|
| 62 | @Override
|
| 63 | public @Nullable BlockEntity getBlockEntity(final BlockPos pos) {
|
| 64 | return this.getSection(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getY()), SectionPos.blockToSectionCoord(pos.getZ()))
|
| 65 | .getBlockEntity(pos);
|
| 66 | }
|
| 67 |
|
| 68 | private SectionCopy getSection(final int sectionX, final int sectionY, final int sectionZ) {
|
| 69 | return this.sections[index(this.minSectionX, this.minSectionY, this.minSectionZ, sectionX, sectionY, sectionZ)];
|
| 70 | }
|
| 71 |
|
| 72 | @Override
|
| 73 | public int getBlockTint(final BlockPos pos, final ColorResolver resolver) {
|
| 74 | return this.level.getBlockTint(pos, resolver);
|
| 75 | }
|
| 76 |
|
| 77 | @Override
|
| 78 | public int getMinY() {
|
| 79 | return this.level.getMinY();
|
| 80 | }
|
| 81 |
|
| 82 | @Override
|
| 83 | public int getHeight() {
|
| 84 | return this.level.getHeight();
|
| 85 | }
|
| 86 |
|
| 87 | public static int index(final int minSectionX, final int minSectionY, final int minSectionZ, final int sectionX, final int sectionY, final int sectionZ) {
|
| 88 | return sectionX - minSectionX + (sectionY - minSectionY) * 3 + (sectionZ - minSectionZ) * 3 * 3;
|
| 89 | }
|
| 90 | }
|
| 91 |
|