| 1 | package net.minecraft.client.renderer;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.Minecraft;
|
| 6 | import net.minecraft.client.RotatingSectionStorage;
|
| 7 | import net.minecraft.client.renderer.chunk.SectionRenderDispatcher;
|
| 8 | import net.minecraft.core.BlockPos;
|
| 9 | import net.minecraft.core.SectionPos;
|
| 10 | import org.jspecify.annotations.Nullable;
|
| 11 |
|
| 12 | @Environment(EnvType.CLIENT)
|
| 13 | public class ViewArea {
|
| 14 | private final SectionOcclusionGraph sectionOcclusionGraph;
|
| 15 | private final RotatingSectionStorage<SectionRenderDispatcher.RenderSection> sections;
|
| 16 | private final int minY;
|
| 17 | private final int maxY;
|
| 18 |
|
| 19 | public ViewArea(
|
| 20 | final SectionRenderDispatcher sectionRenderDispatcher,
|
| 21 | final int minY,
|
| 22 | final int maxY,
|
| 23 | final int minSectionY,
|
| 24 | final int maxSectionY,
|
| 25 | final int renderDistance,
|
| 26 | final SectionOcclusionGraph sectionOcclusionGraph
|
| 27 | ) {
|
| 28 | this.sectionOcclusionGraph = sectionOcclusionGraph;
|
| 29 | this.minY = minY;
|
| 30 | this.maxY = maxY;
|
| 31 | if (!Minecraft.getInstance().isSameThread()) {
|
| 32 | throw new IllegalStateException("createSections called from wrong thread: " + Thread.currentThread().getName());
|
| 33 | }
|
| 34 |
|
| 35 | this.sections = new RotatingSectionStorage<>(
|
| 36 | renderDistance, minSectionY, maxSectionY, (index, sectionNode) -> sectionRenderDispatcher.new RenderSection(index, sectionNode)
|
| 37 | );
|
| 38 | }
|
| 39 |
|
| 40 | public void releaseAllBuffers() {
|
| 41 | for (SectionRenderDispatcher.RenderSection section : this.sections) {
|
| 42 | section.reset();
|
| 43 | }
|
| 44 | }
|
| 45 |
|
| 46 | public int size() {
|
| 47 | return this.sections.size();
|
| 48 | }
|
| 49 |
|
| 50 | public int minY() {
|
| 51 | return this.minY;
|
| 52 | }
|
| 53 |
|
| 54 | public int maxY() {
|
| 55 | return this.maxY;
|
| 56 | }
|
| 57 |
|
| 58 | public int minSectionY() {
|
| 59 | return this.sections.minY();
|
| 60 | }
|
| 61 |
|
| 62 | public int maxSectionY() {
|
| 63 | return this.sections.maxY();
|
| 64 | }
|
| 65 |
|
| 66 | public int sectionCount() {
|
| 67 | return this.sections.height();
|
| 68 | }
|
| 69 |
|
| 70 | public int getViewDistance() {
|
| 71 | return this.sections.radius();
|
| 72 | }
|
| 73 |
|
| 74 | public boolean repositionCamera(final SectionPos cameraSectionPos) {
|
| 75 | boolean result = this.sections.repositionCenter(cameraSectionPos);
|
| 76 | if (result) {
|
| 77 | this.sectionOcclusionGraph.invalidate();
|
| 78 | }
|
| 79 |
|
| 80 | return result;
|
| 81 | }
|
| 82 |
|
| 83 | public SectionPos getCameraSectionPos() {
|
| 84 | return this.sections.centerSectionPos();
|
| 85 | }
|
| 86 |
|
| 87 | public SectionRenderDispatcher.@Nullable RenderSection getRenderSectionAt(final BlockPos pos) {
|
| 88 | return this.sections.getValueAt(pos);
|
| 89 | }
|
| 90 |
|
| 91 | protected SectionRenderDispatcher.@Nullable RenderSection getRenderSection(final long sectionNode) {
|
| 92 | return this.sections.getValue(sectionNode);
|
| 93 | }
|
| 94 | }
|
| 95 |
|