81 lines
2.4 KiB
Java
81 lines
2.4 KiB
Java
package net.minecraft.client.renderer.chunk;
|
|
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.api.Environment;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.core.SectionPos;
|
|
import net.minecraft.world.level.BlockAndTintGetter;
|
|
import net.minecraft.world.level.ColorResolver;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.lighting.LevelLightEngine;
|
|
import net.minecraft.world.level.material.FluidState;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public class RenderChunkRegion implements BlockAndTintGetter {
|
|
public static final int RADIUS = 1;
|
|
public static final int SIZE = 3;
|
|
private final int minChunkX;
|
|
private final int minChunkZ;
|
|
protected final RenderChunk[] chunks;
|
|
protected final Level level;
|
|
|
|
RenderChunkRegion(Level level, int minChunkX, int minChunkZ, RenderChunk[] chunks) {
|
|
this.level = level;
|
|
this.minChunkX = minChunkX;
|
|
this.minChunkZ = minChunkZ;
|
|
this.chunks = chunks;
|
|
}
|
|
|
|
@Override
|
|
public BlockState getBlockState(BlockPos pos) {
|
|
return this.getChunk(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getZ())).getBlockState(pos);
|
|
}
|
|
|
|
@Override
|
|
public FluidState getFluidState(BlockPos pos) {
|
|
return this.getChunk(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getZ())).getBlockState(pos).getFluidState();
|
|
}
|
|
|
|
@Override
|
|
public float getShade(Direction direction, boolean shade) {
|
|
return this.level.getShade(direction, shade);
|
|
}
|
|
|
|
@Override
|
|
public LevelLightEngine getLightEngine() {
|
|
return this.level.getLightEngine();
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public BlockEntity getBlockEntity(BlockPos pos) {
|
|
return this.getChunk(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getZ())).getBlockEntity(pos);
|
|
}
|
|
|
|
private RenderChunk getChunk(int x, int z) {
|
|
return this.chunks[index(this.minChunkX, this.minChunkZ, x, z)];
|
|
}
|
|
|
|
@Override
|
|
public int getBlockTint(BlockPos blockPos, ColorResolver colorResolver) {
|
|
return this.level.getBlockTint(blockPos, colorResolver);
|
|
}
|
|
|
|
@Override
|
|
public int getMinY() {
|
|
return this.level.getMinY();
|
|
}
|
|
|
|
@Override
|
|
public int getHeight() {
|
|
return this.level.getHeight();
|
|
}
|
|
|
|
public static int index(int minX, int minZ, int x, int z) {
|
|
return x - minX + (z - minZ) * 3;
|
|
}
|
|
}
|