Search in sources :

Example 1 with Color

use of org.blockartistry.lib.Color in project DynamicSurroundings by OreCruncher.

the class EntityHealthPopoffEffect method update.

@Override
public void update(@Nonnull final Entity subject) {
    if (!ModOptions.player.enableDamagePopoffs)
        return;
    final EntityLivingBase entity = (EntityLivingBase) subject;
    if (this.lastHealth != entity.getHealth()) {
        final World world = EnvironState.getWorld();
        final int adjustment = MathHelper.ceil(entity.getHealth() - this.lastHealth);
        this.lastHealth = entity.getHealth();
        // Don't display if it is the current player in first person view
        if (!EnvironState.isPlayer(subject) || !isFirstPersonView()) {
            final int delta = Math.max(1, MathStuff.abs(adjustment));
            final int criticalAmount = (int) (entity.getMaxHealth() / 2.5F);
            final AxisAlignedBB bb = entity.getEntityBoundingBox();
            final double posX = entity.posX;
            final double posY = bb.maxY + 0.5D;
            final double posZ = entity.posZ;
            final String text = String.valueOf(delta);
            final Color color = adjustment > 0 ? HEAL_TEXT_COLOR : DAMAGE_TEXT_COLOR;
            ParticleTextPopOff particle = null;
            if (ModOptions.player.showCritWords && adjustment < 0 && delta >= criticalAmount) {
                particle = new ParticleTextPopOff(world, getPowerWord(), CRITICAL_TEXT_COLOR, posX, posY + 0.5D, posZ);
                getState().addParticle(particle);
            }
            particle = new ParticleTextPopOff(world, text, color, posX, posY, posZ);
            getState().addParticle(particle);
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ParticleTextPopOff(org.blockartistry.DynSurround.client.fx.particle.ParticleTextPopOff) Color(org.blockartistry.lib.Color) EntityLivingBase(net.minecraft.entity.EntityLivingBase) World(net.minecraft.world.World)

Example 2 with Color

use of org.blockartistry.lib.Color in project DynamicSurroundings by OreCruncher.

the class StormRenderer method render.

/**
 * Render rain and snow
 */
public void render(@Nonnull final EntityRenderer renderer, final float partialTicks) {
    // Don't use EnvironState - may not have been initialized when rendering
    // starts.
    final Minecraft mc = Minecraft.getMinecraft();
    final World world = mc.world;
    if (!ClientRegistry.DIMENSION.hasWeather(world))
        return;
    final float rainStrength = Weather.getIntensityLevel();
    if (rainStrength <= 0.0F)
        return;
    final float alphaRatio = rainStrength / Weather.getMaxIntensityLevel();
    renderer.enableLightmap();
    GlStateManager.disableCull();
    GlStateManager.glNormal3f(0.0F, 1.0F, 0.0F);
    GlStateManager.enableBlend();
    GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
    GlStateManager.alphaFunc(516, 0.1F);
    final int range = mc.gameSettings.fancyGraphics ? 10 : 5;
    final float f1 = RenderWeather.rendererUpdateCount + partialTicks;
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    final SeasonInfo season = ClientRegistry.SEASON.getData(world);
    final Weather.Properties props = Weather.getWeatherProperties();
    final Entity entity = mc.getRenderViewEntity();
    final BlockPos playerPos = EnvironState.getPlayerPosition();
    final int playerX = playerPos.getX();
    final int playerY = playerPos.getY();
    final int playerZ = playerPos.getZ();
    for (int gridZ = playerZ - range; gridZ <= playerZ + range; ++gridZ) {
        for (int gridX = playerX - range; gridX <= playerX + range; ++gridX) {
            final int idx = (gridZ - playerZ + 16) * 32 + gridX - playerX + 16;
            final double rainX = RAIN_X_COORDS[idx];
            final double rainY = RAIN_Y_COORDS[idx];
            this.mutable.setPos(gridX, 0, gridZ);
            if (!RandomThings.shouldRain(world, this.mutable))
                continue;
            final BiomeInfo biome = ClientRegistry.BIOME.get(ClientChunkCache.INSTANCE.getBiome(this.mutable));
            if (!biome.hasWeatherEffect())
                continue;
            final int precipHeight = season.getPrecipitationHeight(world, this.mutable).getY();
            final int k2 = Math.max(playerY - range, precipHeight);
            final int l2 = Math.max(playerY + range, precipHeight);
            if (k2 == l2)
                continue;
            final int i3 = Math.max(precipHeight, locY);
            this.random.setSeed(gridX * gridX * 3121 + gridX * 45238971 ^ gridZ * gridZ * 418711 + gridZ * 13761);
            this.mutable.setPos(gridX, k2, gridZ);
            final boolean canSnow = season.canWaterFreeze(world, this.mutable);
            final double d6 = gridX + 0.5F - entity.posX;
            final double d7 = gridZ + 0.5F - entity.posZ;
            final float f3 = MathHelper.sqrt(d6 * d6 + d7 * d7) / range;
            this.mutable.setPos(gridX, i3, gridZ);
            final int combinedLight = ClientChunkCache.INSTANCE.getCombinedLight(this.mutable, 0);
            if (!biome.getHasDust() && !canSnow) {
                setupForRender(props.getRainTexture());
                // d8 makes the rain fall down. Assumes texture height of 512 pixels.
                final double d5 = ((double) (RenderWeather.rendererUpdateCount + gridX * gridX * 3121 + gridX * 45238971 + gridZ * gridZ * 418711 + gridZ * 13761 & 31) + (double) partialTicks) / 32.0D * (3.0D + this.random.nextDouble());
                final float alpha = ((1.0F - f3 * f3) * 0.5F + 0.5F) * alphaRatio;
                final int slX16 = combinedLight >> 16 & 65535;
                final int blX16 = combinedLight & 65535;
                worldrenderer.pos(gridX - rainX + 0.5D, k2, gridZ - rainY + 0.5D).tex(0.0D, k2 * 0.25D + d5).color(1.0F, 1.0F, 1.0F, alpha).lightmap(slX16, blX16).endVertex();
                worldrenderer.pos(gridX + rainX + 0.5D, k2, gridZ + rainY + 0.5D).tex(1.0D, k2 * 0.25D + d5).color(1.0F, 1.0F, 1.0F, alpha).lightmap(slX16, blX16).endVertex();
                worldrenderer.pos(gridX + rainX + 0.5D, l2, gridZ + rainY + 0.5D).tex(1.0D, l2 * 0.25D + d5).color(1.0F, 1.0F, 1.0F, alpha).lightmap(slX16, blX16).endVertex();
                worldrenderer.pos(gridX - rainX + 0.5D, l2, gridZ - rainY + 0.5D).tex(0.0D, l2 * 0.25D + d5).color(1.0F, 1.0F, 1.0F, alpha).lightmap(slX16, blX16).endVertex();
            } else {
                ResourceLocation texture = props.getSnowTexture();
                if (biome.getHasDust() && !canSnow)
                    texture = props.getDustTexture();
                setupForRender(texture);
                final Color color;
                if (biome.getHasDust())
                    color = biome.getDustColor();
                else
                    color = Color.WHITE;
                // d8 makes the snow fall down. Assumes texture height of 512 pixels.
                final double d8 = ((RenderWeather.rendererUpdateCount & 511) + partialTicks) / 512.0F;
                // The 0.2F factor was originally 0.01F. It
                // affects the horizontal movement of particles,
                // which works well for dust.
                final float factor = biome.getHasDust() ? 0.2F : 0.01F;
                // d9 shifts the texture left/right
                final double d9 = this.random.nextDouble() + (double) f1 * factor * ((float) this.random.nextGaussian());
                // d10 shifts the texture up/down
                final double d10 = this.random.nextDouble() + f1 * (float) this.random.nextGaussian() * 0.001D;
                final float alpha = ((1.0F - f3 * f3) * 0.3F + 0.5F) * alphaRatio;
                final int cl = (combinedLight * 3 + 15728880) / 4;
                final int slX16 = cl >> 16 & 65535;
                final int blX16 = cl & 65535;
                worldrenderer.pos(gridX - rainX + 0.5D, k2, gridZ - rainY + 0.5D).tex(0.0D + d9, k2 * 0.25D + d8 + d10).color(color.red, color.green, color.blue, alpha).lightmap(slX16, blX16).endVertex();
                worldrenderer.pos(gridX + rainX + 0.5D, k2, gridZ + rainY + 0.5D).tex(1.0D + d9, k2 * 0.25D + d8 + d10).color(color.red, color.green, color.blue, alpha).lightmap(slX16, blX16).endVertex();
                worldrenderer.pos(gridX + rainX + 0.5D, l2, gridZ + rainY + 0.5D).tex(1.0D + d9, l2 * 0.25D + d8 + d10).color(color.red, color.green, color.blue, alpha).lightmap(slX16, blX16).endVertex();
                worldrenderer.pos(gridX - rainX + 0.5D, l2, gridZ - rainY + 0.5D).tex(0.0D + d9, l2 * 0.25D + d8 + d10).color(color.red, color.green, color.blue, alpha).lightmap(slX16, blX16).endVertex();
            }
        }
    }
    closeRender();
    GlStateManager.enableCull();
    GlStateManager.disableBlend();
    GlStateManager.alphaFunc(516, 0.1F);
    renderer.disableLightmap();
}
Also used : Entity(net.minecraft.entity.Entity) Color(org.blockartistry.lib.Color) BiomeInfo(org.blockartistry.DynSurround.registry.BiomeInfo) World(net.minecraft.world.World) Minecraft(net.minecraft.client.Minecraft) ResourceLocation(net.minecraft.util.ResourceLocation) SeasonInfo(org.blockartistry.DynSurround.registry.season.SeasonInfo) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with Color

use of org.blockartistry.lib.Color in project DynamicSurroundings by OreCruncher.

the class LightLevelHUD method updateLightInfo.

protected static void updateLightInfo(@Nonnull final RenderManager manager, final double x, final double y, final double z) {
    font = Minecraft.getMinecraft().fontRenderer;
    final boolean isThirdPerson = manager.options.thirdPersonView == 2;
    // Position frustum behind the player in order to reduce
    // clipping of nearby light level textures. Purpose of the
    // frustum is to reduce processing requirements and does
    // not have to be perfect.
    final EntityPlayer player = EnvironState.getPlayer();
    final Vec3d lookVec = player.getLookVec();
    final double fX, fY, fZ;
    if (isThirdPerson) {
        fX = x + lookVec.x * 2D;
        fY = y + lookVec.y * 2D;
        fZ = z + lookVec.z * 2D;
    } else {
        fX = x - lookVec.x * 2D;
        fY = y - lookVec.y * 2D;
        fZ = z - lookVec.z * 2D;
    }
    frustum.setPosition(fX, fY, fZ);
    nextCoord = 0;
    final ColorSet colors = ColorSet.getStyle(ModOptions.lightlevel.llColors);
    final Mode displayMode = Mode.getMode(ModOptions.lightlevel.llDisplayMode);
    final int skyLightSub = EnvironState.getWorld().calculateSkylightSubtracted(1.0F);
    final int rangeXZ = ModOptions.lightlevel.llBlockRange * 2 + 1;
    final int rangeY = ModOptions.lightlevel.llBlockRange + 1;
    final int originX = MathStuff.floor(x) - (rangeXZ / 2);
    final int originZ = MathStuff.floor(z) - (rangeXZ / 2);
    final int originY = MathStuff.floor(y) - (rangeY - 3);
    final IBlockAccessEx blocks = ClientChunkCache.INSTANCE;
    for (int dX = 0; dX < rangeXZ; dX++) for (int dZ = 0; dZ < rangeXZ; dZ++) {
        final int trueX = originX + dX;
        final int trueZ = originZ + dZ;
        if (!blocks.isAvailable(trueX, trueZ))
            return;
        IBlockState lastState = null;
        for (int dY = 0; dY < rangeY; dY++) {
            final int trueY = originY + dY;
            if (trueY < 1 || !inFrustum(trueX, trueY, trueZ))
                continue;
            final IBlockState state = blocks.getBlockState(trueX, trueY, trueZ);
            if (lastState == null)
                lastState = blocks.getBlockState(trueX, trueY - 1, trueZ);
            if (renderLightLevel(state, lastState)) {
                mutable.setPos(trueX, trueY, trueZ);
                final boolean mobSpawn = canMobSpawn(mutable);
                if (mobSpawn || !ModOptions.lightlevel.llHideSafe) {
                    final int blockLight = blocks.getLightFor(EnumSkyBlock.BLOCK, mutable);
                    final int skyLight = blocks.getLightFor(EnumSkyBlock.SKY, mutable) - skyLightSub;
                    final int effective = Math.max(blockLight, skyLight);
                    final int result = displayMode == Mode.BLOCK_SKY ? effective : blockLight;
                    Color color = colors.safe;
                    if (!mobSpawn) {
                        color = colors.noSpawn;
                    } else if (blockLight <= ModOptions.lightlevel.llSpawnThreshold) {
                        if (effective > ModOptions.lightlevel.llSpawnThreshold)
                            color = colors.caution;
                        else
                            color = colors.hazard;
                    }
                    if (!(color == colors.safe && ModOptions.lightlevel.llHideSafe)) {
                        final LightCoord coord = nextCoord();
                        coord.x = trueX;
                        coord.y = trueY + heightAdjustment(state, lastState, mutable);
                        coord.z = trueZ;
                        coord.lightLevel = result;
                        coord.color = color;
                    }
                }
            }
            lastState = state;
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IBlockAccessEx(org.blockartistry.lib.chunk.IBlockAccessEx) Color(org.blockartistry.lib.Color) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Vec3d(net.minecraft.util.math.Vec3d)

Example 4 with Color

use of org.blockartistry.lib.Color in project DynamicSurroundings by OreCruncher.

the class BiomeFogColorCalculator method calculate.

@Override
@Nonnull
public Color calculate(@Nonnull final EntityViewRenderEvent.FogColors event) {
    final EntityLivingBase player = EnvironState.getPlayer();
    final World world = EnvironState.getWorld();
    final IBlockAccessEx provider = ClientChunkCache.INSTANCE;
    final int playerX = MathStuff.floor(player.posX);
    final int playerZ = MathStuff.floor(player.posZ);
    // ForgeHooksClient.getSkyBlendColour()
    final GameSettings settings = Minecraft.getMinecraft().gameSettings;
    final int[] ranges = ForgeModContainer.blendRanges;
    int distance = 6;
    if (settings.fancyGraphics && ranges.length > 0) {
        distance = ranges[MathStuff.clamp(settings.renderDistanceChunks, 0, ranges.length - 1)];
    }
    final BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(0, 0, 0);
    this.doScan |= this.posX != playerX || this.posZ != playerZ;
    if (this.doScan) {
        this.doScan = false;
        this.posX = playerX;
        this.posZ = playerZ;
        this.biomeFogColor = new Color(0, 0, 0);
        this.weightBiomeFog = 0;
        for (int x = -distance; x <= distance; ++x) {
            for (int z = -distance; z <= distance; ++z) {
                pos.setPos(playerX + x, 0, playerZ + z);
                // If the chunk is not available doScan will be set true. This will force
                // another scan on the next tick.
                this.doScan = this.doScan | !provider.isAvailable(pos);
                final BiomeInfo biome = ClientRegistry.BIOME.get(provider.getBiome(pos));
                final Color color;
                // Fetch the color we are dealing with.
                if (biome.getHasDust()) {
                    color = biome.getDustColor();
                } else if (biome.getHasFog()) {
                    color = biome.getFogColor();
                } else {
                    color = null;
                }
                if (color != null) {
                    this.biomeFogColor.add(color);
                    this.weightBiomeFog += 1F;
                }
            }
        }
    }
    // If we have nothing then just return whatever Vanilla wanted
    if (this.weightBiomeFog == 0 || distance == 0)
        return super.calculate(event);
    // WorldProvider.getFogColor() - need to calculate the scale based
    // on sunlight and stuff.
    final float partialTicks = (float) event.getRenderPartialTicks();
    final float celestialAngle = world.getCelestialAngle(partialTicks);
    final float baseScale = MathStuff.clamp(MathStuff.cos(celestialAngle * MathStuff.PI_F * 2.0F) * 2.0F + 0.5F, 0, 1);
    double rScale = baseScale * 0.94F + 0.06F;
    double gScale = baseScale * 0.94F + 0.06F;
    double bScale = baseScale * 0.91F + 0.09F;
    // EntityRenderer.updateFogColor() - adjust the scale further
    // based on rain and thunder.
    final float rainStrength = Weather.getIntensityLevel();
    if (rainStrength > 0) {
        rScale *= 1 - rainStrength * 0.5f;
        gScale *= 1 - rainStrength * 0.5f;
        bScale *= 1 - rainStrength * 0.4f;
    }
    final float thunderStrength = Weather.getThunderStrength();
    if (thunderStrength > 0) {
        rScale *= 1 - thunderStrength * 0.5f;
        gScale *= 1 - thunderStrength * 0.5f;
        bScale *= 1 - thunderStrength * 0.5f;
    }
    // Normalize the blended color components based on the biome weight.
    // The components contain a summation of all the fog components
    // in the area around the player.
    final Color fogColor = new Color(this.biomeFogColor);
    fogColor.scale(// 
    (float) (rScale / this.weightBiomeFog), // 
    (float) (gScale / this.weightBiomeFog), // 
    (float) (bScale / this.weightBiomeFog));
    final Color processedColor = applyPlayerEffects(world, player, fogColor, partialTicks);
    final double weightMixed = (distance * 2 + 1) * (distance * 2 + 1);
    final double weightDefault = weightMixed - this.weightBiomeFog;
    final Color vanillaColor = super.calculate(event);
    processedColor.scale((float) this.weightBiomeFog);
    vanillaColor.scale((float) weightDefault);
    return processedColor.add(vanillaColor).scale((float) (1 / weightMixed));
}
Also used : Color(org.blockartistry.lib.Color) BiomeInfo(org.blockartistry.DynSurround.registry.BiomeInfo) World(net.minecraft.world.World) IBlockAccessEx(org.blockartistry.lib.chunk.IBlockAccessEx) EntityLivingBase(net.minecraft.entity.EntityLivingBase) BlockPos(net.minecraft.util.math.BlockPos) GameSettings(net.minecraft.client.settings.GameSettings) Nonnull(javax.annotation.Nonnull)

Example 5 with Color

use of org.blockartistry.lib.Color in project DynamicSurroundings by OreCruncher.

the class EnvironmentEffectHandler method fogColorEvent.

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void fogColorEvent(final EntityViewRenderEvent.FogColors event) {
    if (doFog()) {
        final long start = System.nanoTime();
        final Material material = event.getState().getMaterial();
        if (material != Material.LAVA && material != Material.WATER) {
            final Color color = this.fogColor.calculate(event);
            if (color != null) {
                event.setRed(color.red);
                event.setGreen(color.green);
                event.setBlue(color.blue);
            }
        }
        this.nanos += System.nanoTime() - start;
    }
}
Also used : Color(org.blockartistry.lib.Color) Material(net.minecraft.block.material.Material) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

Color (org.blockartistry.lib.Color)8 World (net.minecraft.world.World)3 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 BlockPos (net.minecraft.util.math.BlockPos)2 BiomeInfo (org.blockartistry.DynSurround.registry.BiomeInfo)2 IBlockAccessEx (org.blockartistry.lib.chunk.IBlockAccessEx)2 Nonnull (javax.annotation.Nonnull)1 Material (net.minecraft.block.material.Material)1 IBlockState (net.minecraft.block.state.IBlockState)1 Minecraft (net.minecraft.client.Minecraft)1 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 GameSettings (net.minecraft.client.settings.GameSettings)1 Entity (net.minecraft.entity.Entity)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 Vec3d (net.minecraft.util.math.Vec3d)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 ParticleTextPopOff (org.blockartistry.DynSurround.client.fx.particle.ParticleTextPopOff)1