Search in sources :

Example 6 with IBlockAccessEx

use of org.blockartistry.lib.chunk.IBlockAccessEx in project DynamicSurroundings by OreCruncher.

the class AlwaysOnBlockEffectScanner method blockScan.

@Override
public void blockScan(@Nonnull final IBlockState state, @Nonnull final BlockPos pos, @Nonnull final Random rand) {
    final IBlockAccessEx provider = this.locus.getWorld();
    final BlockEffect[] effects = this.profile.getAlwaysOnEffects();
    for (int i = 0; i < effects.length; i++) {
        final BlockEffect be = effects[i];
        if (be.canTrigger(provider, state, pos, rand))
            be.doEffect(provider, state, pos, rand);
    }
}
Also used : BlockEffect(org.blockartistry.DynSurround.client.fx.BlockEffect) IBlockAccessEx(org.blockartistry.lib.chunk.IBlockAccessEx)

Example 7 with IBlockAccessEx

use of org.blockartistry.lib.chunk.IBlockAccessEx in project DynamicSurroundings by OreCruncher.

the class BiomeScanner method update.

@Override
public void update() {
    final BlockPos position = EnvironState.getPlayerPosition();
    if (this.surveyedBiome != EnvironState.getPlayerBiome() || this.surveyedDimension != EnvironState.getDimensionId() || this.surveyedPosition.compareTo(position) != 0) {
        this.surveyedBiome = EnvironState.getPlayerBiome();
        this.surveyedDimension = EnvironState.getDimensionId();
        this.surveyedPosition = position;
        this.biomeArea = 0;
        this.weights.clear();
        if (EnvironState.getPlayerBiome().isFake()) {
            this.biomeArea = 1;
            this.weights.put(EnvironState.getPlayerBiome(), 1);
        } else {
            final IBlockAccessEx provider = ClientChunkCache.INSTANCE;
            // Collect raw biome data before mapping to BiomeInfo - saves lookups
            final TObjectIntCustomHashMap<Biome> scratch = new TObjectIntCustomHashMap<>(IdentityHashingStrategy.INSTANCE);
            for (int dX = -BIOME_SURVEY_RANGE; dX <= BIOME_SURVEY_RANGE; dX++) for (int dZ = -BIOME_SURVEY_RANGE; dZ <= BIOME_SURVEY_RANGE; dZ++) {
                this.mutable.setPos(this.surveyedPosition.getX() + dX, 0, this.surveyedPosition.getZ() + dZ);
                scratch.adjustOrPutValue(provider.getBiome(this.mutable), 1, 1);
            }
            this.biomeArea = MAX_BIOME_AREA;
            scratch.forEachEntry((biome, w) -> {
                this.weights.put(ClientRegistry.BIOME.get(biome), w);
                return true;
            });
        }
    }
}
Also used : Biome(net.minecraft.world.biome.Biome) IBlockAccessEx(org.blockartistry.lib.chunk.IBlockAccessEx) BlockPos(net.minecraft.util.math.BlockPos) TObjectIntCustomHashMap(gnu.trove.map.custom_hash.TObjectIntCustomHashMap)

Example 8 with IBlockAccessEx

use of org.blockartistry.lib.chunk.IBlockAccessEx in project DynamicSurroundings by OreCruncher.

the class BiomeFogRangeCalculator method calculate.

