public boolean shouldRender( T livingEntity, ICamera camera, double camX, double camY, double camZ) { AxisAlignedBB axisalignedbb = livingEntity.getEntityBoundingBox(); if (axisalignedbb.func_181656_b() || axisalignedbb.getAverageEdgeLength() == 0.0D) { axisalignedbb = new AxisAlignedBB( livingEntity.posX - 2.0D, livingEntity.posY - 2.0D, livingEntity.posZ - 2.0D, livingEntity.posX + 2.0D, livingEntity.posY + 2.0D, livingEntity.posZ + 2.0D); } return livingEntity.isInRangeToRender3d(camX, camY, camZ) && (livingEntity.ignoreFrustumCheck || camera.isBoundingBoxInFrustum(axisalignedbb)); }
public void updateInFrustum(ICamera par1ICamera) { this.isInFrustum = par1ICamera.isBoundingBoxInFrustum(this.rendererBoundingBox); }
@Override public void setupTerrain( final Entity viewEntity, final double partialTicks, final ICamera camera, final int frameCount, final boolean playerSpectator) { if (ConfigurationHandler.renderDistance != this.renderDistanceChunks || this.vboEnabled != OpenGlHelper.useVbo()) { loadRenderers(); } this.profiler.startSection("camera"); final double posX = PLAYER_POSITION_OFFSET.x; final double posY = PLAYER_POSITION_OFFSET.y; final double posZ = PLAYER_POSITION_OFFSET.z; final double deltaX = posX - this.frustumUpdatePosX; final double deltaY = posY - this.frustumUpdatePosY; final double deltaZ = posZ - this.frustumUpdatePosZ; final int chunkCoordX = MathHelper.floor_double(posX) >> 4; final int chunkCoordY = MathHelper.floor_double(posY) >> 4; final int chunkCoordZ = MathHelper.floor_double(posZ) >> 4; if (this.frustumUpdatePosChunkX != chunkCoordX || this.frustumUpdatePosChunkY != chunkCoordY || this.frustumUpdatePosChunkZ != chunkCoordZ || deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ > 16.0) { this.frustumUpdatePosX = posX; this.frustumUpdatePosY = posY; this.frustumUpdatePosZ = posZ; this.frustumUpdatePosChunkX = chunkCoordX; this.frustumUpdatePosChunkY = chunkCoordY; this.frustumUpdatePosChunkZ = chunkCoordZ; this.viewFrustum.updateChunkPositions(posX, posZ); } this.profiler.endStartSection("renderlistcamera"); this.renderContainer.initialize(posX, posY, posZ); this.profiler.endStartSection("culling"); final BlockPos posEye = new BlockPos(posX, posY + viewEntity.getEyeHeight(), posZ); final RenderChunk renderchunk = this.viewFrustum.getRenderChunk(posEye); final RenderOverlay renderoverlay = this.viewFrustum.getRenderOverlay(posEye); this.displayListEntitiesDirty = this.displayListEntitiesDirty || !this.chunksToUpdate.isEmpty() || posX != this.lastViewEntityX || posY != this.lastViewEntityY || posZ != this.lastViewEntityZ || viewEntity.rotationPitch != this.lastViewEntityPitch || viewEntity.rotationYaw != this.lastViewEntityYaw; this.lastViewEntityX = posX; this.lastViewEntityY = posY; this.lastViewEntityZ = posZ; this.lastViewEntityPitch = viewEntity.rotationPitch; this.lastViewEntityYaw = viewEntity.rotationYaw; if (this.displayListEntitiesDirty) { this.displayListEntitiesDirty = false; this.renderInfos = Lists.newArrayListWithCapacity(CHUNKS); final LinkedList<ContainerLocalRenderInformation> renderInfoList = Lists.newLinkedList(); boolean renderChunksMany = this.mc.renderChunksMany; if (renderchunk == null) { final int chunkY = posEye.getY() > 0 ? 248 : 8; for (int chunkX = -this.renderDistanceChunks; chunkX <= this.renderDistanceChunks; chunkX++) { for (int chunkZ = -this.renderDistanceChunks; chunkZ <= this.renderDistanceChunks; chunkZ++) { final BlockPos pos = new BlockPos((chunkX << 4) + 8, chunkY, (chunkZ << 4) + 8); final RenderChunk renderChunk = this.viewFrustum.getRenderChunk(pos); final RenderOverlay renderOverlay = this.viewFrustum.getRenderOverlay(pos); if (renderChunk != null && camera.isBoundingBoxInFrustum(renderChunk.boundingBox)) { renderChunk.setFrameIndex(frameCount); renderOverlay.setFrameIndex(frameCount); renderInfoList.add( new ContainerLocalRenderInformation(renderChunk, renderOverlay, null, 0)); } } } } else { boolean add = false; final ContainerLocalRenderInformation renderInfo = new ContainerLocalRenderInformation(renderchunk, renderoverlay, null, 0); final Set<EnumFacing> visibleSides = getVisibleSides(posEye); if (!visibleSides.isEmpty() && visibleSides.size() == 1) { final Vector3f viewVector = getViewVector(viewEntity, partialTicks); final EnumFacing facing = EnumFacing.getFacingFromVector(viewVector.x, viewVector.y, viewVector.z) .getOpposite(); visibleSides.remove(facing); } if (visibleSides.isEmpty()) { add = true; } if (add && !playerSpectator) { this.renderInfos.add(renderInfo); } else { if (playerSpectator && this.world.getBlockState(posEye).getBlock().isOpaqueCube()) { renderChunksMany = false; } renderchunk.setFrameIndex(frameCount); renderoverlay.setFrameIndex(frameCount); renderInfoList.add(renderInfo); } } while (!renderInfoList.isEmpty()) { final ContainerLocalRenderInformation renderInfo = renderInfoList.poll(); final RenderChunk renderChunk = renderInfo.renderChunk; final EnumFacing facing = renderInfo.facing; final BlockPos posChunk = renderChunk.getPosition(); this.renderInfos.add(renderInfo); for (final EnumFacing side : EnumFacing.VALUES) { final RenderChunk neighborRenderChunk = getNeighborRenderChunk(posEye, posChunk, side); final RenderOverlay neighborRenderOverlay = getNeighborRenderOverlay(posEye, posChunk, side); if ((!renderChunksMany || !renderInfo.setFacing.contains(side.getOpposite())) && (!renderChunksMany || facing == null || renderChunk.getCompiledChunk().isVisible(facing.getOpposite(), side)) && neighborRenderChunk != null && neighborRenderChunk.setFrameIndex(frameCount) && camera.isBoundingBoxInFrustum(neighborRenderChunk.boundingBox)) { final ContainerLocalRenderInformation renderInfoNext = new ContainerLocalRenderInformation( neighborRenderChunk, neighborRenderOverlay, side, renderInfo.counter + 1); renderInfoNext.setFacing.addAll(renderInfo.setFacing); renderInfoNext.setFacing.add(side); renderInfoList.add(renderInfoNext); } } } } this.renderDispatcher.clearChunkUpdates(); this.renderDispatcherOverlay.clearChunkUpdates(); final Set<RenderChunk> set = this.chunksToUpdate; final Set<RenderOverlay> set1 = this.overlaysToUpdate; this.chunksToUpdate = Sets.newLinkedHashSet(); for (final ContainerLocalRenderInformation renderInfo : this.renderInfos) { final RenderChunk renderChunk = renderInfo.renderChunk; final RenderOverlay renderOverlay = renderInfo.renderOverlay; if (renderChunk.isNeedsUpdate() || renderChunk.isCompileTaskPending() || set.contains(renderChunk)) { this.displayListEntitiesDirty = true; this.chunksToUpdate.add(renderChunk); } if (renderOverlay.isNeedsUpdate() || renderOverlay.isCompileTaskPending() || set1.contains(renderOverlay)) { this.displayListEntitiesDirty = true; this.overlaysToUpdate.add(renderOverlay); } } this.chunksToUpdate.addAll(set); this.overlaysToUpdate.addAll(set1); this.profiler.endSection(); }
@Override public void renderEntities( final Entity renderViewEntity, final ICamera camera, final float partialTicks) { final int entityPass = 0; this.profiler.startSection("prepare"); TileEntityRendererDispatcher.instance.cacheActiveRenderInfo( this.world, this.mc.getTextureManager(), this.mc.fontRendererObj, renderViewEntity, partialTicks); this.renderManager.cacheActiveRenderInfo( this.world, this.mc.fontRendererObj, renderViewEntity, this.mc.pointedEntity, this.mc.gameSettings, partialTicks); this.countEntitiesTotal = 0; this.countEntitiesRendered = 0; this.countTileEntitiesTotal = 0; this.countTileEntitiesRendered = 0; final double x = PLAYER_POSITION_OFFSET.x; final double y = PLAYER_POSITION_OFFSET.y; final double z = PLAYER_POSITION_OFFSET.z; TileEntityRendererDispatcher.staticPlayerX = x; TileEntityRendererDispatcher.staticPlayerY = y; TileEntityRendererDispatcher.staticPlayerZ = z; TileEntityRendererDispatcher.instance.entityX = x; TileEntityRendererDispatcher.instance.entityY = y; TileEntityRendererDispatcher.instance.entityZ = z; this.renderManager.setRenderPosition(x, y, z); this.mc.entityRenderer.enableLightmap(); this.profiler.endStartSection("blockentities"); RenderHelper.enableStandardItemLighting(); for (final ContainerLocalRenderInformation renderInfo : this.renderInfos) { for (final TileEntity tileEntity : (List<TileEntity>) renderInfo.renderChunk.getCompiledChunk().getTileEntities()) { final AxisAlignedBB renderBB = tileEntity.getRenderBoundingBox(); this.countTileEntitiesTotal++; if (!tileEntity.shouldRenderInPass(entityPass) || !camera.isBoundingBoxInFrustum(renderBB)) { continue; } if (!this.mc.theWorld.isAirBlock(tileEntity.getPos().add(this.world.position))) { continue; } TileEntityRendererDispatcher.instance.renderTileEntity(tileEntity, partialTicks, -1); this.countTileEntitiesRendered++; } } this.mc.entityRenderer.disableLightmap(); this.profiler.endSection(); }