Java 类net.minecraftforge.client.event.EntityViewRenderEvent.FogDensity 实例源码

项目:PerFabricaAdAstra    文件:FogHandler.java   
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onFogDensity(FogDensity event) {
    IndustrialFluidBlock block = IndustrialFluidBlock.atEyeLevel(event.entity);
    if (block != null) {
        Fluid fluid = block.getFluid();
        GL11.glFogi(GL11.GL_FOG_MODE, GL11.GL_EXP);
        if (!fluid.isGaseous() && event.entity.isPotionActive(Potion.waterBreathing))
        {
            event.density = 0.05F;
        }
        else
        {
            event.density = 0.1F - (float)EnchantmentHelper.getRespiration(event.entity) * 0.03F;
        }
        event.setCanceled(true);
    }
}
项目:Artifacts    文件:ArtifactClientEventHandler.java   
@SubscribeEvent
public void onFogRender(FogDensity event) {
    //Handle player "cloaking" with Obscurity component.
    Minecraft mc = Minecraft.getMinecraft();
    if((cloaked && !mc.thePlayer.isPotionActive(Potion.invisibility)) || mc.thePlayer.isPotionActive(Potion.blindness)) {
        cloaked = false;
    }

    //Make the fog max depend on the render distance.
    float fogMax = mc.gameSettings.renderDistanceChunks * 16;
    if(fogCurrent > fogMax) {
        fogCurrent = fogMax;
    }

       //Check if the effect should or shouldn't be applied (it shouldn't if the player already has a strong fog effect).
    if(!mc.thePlayer.isPotionActive(Potion.blindness) && !mc.thePlayer.isInsideOfMaterial(Material.water) && !mc.thePlayer.isInsideOfMaterial(Material.lava)) {
       //Note to self - this didn't work that well: && !BlockQuickSand.headInQuicksand(mc.theWorld, MathHelper.floor_double(mc.thePlayer.posX), MathHelper.floor_double(mc.thePlayer.posY + mc.thePlayer.getEyeHeight()), MathHelper.floor_double(mc.thePlayer.posZ), mc.thePlayer)

        //If the player is cloaked, render the fog coming in. It stops when it reaches fogMin.
        if(cloaked) {
            event.setCanceled(true);
            if(fogCurrent > fogMin + 0.01) {
                fogCurrent -= (fogCurrent-fogMin)/fogMax * 0.3f;
            }
        }
        //Otherwise render the fog going out, then stop rendering when it reaches fogMax.
        else {
            if(fogCurrent < fogMax) {
                event.setCanceled(true);

                fogCurrent += 0.1f;
            }
        } 
    }
    else {
        //"Insta-move" the fog if it isn't rendering.
        if(cloaked) {
            fogCurrent = fogMin;
        }
        else {
            fogCurrent = fogMax;
        }
    }

    //Render the fog.
    if(event.isCanceled()) {
        GL11.glFogi(GL11.GL_FOG_MODE, GL11.GL_LINEAR);

        GL11.glFogf(GL11.GL_FOG_START, fogCurrent * 0.25F);
        GL11.glFogf(GL11.GL_FOG_END, fogCurrent);

        if (GLContext.getCapabilities().GL_NV_fog_distance)
        {
            GL11.glFogi(34138, 34139);
        }
    }
}