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);
}
}
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;
});
}
}
}
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;
}
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));
}
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);
}
Aggregations