public static final ExtendedBlockStorage NULL_BLOCK_STORAGE = null;
private final ExtendedBlockStorage[] storageArrays;
private final byte[] blockBiomeArray;
private final int[] precipitationHeightMap;
private final boolean[] updateSkylightColumns;
private boolean loaded;
private final World world;
private final int[] heightMap;
public final int x;
public final int z;
private boolean isGapLightingUpdated;
private final Map<BlockPos, TileEntity> tileEntities;
private final ClassInheritanceMultiMap<Entity>[] entityLists;
private boolean isTerrainPopulated;
private boolean isLightPopulated;
private boolean ticked;
private boolean dirty;
private boolean hasEntities;
private long lastSaveTime;
private int heightMapMinimum;
private long inhabitedTime;
private int queuedLightChecks;
private final ConcurrentLinkedQueue<BlockPos> tileEntityPosQueue;
public boolean unloadQueued;
public Biome getBiome(BlockPos pos, BiomeProvider provider)
public byte[] getBiomeArray()
public int getBlockLightOpacity(BlockPos pos)
private int getBlockLightOpacity(int x, int y, int z)
public IBlockState getBlockState(final int x, final int y, final int z)
public IBlockState getBlockState(BlockPos pos)
public ExtendedBlockStorage[] getBlockStorageArray()
public <T extends Entity> void getEntitiesOfTypeWithinAABB(Class <? extends T > entityClass, AxisAlignedBB aabb, List<T> listToFill, Predicate <? super T > filter)
public void getEntitiesWithinAABBForEntity(@Nullable Entity entityIn, AxisAlignedBB aabb, List<Entity> listToFill, Predicate <? super Entity > filter)
public ClassInheritanceMultiMap<Entity>[] getEntityLists()
public int getHeightValue(int x, int z)
public int getHeight(BlockPos pos)
public int[] getHeightMap()
public long getInhabitedTime()
private ExtendedBlockStorage getLastExtendedBlockStorage()
public int getLightFor(EnumSkyBlock type, BlockPos pos)
public int getLightSubtracted(BlockPos pos, int amount)
public ChunkPos getPos()
public BlockPos getPrecipitationHeight(BlockPos pos)
public Random getRandomWithSeed(long seed)
public TileEntity getTileEntity(BlockPos pos, Chunk.EnumCreateEntityType createType)
public Map<BlockPos, TileEntity> getTileEntityMap()
public int getTopFilledSegment()
public World getWorld()
/**
* Returns an array containing a 16x16 mapping on the X/Z of block positions in this Chunk to biome IDs.
* 返回Chunk中保存的16*16列的生物群系id数组
* @return
*/
public byte[] getBiomeArray()
{
return this.blockBiomeArray;
}
其实就是一个普通的get函数,没什么好讲的。
getBlockLightOpacity
/**
* 返回特定坐标的方块的不透明度
* @param pos 方块坐标对象
* @return 方块不透明度
*/
public int getBlockLightOpacity(BlockPos pos)
{
return this.getBlockState(pos).getLightOpacity(); //通过位置获得所在方块的方块状态对象,再从这里获得方块不透明度
}
方块光线不透明度封装在方块状态类里,而方块状态对象通过本类中getBlockState函数来获取。
getBlockLightOpacity
/**
* 返回特定坐标的方块的不透明度
* @param x x坐标值
* @param y y坐标值
* @param z z坐标值
* @return 方块不透明度
*/
private int getBlockLightOpacity(int x, int y, int z)
{
return this.getBlockState(x, y, z).getLightOpacity();
}
再次封装函数public IBlockState getBlockState(final int x, final int y, final int z),只传入封装方块位置的BlockPso对象。
getBlockStorageArray
/**
* Returns the ExtendedBlockStorage array for this Chunk.
* 从chunk返回section列表
*/
public ExtendedBlockStorage[] getBlockStorageArray()
{
return this.storageArrays;
}
返回本Chunk保存的Section数组。没什么好讲的。
getEntitiesOfTypeWithinAABB
/**
* @param entityClass
* @param aabb
* @param listToFill
* @param filter
* @param <T>
*/
public <T extends Entity> void getEntitiesOfTypeWithinAABB(Class <? extends T > entityClass, AxisAlignedBB aabb, List<T> listToFill, Predicate <? super T > filter)
{
int i = MathHelper.floor((aabb.minY - 2.0D) / 16.0D);
int j = MathHelper.floor((aabb.maxY + 2.0D) / 16.0D);
i = MathHelper.clamp(i, 0, this.entityLists.length - 1);
j = MathHelper.clamp(j, 0, this.entityLists.length - 1);
for (int k = i; k <= j; ++k)
{
for (T t : this.entityLists[k].getByClass(entityClass))
{
//如果选到的区域与aabb重叠且通过了过滤
if (t.getEntityBoundingBox().intersects(aabb) && (filter == null || filter.apply(t)))
{
listToFill.add(t); //就把它加入到列表中
}
}
}
}
还未知。
getEntitiesWithinAABBForEntity
/**
* Fills the given list of all entities that intersect within the given bounding box that aren't the passed entity.
* 填充给定边界框内相交但不是传递实体的所有实体的给定列表。
* @param entityIn
* @param aabb
* @param listToFill
* @param filter
*/
public void getEntitiesWithinAABBForEntity(@Nullable Entity entityIn, AxisAlignedBB aabb, List<Entity> listToFill, Predicate <? super Entity > filter)
{
int i = MathHelper.floor((aabb.minY - 2.0D) / 16.0D);
int j = MathHelper.floor((aabb.maxY + 2.0D) / 16.0D);
i = MathHelper.clamp(i, 0, this.entityLists.length - 1);
j = MathHelper.clamp(j, 0, this.entityLists.length - 1);
for (int k = i; k <= j; ++k)
{
if (!this.entityLists[k].isEmpty())
{
for (Entity entity : this.entityLists[k])
{
if (entity.getEntityBoundingBox().intersects(aabb) && entity != entityIn)
{
if (filter == null || filter.apply(entity))
{
listToFill.add(entity);
}
Entity[] aentity = entity.getParts();
if (aentity != null)
{
for (Entity entity1 : aentity)
{
if (entity1 != entityIn && entity1.getEntityBoundingBox().intersects(aabb) && (filter == null || filter.apply(entity1)))
{
listToFill.add(entity1);
}
}
}
}
}
}
}
}
/**
* Returns the value in the height map at this x, z coordinate in the chunk
* 获取x,z的地形高度
*/
public int getHeightValue(int x, int z)
{
return this.heightMap[z << 4 | x]; //把x,z转化为0-255的值,也就是说找到一个方块的坐标,转化为它的序号
}
/**
* 根据方块类型返回亮度
* 如果是空的,返回默认值
* 如果是天空,返回全局光照
* 如果是方块,返回局部光照
* @param type 方块类型
* @param pos 坐标对象
* @return 亮度值
*/
public int getLightFor(EnumSkyBlock type, BlockPos pos)
{
int i = pos.getX() & 15; //取 0-15之间,也就是一个section底面以内
int j = pos.getY();
int k = pos.getZ() & 15; //取 0-15之间,也就是一个section底面以内
ExtendedBlockStorage extendedblockstorage = this.storageArrays[j >> 4]; //得到所在section
if (extendedblockstorage == NULL_BLOCK_STORAGE)
{
//如果能看见天空,就返回默认的光亮值,如果看不见,就返回0
return this.canSeeSky(pos) ? type.defaultLightValue : 0;
}
else if (type == EnumSkyBlock.SKY)
{
//从section获得sky light
return !this.world.provider.hasSkyLight() ? 0 : extendedblockstorage.getSkyLight(i, j & 15, k);
}
else
{
return type == EnumSkyBlock.BLOCK ? extendedblockstorage.getBlockLight(i, j & 15, k) : type.defaultLightValue;//如果是一个block,就从block处返回局部光照,否则返回默认的光照
}
}
首先也是从方块位置对象中获得方块的x轴、y轴、z轴坐标值,同时把x轴和y轴&15,使之保持在0-15之间,也就是处于一个Chunk中,然后通过 y >> 4 来得出方块所在的section的id,再从storageArrays中索引section对象,如果section是非空的,且该方块的位置能看见天空,就返回默认的天光光线强度,如果看不见,就返回0,也就是没有天光。
/**
* 返回heightMap中最小的值
* @return heightMap中最小的值
*/
public int getLowestHeight()
{
return this.heightMapMinimum;
}
没啥好讲的,返回heightMap数组中最小的值
getPos
/**
* Gets a {@link ChunkPos} representing the x and z coordinates of this chunk.
* 返回一个封装好本Chunk的x轴和z轴坐标的ChunkPos对象
*/
public ChunkPos getPos()
{
return new ChunkPos(this.x, this.z);
}
返回一个封装好本Chunk的x轴和z轴坐标的ChunkPos对象
getPrecipitationHeight
/**
* 重新计算某个方块所在列的降水高度,方便给水滴动作一点的指示
* @param pos 封装好方块坐标的对象
* @return 这个方块所在列的降水应该停留的方块位置
*/
public BlockPos getPrecipitationHeight(BlockPos pos)
{
int i = pos.getX() & 15;
int j = pos.getZ() & 15;
int k = i | j << 4; //根据x,z轴获得在一个chunk平面的序号
////根据方块的x,z和降水高度获得接收到降水的区块的位置
BlockPos blockpos = new BlockPos(pos.getX(), this.precipitationHeightMap[k], pos.getZ());
if (blockpos.getY() == -999) //降水高度只被初始化了,没有被计算过,降水高度是无效的
{
int l = this.getTopFilledSegment() + 15; //取最上面非空section的最上面一层方块
blockpos = new BlockPos(pos.getX(), l, pos.getZ()); //获取该方块的位置对象
int i1 = -1; //定义初始降水高度
while (blockpos.getY() > 0 && i1 == -1) //如果方块存在且刚刚开始
{
IBlockState iblockstate = this.getBlockState(blockpos); //获得方块
Material material = iblockstate.getMaterial(); //获得材质
if (!material.blocksMovement() && !material.isLiquid()) //如果方块不是固体且方块不是液体
{
blockpos = blockpos.down(); //那就是空的呗,位置下降一格,大概是模拟雨滴下降的动作吧
}
else //如果是固体或者是液体,雨滴收到了遮挡
{
i1 = blockpos.getY() + 1; //降水高度应该是接触方块的上面一格
}
}
//如果你想获得0层以及0层以下的降水高度,那么降水高度是-1
this.precipitationHeightMap[k] = i1; //把降水高度赋值给列表
}
return new BlockPos(pos.getX(), this.precipitationHeightMap[k], pos.getZ()); //返回封装好的位置对象
}
/**
* 获得本Chunk所处的世界
* @return 本Chunk所处世界对象
*/
public World getWorld()
{
return this.world;
}
获得本Chunk所处的世界对象
set方法
public void setBiomeArray(byte[] biomeArray)
setBiomeArray
/**
* Accepts a 256-entry array that contains a 16x16 mapping on the X/Z plane of block positions in this Chunk to biome IDs.
* 接受一个256项数组,该数组包含该块中块位置X/Z平面上的16x16映射到biome IDs。
* 这里是chunk类中唯一一个可以写入blockBiomeArray的方法,构造方法只是初始化了变量
*/
public void setBiomeArray(byte[] biomeArray)
{
if (this.blockBiomeArray.length != biomeArray.length) //如果传入的数组长度不符合要求,就报错
{
LOGGER.warn("Could not set level chunk biomes, array length is {} instead of {}", Integer.valueOf(biomeArray.length), Integer.valueOf(this.blockBiomeArray.length));
}
else
{
System.arraycopy(biomeArray, 0, this.blockBiomeArray, 0, this.blockBiomeArray.length); //拷贝数组到blockBiomeArray
}
}