| 1 | package net.minecraft.client.renderer;
|
| 2 |
|
| 3 | import java.util.Arrays;
|
| 4 | import net.minecraft.block.state.IBlockState;
|
| 5 | import net.minecraft.init.Blocks;
|
| 6 | import net.minecraft.tileentity.TileEntity;
|
| 7 | import net.minecraft.util.BlockPos;
|
| 8 | import net.minecraft.util.Vec3i;
|
| 9 | import net.minecraft.world.ChunkCache;
|
| 10 | import net.minecraft.world.World;
|
| 11 | import net.minecraft.world.chunk.Chunk;
|
| 12 |
|
| 13 | public class RegionRenderCache extends ChunkCache
|
| 14 | {
|
| 15 | private static final IBlockState DEFAULT_STATE = Blocks.air.getDefaultState();
|
| 16 | private final BlockPos position;
|
| 17 | private int[] combinedLights;
|
| 18 | private IBlockState[] blockStates;
|
| 19 |
|
| 20 | public RegionRenderCache(World worldIn, BlockPos posFromIn, BlockPos posToIn, int subIn)
|
| 21 | {
|
| 22 | super(worldIn, posFromIn, posToIn, subIn);
|
| 23 | this.position = posFromIn.subtract(new Vec3i(subIn, subIn, subIn));
|
| 24 | int i = 8000;
|
| 25 | this.combinedLights = new int[8000];
|
| 26 | Arrays.fill((int[])this.combinedLights, (int) - 1);
|
| 27 | this.blockStates = new IBlockState[8000];
|
| 28 | }
|
| 29 |
|
| 30 | public TileEntity getTileEntity(BlockPos pos)
|
| 31 | {
|
| 32 | int i = (pos.getX() >> 4) - this.chunkX;
|
| 33 | int j = (pos.getZ() >> 4) - this.chunkZ;
|
| 34 | return this.chunkArray[i][j].getTileEntity(pos, Chunk.EnumCreateEntityType.QUEUED);
|
| 35 | }
|
| 36 |
|
| 37 | public int getCombinedLight(BlockPos pos, int lightValue)
|
| 38 | {
|
| 39 | int i = this.getPositionIndex(pos);
|
| 40 | int j = this.combinedLights[i];
|
| 41 |
|
| 42 | if (j == -1)
|
| 43 | {
|
| 44 | j = super.getCombinedLight(pos, lightValue);
|
| 45 | this.combinedLights[i] = j;
|
| 46 | }
|
| 47 |
|
| 48 | return j;
|
| 49 | }
|
| 50 |
|
| 51 | public IBlockState getBlockState(BlockPos pos)
|
| 52 | {
|
| 53 | int i = this.getPositionIndex(pos);
|
| 54 | IBlockState iblockstate = this.blockStates[i];
|
| 55 |
|
| 56 | if (iblockstate == null)
|
| 57 | {
|
| 58 | iblockstate = this.getBlockStateRaw(pos);
|
| 59 | this.blockStates[i] = iblockstate;
|
| 60 | }
|
| 61 |
|
| 62 | return iblockstate;
|
| 63 | }
|
| 64 |
|
| 65 | private IBlockState getBlockStateRaw(BlockPos pos)
|
| 66 | {
|
| 67 | if (pos.getY() >= 0 && pos.getY() < 256)
|
| 68 | {
|
| 69 | int i = (pos.getX() >> 4) - this.chunkX;
|
| 70 | int j = (pos.getZ() >> 4) - this.chunkZ;
|
| 71 | return this.chunkArray[i][j].getBlockState(pos);
|
| 72 | }
|
| 73 | else
|
| 74 | {
|
| 75 | return DEFAULT_STATE;
|
| 76 | }
|
| 77 | }
|
| 78 |
|
| 79 | private int getPositionIndex(BlockPos p_175630_1_)
|
| 80 | {
|
| 81 | int i = p_175630_1_.getX() - this.position.getX();
|
| 82 | int j = p_175630_1_.getY() - this.position.getY();
|
| 83 | int k = p_175630_1_.getZ() - this.position.getZ();
|
| 84 | return i * 400 + k * 20 + j;
|
| 85 | }
|
| 86 | }
|
| 87 |
|