@Override
@Nonnull
public FogResult calculate(@Nonnull final EntityViewRenderEvent.RenderFogEvent event) {
    final EntityLivingBase player = EnvironState.getPlayer();
    final IBlockAccessEx provider = ClientChunkCache.INSTANCE;
    final int playerX = MathStuff.floor(player.posX);
    final int playerZ = MathStuff.floor(player.posZ);
    final float rainStr = Weather.getIntensityLevel();
    final Context ctx = this.context[event.getFogMode() == -1 ? 0 : 1];
    if (ctx.returnCached(playerX, playerZ, rainStr, event))
        return ctx.cached;
    final BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(0, 0, 0);
    float fpDistanceBiomeFog = 0F;
    float weightBiomeFog = 0;
    final boolean isRaining = Weather.isRaining();
    ctx.rain = rainStr;
    ctx.doScan = false;
    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.
            ctx.doScan = ctx.doScan | !provider.isAvailable(pos);
            final BiomeInfo biome = ClientRegistry.BIOME.get(provider.getBiome(pos));
            float distancePart = 1F;
            final float weightPart = 1;
            if (isRaining && biome.getHasDust()) {
                distancePart = 1F - DUST_FOG_IMPACT * rainStr;
            } else if (biome.getHasFog()) {
                distancePart = biome.getFogDensity();
            }
            fpDistanceBiomeFog += distancePart;
            weightBiomeFog += weightPart;
        }
    }
    final float weightMixed = (DISTANCE * 2 + 1) * (DISTANCE * 2 + 1);
    final float weightDefault = weightMixed - weightBiomeFog;
    final float fpDistanceBiomeFogAvg = (weightBiomeFog == 0) ? 0 : fpDistanceBiomeFog / weightBiomeFog;
    float farPlaneDistance = (fpDistanceBiomeFog * 240 + event.getFarPlaneDistance() * weightDefault) / weightMixed;
    final float farPlaneDistanceScaleBiome = (0.1f * (1 - fpDistanceBiomeFogAvg) + 0.75f * fpDistanceBiomeFogAvg);
    final float farPlaneDistanceScale = (farPlaneDistanceScaleBiome * weightBiomeFog + 0.75f * weightDefault) / weightMixed;
    ctx.posX = playerX;
    ctx.posZ = playerZ;
    ctx.lastFarPlane = event.getFarPlaneDistance();
    farPlaneDistance = Math.min(farPlaneDistance, event.getFarPlaneDistance());
    ctx.cached.set(event.getFogMode(), farPlaneDistance, farPlaneDistanceScale);
    return ctx.cached;
}
Also used : IBlockAccessEx(org.blockartistry.lib.chunk.IBlockAccessEx) EntityLivingBase(net.minecraft.entity.EntityLivingBase) BiomeInfo(org.blockartistry.DynSurround.registry.BiomeInfo) BlockPos(net.minecraft.util.math.BlockPos) Nonnull(javax.annotation.Nonnull)

Example 9 with IBlockAccessEx

use of org.blockartistry.lib.chunk.IBlockAccessEx 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 10 with IBlockAccessEx

use of org.blockartistry.lib.chunk.IBlockAccessEx in project DynamicSurroundings by OreCruncher.

the class RandomBlockEffectScanner method blockScan.

@Override
public void blockScan(@Nonnull final IBlockState state, @Nonnull final BlockPos pos, @Nonnull final Random rand) {
    final IBlockAccessEx provider = this.locus.getWorld();
    final BlockEffect[] effects = this.profile.getEffects();
    for (int i = 0; i < effects.length; i++) {
        final BlockEffect be = effects[i];
        if (be.canTrigger(provider, state, pos, rand))
            be.doEffect(provider, state, pos, rand);
    }
    final SoundEffect sound = this.profile.getSoundToPlay(rand);
    if (sound != null)
        sound.doEffect(provider, state, pos, rand);
}
Also used : SoundEffect(org.blockartistry.DynSurround.client.sound.SoundEffect) BlockEffect(org.blockartistry.DynSurround.client.fx.BlockEffect) IBlockAccessEx(org.blockartistry.lib.chunk.IBlockAccessEx)

Aggregations

IBlockAccessEx (org.blockartistry.lib.chunk.IBlockAccessEx)10 BlockPos (net.minecraft.util.math.BlockPos)7 IBlockState (net.minecraft.block.state.IBlockState)4 Nonnull (javax.annotation.Nonnull)2 Nullable (javax.annotation.Nullable)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 Vec3d (net.minecraft.util.math.Vec3d)2 BlockEffect (org.blockartistry.DynSurround.client.fx.BlockEffect)2 BiomeInfo (org.blockartistry.DynSurround.registry.BiomeInfo)2 Color (org.blockartistry.lib.Color)2 TObjectIntCustomHashMap (gnu.trove.map.custom_hash.TObjectIntCustomHashMap)1 Block (net.minecraft.block.Block)1 GameSettings (net.minecraft.client.settings.GameSettings)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EnumFacing (net.minecraft.util.EnumFacing)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 World (net.minecraft.world.World)1 Biome (net.minecraft.world.biome.Biome)1 SoundEffect (org.blockartistry.DynSurround.client.sound.SoundEffect)1