Java 类net.minecraft.client.renderer.culling.Frustrum 实例源码

项目:Network    文件:MobHealthBars.java   
@SubscribeEvent
public void onRenderWorldLast(RenderWorldLastEvent event) {
    Minecraft mc = Minecraft.getMinecraft();
    if (!Minecraft.isGuiEnabled())
        return;
    EntityLivingBase cameraEntity = mc.renderViewEntity;
    Vec3 renderingVector = cameraEntity.getPosition(event.partialTicks);
    Frustrum frustrum = new Frustrum();

    double viewX = cameraEntity.lastTickPosX + (cameraEntity.posX - cameraEntity.lastTickPosX) * event.partialTicks;
    double viewY = cameraEntity.lastTickPosY + (cameraEntity.posY - cameraEntity.lastTickPosY) * event.partialTicks;
    double viewZ = cameraEntity.lastTickPosZ + (cameraEntity.posZ - cameraEntity.lastTickPosZ) * event.partialTicks;
    frustrum.setPosition(viewX, viewY, viewZ);

    List<Entity> loadedEntities = mc.theWorld.getLoadedEntityList();
    for (Entity entity : loadedEntities) {
        if (entity != null && entity instanceof EntityLivingBase && entity.isInRangeToRender3d(renderingVector.xCoord, renderingVector.yCoord, renderingVector.zCoord) && (entity.ignoreFrustumCheck || frustrum.isBoundingBoxInFrustum(entity.boundingBox)) && entity.isEntityAlive()) {
            renderHealthBar((EntityLivingBase) entity, event.partialTicks, cameraEntity);
        }
    }
}