Fog rendering

This commit is contained in:
paulevsGitch 2020-09-23 14:52:54 +03:00
parent 32126bd9b0
commit 2fdad6aee8
6 changed files with 221 additions and 243 deletions

View file

@ -0,0 +1,74 @@
package ru.betterend.mixin.client;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.BackgroundRenderer;
import net.minecraft.client.render.Camera;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.fluid.FluidState;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biome.Category;
import ru.betterend.registry.BiomeRegistry;
import ru.betterend.world.biome.EndBiome;
@Mixin(BackgroundRenderer.class)
public class BackgroundRendererMixin {
private static float lastFogStart;
private static float lastFogEnd;
private static float fogStart;
private static float fogEnd;
private static float lerp;
private static final float SKY_RED = 21F / 255F;
private static final float SKY_GREEN = 16F / 255F;
private static final float SKY_BLUE = 20F / 255F;
@Inject(method = "render", at = @At("RETURN"))
private static void onRender(Camera camera, float tickDelta, ClientWorld world, int i, float f, CallbackInfo info) {
lerp += tickDelta * 0.01F;
if (lerp > 1) lerp = 1;
FluidState fluidState = camera.getSubmergedFluidState();
if (fluidState.isEmpty() && world.getDimension().hasEnderDragonFight()) {
RenderSystem.clearColor(SKY_RED, SKY_GREEN, SKY_BLUE, 0);
}
}
@Inject(method = "applyFog", at = @At("HEAD"), cancellable = true)
private static void fogDensity(Camera camera, BackgroundRenderer.FogType fogType, float viewDistance, boolean thickFog, CallbackInfo info) {
ClientPlayerEntity clientPlayerEntity = (ClientPlayerEntity) camera.getFocusedEntity();
Biome biome = clientPlayerEntity.world.getBiome(clientPlayerEntity.getBlockPos());
FluidState fluidState = camera.getSubmergedFluidState();
if (biome.getCategory() == Category.THEEND && fluidState.isEmpty()) {
EndBiome endBiome = BiomeRegistry.getFromBiome(biome);
if (fogEnd == 0) {
fogStart = viewDistance * 0.75F / endBiome.getFogDensity();
fogEnd = viewDistance / endBiome.getFogDensity();
lastFogStart = fogStart;
lastFogEnd = fogEnd;
}
if (lerp == 1) {
lastFogStart = fogStart;
lastFogEnd = fogEnd;
fogStart = viewDistance * 0.75F / endBiome.getFogDensity();
fogEnd = viewDistance / endBiome.getFogDensity();
lerp = 0;
}
RenderSystem.fogStart(MathHelper.lerp(lerp, lastFogStart, fogStart));
RenderSystem.fogEnd(MathHelper.lerp(lerp, lastFogEnd, fogEnd));
RenderSystem.fogMode(GlStateManager.FogMode.LINEAR);
RenderSystem.setupNvFogDistance();
info.cancel();
}
}
}

View file

@ -18,7 +18,7 @@ import ru.betterend.world.generator.BiomeType;
public class BiomeRegistry {
private static final Map<EndBiome, RegistryKey<Biome>> KEYS = Maps.newHashMap();
public static final HashMap<Biome, EndBiome> MUTABLE = Maps.newHashMap();
private static final HashMap<Biome, EndBiome> MUTABLE = Maps.newHashMap();
public static final BiomePicker LAND_BIOMES = new BiomePicker();
public static final BiomePicker VOID_BIOMES = new BiomePicker();
@ -27,10 +27,18 @@ public class BiomeRegistry {
public static final EndBiome END_HIGHLANDS = registerBiome(BiomeKeys.END_HIGHLANDS, BiomeType.LAND);
public static final EndBiome END_MIDLANDS = registerBiome(BiomeKeys.END_MIDLANDS, BiomeType.LAND);
public static final EndBiome SMALL_END_ISLANDS = registerBiome(BiomeKeys.SMALL_END_ISLANDS, BiomeType.VOID);
public static final EndBiome TEST = registerBiome(new EndBiome(new BiomeDefinition("test").setFogColor(255, 0, 0)), BiomeType.VOID);
public static final EndBiome TEST = registerBiome(new EndBiome(new BiomeDefinition("test").setFogColor(255, 0, 0).setFogDensity(10)), BiomeType.VOID);
public static void register() {}
public static void mutateRegistry(Registry<Biome> biomeRegistry) {
BiomeRegistry.MUTABLE.clear();
for (EndBiome biome : BiomeRegistry.LAND_BIOMES.getBiomes())
BiomeRegistry.MUTABLE.put(biomeRegistry.getOrThrow(BiomeRegistry.getBiomeKey(biome)), biome);
for (EndBiome biome : BiomeRegistry.VOID_BIOMES.getBiomes())
BiomeRegistry.MUTABLE.put(biomeRegistry.getOrThrow(BiomeRegistry.getBiomeKey(biome)), biome);
}
public static EndBiome registerBiome(RegistryKey<Biome> key, BiomeType type) {
EndBiome endBiome = new EndBiome(BuiltinRegistries.BIOME.get(key));
addToPicker(endBiome, type);
@ -72,4 +80,8 @@ public class BiomeRegistry {
public static RegistryKey<Biome> getBiomeKey(EndBiome biome) {
return KEYS.get(biome);
}
public static EndBiome getFromBiome(Biome biome) {
return MUTABLE.getOrDefault(biome, END);
}
}

View file

@ -6,7 +6,6 @@ import com.google.common.collect.Lists;
import net.minecraft.client.sound.MusicType;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.sound.BiomeAdditionsSound;
import net.minecraft.sound.BiomeMoodSound;
import net.minecraft.sound.SoundEvent;
@ -28,104 +27,65 @@ import net.minecraft.world.gen.surfacebuilder.ConfiguredSurfaceBuilders;
import ru.betterend.BetterEnd;
import ru.betterend.util.MHelper;
public class BiomeDefinition
{
public class BiomeDefinition {
private final List<ConfiguredStructureFeature<?, ?>> structures = Lists.newArrayList();
private final List<FeatureInfo> features = Lists.newArrayList();
private final List<SpawnInfo> mobs = Lists.newArrayList();
private BiomeParticleConfig particleConfig;
private BiomeAdditionsSound additions;
private BiomeMoodSound mood;
private SoundEvent music;
private SoundEvent loop;
private int waterFogColor = 329011;
private int waterColor = 4159204;
private int fogColor = 3344392;
private float fogDensity = 1F;
private boolean stalactites = true;
private boolean bnStructures = true;
private final Identifier id;
public BiomeDefinition(String name)
{
public BiomeDefinition(String name) {
this.id = new Identifier(BetterEnd.MOD_ID, name);
}
public BiomeDefinition setStalactites(boolean value)
{
public BiomeDefinition setStalactites(boolean value) {
stalactites = value;
return this;
}
public BiomeDefinition setBNStructures(boolean value)
{
public BiomeDefinition setBNStructures(boolean value) {
bnStructures = value;
return this;
}
/**
* Set default ores generation
* @param value - if true (default) then default ores will be generated
* @return this {@link BiomeDefinition}
*/
public BiomeDefinition setDefaultOres(boolean value)
{
public BiomeDefinition setDefaultOres(boolean value) {
return this;
}
/**
* Set default nether structure features to be added
* @param value - if true (default) then default structure features (nether fortresses, caves, etc.) will be added into biome
* @return this {@link BiomeDefinition}
*/
public BiomeDefinition setDefaultStructureFeatures(boolean value)
{
public BiomeDefinition setDefaultStructureFeatures(boolean value) {
return this;
}
/**
* Set default nether features to be added
* @param value - if true (default) then default features (small structures) will be added into biome
* @return this {@link BiomeDefinition}
*/
public BiomeDefinition setDefaultFeatures(boolean value)
{
public BiomeDefinition setDefaultFeatures(boolean value) {
return this;
}
/**
* Set default Nether Wastes mobs to be added
* @param value - if true (default) then default mobs will be added into biome
* @return this {@link BiomeDefinition}
*/
public BiomeDefinition setDefaultMobs(boolean value)
{
public BiomeDefinition setDefaultMobs(boolean value) {
return this;
}
public BiomeDefinition setParticleConfig(BiomeParticleConfig config)
{
public BiomeDefinition setParticleConfig(BiomeParticleConfig config) {
this.particleConfig = config;
return this;
}
/**
* Adds mob into biome
* @param type - {@link EntityType}
* @param group - {@link SpawnGroup}
* @param weight - cumulative spawning weight
* @param minGroupSize - minimum count of mobs in the group
* @param maxGroupSize - maximum count of mobs in the group
* @return this {@link BiomeDefinition}
*/
public BiomeDefinition addMobSpawn(EntityType<?> type, int weight, int minGroupSize, int maxGroupSize)
{
public BiomeDefinition addMobSpawn(EntityType<?> type, int weight, int minGroupSize, int maxGroupSize) {
Identifier eID = Registry.ENTITY_TYPE.getId(type);
if (eID != Registry.ENTITY_TYPE.getDefaultId())
{
if (eID != Registry.ENTITY_TYPE.getDefaultId()) {
SpawnInfo info = new SpawnInfo();
info.type = type;
info.weight = weight;
@ -135,178 +95,125 @@ public class BiomeDefinition
}
return this;
}
/**
* Adds feature (small structure) into biome - plants, ores, small buildings, etc.
* @param feature - {@link ConfiguredStructureFeature} to add
* @return this {@link BiomeDefinition}
*/
public BiomeDefinition addStructureFeature(ConfiguredStructureFeature<?, ?> feature)
{
public BiomeDefinition addStructureFeature(ConfiguredStructureFeature<?, ?> feature) {
System.out.println("Structure " + feature);
structures.add(feature);
return this;
}
public BiomeDefinition addFeature(Feature featureStep, ConfiguredFeature<?, ?> feature)
{
public BiomeDefinition addFeature(Feature featureStep, ConfiguredFeature<?, ?> feature) {
FeatureInfo info = new FeatureInfo();
info.featureStep = featureStep;
info.feature = feature;
features.add(info);
return this;
}
/**
* Sets biome fog color
* @param r - Red [0 - 255]
* @param g - Green [0 - 255]
* @param b - Blue [0 - 255]
* @return this {@link BiomeDefinition}
*/
public BiomeDefinition setFogColor(int r, int g, int b)
{
public BiomeDefinition setFogColor(int r, int g, int b) {
r = MathHelper.clamp(r, 0, 255);
g = MathHelper.clamp(g, 0, 255);
b = MathHelper.clamp(b, 0, 255);
this.fogColor = MHelper.color(r, g, b);
return this;
}
/**
* Sets biome water color
* @param r - Red [0 - 255]
* @param g - Green [0 - 255]
* @param b - Blue [0 - 255]
* @return this {@link BiomeDefinition}
*/
public BiomeDefinition setWaterColor(int r, int g, int b)
{
public BiomeDefinition setFogDensity(float density) {
this.fogDensity = density;
return this;
}
public BiomeDefinition setWaterColor(int r, int g, int b) {
r = MathHelper.clamp(r, 0, 255);
g = MathHelper.clamp(g, 0, 255);
b = MathHelper.clamp(b, 0, 255);
this.waterColor = MHelper.color(r, g, b);
return this;
}
/**
* Sets biome underwater fog color
* @param r - Red [0 - 255]
* @param g - Green [0 - 255]
* @param b - Blue [0 - 255]
* @return this {@link BiomeDefinition}
*/
public BiomeDefinition setWaterFogColor(int r, int g, int b)
{
public BiomeDefinition setWaterFogColor(int r, int g, int b) {
r = MathHelper.clamp(r, 0, 255);
g = MathHelper.clamp(g, 0, 255);
b = MathHelper.clamp(b, 0, 255);
this.waterFogColor = MHelper.color(r, g, b);
return this;
}
/**
* Plays in never-ending loop for as long as player is in the biome
* @param loop - SoundEvent
* @return this {@link BiomeDefinition}
*/
public BiomeDefinition setLoop(SoundEvent loop)
{
public BiomeDefinition setLoop(SoundEvent loop) {
this.loop = loop;
return this;
}
/**
* Plays commonly while the player is in the biome
* @param mood - SoundEvent
* @return this {@link BiomeDefinition}
*/
public BiomeDefinition setMood(SoundEvent mood)
{
public BiomeDefinition setMood(SoundEvent mood) {
this.mood = new BiomeMoodSound(mood, 6000, 8, 2.0D);
return this;
}
/**
* Set additional sounds. They plays once every 6000-17999 ticks while the player is in the biome
* @param additions - SoundEvent
* @return this BiomeDefenition
*/
public BiomeDefinition setAdditions(SoundEvent additions)
{
public BiomeDefinition setAdditions(SoundEvent additions) {
this.additions = new BiomeAdditionsSound(additions, 0.0111);
return this;
}
/**
* Set background music for biome
* @param music
* @return
*/
public BiomeDefinition setMusic(SoundEvent music)
{
public BiomeDefinition setMusic(SoundEvent music) {
this.music = music;
return this;
}
public Biome build()
{
public Biome build() {
SpawnSettings.Builder spawnSettings = new SpawnSettings.Builder();
GenerationSettings.Builder generationSettings = new GenerationSettings.Builder();
Builder effects = new Builder();
mobs.forEach((spawn) -> { spawnSettings.spawn(spawn.type.getSpawnGroup(), new SpawnSettings.SpawnEntry(spawn.type, spawn.weight, spawn.minGroupSize, spawn.maxGroupSize)); });
mobs.forEach((spawn) -> {
spawnSettings.spawn(spawn.type.getSpawnGroup(),
new SpawnSettings.SpawnEntry(spawn.type, spawn.weight, spawn.minGroupSize, spawn.maxGroupSize));
});
generationSettings.surfaceBuilder(ConfiguredSurfaceBuilders.END);
structures.forEach((structure) -> generationSettings.structureFeature(structure));
features.forEach((info) -> generationSettings.feature(info.featureStep, info.feature));
effects.skyColor(0).waterColor(waterColor).waterFogColor(waterFogColor).fogColor(fogColor);
if (loop != null) effects.loopSound(loop);
if (mood != null) effects.moodSound(mood);
if (additions != null) effects.additionsSound(additions);
if (particleConfig != null) effects.particleConfig(particleConfig);
if (loop != null)
effects.loopSound(loop);
if (mood != null)
effects.moodSound(mood);
if (additions != null)
effects.additionsSound(additions);
if (particleConfig != null)
effects.particleConfig(particleConfig);
effects.music(MusicType.createIngameMusic(music != null ? music : SoundEvents.MUSIC_END));
return new Biome.Builder()
.precipitation(Precipitation.NONE)
.category(Category.THEEND)
.depth(0.1F)
.scale(0.2F)
.temperature(2.0F)
.downfall(0.0F)
.effects(effects.build())
.spawnSettings(spawnSettings.build())
.generationSettings(generationSettings.build())
.build();
return new Biome.Builder().precipitation(Precipitation.NONE).category(Category.THEEND).depth(0.1F).scale(0.2F)
.temperature(2.0F).downfall(0.0F).effects(effects.build()).spawnSettings(spawnSettings.build())
.generationSettings(generationSettings.build()).build();
}
private static final class SpawnInfo
{
private static final class SpawnInfo {
EntityType<?> type;
int weight;
int minGroupSize;
int maxGroupSize;
}
private static final class FeatureInfo
{
private static final class FeatureInfo {
Feature featureStep;
ConfiguredFeature<?, ?> feature;
}
public Identifier getID()
{
public Identifier getID() {
return id;
}
public float getFodDensity() {
return fogDensity;
}
public boolean hasStalactites()
{
public boolean hasStalactites() {
return stalactites;
}
public boolean hasBNStructures()
{
public boolean hasBNStructures() {
return bnStructures;
}
}

View file

@ -11,131 +11,119 @@ import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.biome.Biome;
public class EndBiome
{
public class EndBiome {
protected List<Subbiome> subbiomes = Lists.newArrayList();
protected final Biome biome;
protected final Identifier mcID;
protected EndBiome edge;
protected int edgeSize;
protected EndBiome biomeParent;
protected float maxSubBiomeChance = 1;
protected float genChance = 1;
public EndBiome(BiomeDefinition definition)
{
private final float fogDensity;
public EndBiome(BiomeDefinition definition) {
biome = definition.build();
mcID = definition.getID();
fogDensity = definition.getFodDensity();
}
public EndBiome(Biome biome)
{
public EndBiome(Biome biome) {
this.biome = biome;
mcID = BuiltinRegistries.BIOME.getId(biome);
fogDensity = 1;
}
public void genSurfColumn(WorldAccess world, BlockPos pos, Random random) {}
public EndBiome getEdge()
{
public void genSurfColumn(WorldAccess world, BlockPos pos, Random random) {
}
public EndBiome getEdge() {
return edge == null ? this : edge;
}
public void setEdge(EndBiome edge)
{
public void setEdge(EndBiome edge) {
this.edge = edge;
edge.biomeParent = this;
}
public int getEdgeSize()
{
public int getEdgeSize() {
return edgeSize;
}
public void setEdgeSize(int size)
{
public void setEdgeSize(int size) {
edgeSize = size;
}
public void addSubBiome(EndBiome biome, float chance)
{
public void addSubBiome(EndBiome biome, float chance) {
maxSubBiomeChance += chance;
biome.biomeParent = this;
subbiomes.add(new Subbiome(biome, maxSubBiomeChance));
}
public EndBiome getSubBiome(Random random)
{
public EndBiome getSubBiome(Random random) {
float chance = random.nextFloat() * maxSubBiomeChance;
for (Subbiome biome: subbiomes)
for (Subbiome biome : subbiomes)
if (biome.canGenerate(chance))
return biome.biome;
return this;
}
public EndBiome getParentBiome()
{
public EndBiome getParentBiome() {
return this.biomeParent;
}
public boolean hasEdge()
{
public boolean hasEdge() {
return edge != null;
}
public boolean hasParentBiome()
{
public boolean hasParentBiome() {
return biomeParent != null;
}
public boolean isSame(EndBiome biome)
{
public boolean isSame(EndBiome biome) {
return biome == this || (biome.hasParentBiome() && biome.getParentBiome() == this);
}
protected final class Subbiome
{
protected final class Subbiome {
EndBiome biome;
float chance;
Subbiome(EndBiome biome, float chance)
{
Subbiome(EndBiome biome, float chance) {
this.biome = biome;
this.chance = chance;
}
public boolean canGenerate(float chance)
{
public boolean canGenerate(float chance) {
return chance < this.chance;
}
}
public boolean canGenerate(float chance)
{
public boolean canGenerate(float chance) {
return chance <= this.genChance;
}
public float setGenChance(float chance)
{
public float setGenChance(float chance) {
genChance += chance;
return genChance;
}
public Biome getBiome()
{
public Biome getBiome() {
return biome;
}
@Override
public String toString()
{
public String toString() {
return mcID.toString();
}
public Identifier getID()
{
public Identifier getID() {
return mcID;
}
public float getFogDensity() {
return fogDensity;
}
}

View file

@ -46,11 +46,7 @@ public class BetterEndBiomeSource extends BiomeSource {
chunkRandom.consume(17292);
this.noise = new SimplexNoiseSampler(chunkRandom);
BiomeRegistry.MUTABLE.clear();
for (EndBiome biome : BiomeRegistry.LAND_BIOMES.getBiomes())
BiomeRegistry.MUTABLE.put(biomeRegistry.getOrThrow(BiomeRegistry.getBiomeKey(biome)), biome);
for (EndBiome biome : BiomeRegistry.VOID_BIOMES.getBiomes())
BiomeRegistry.MUTABLE.put(biomeRegistry.getOrThrow(BiomeRegistry.getBiomeKey(biome)), biome);
BiomeRegistry.mutateRegistry(biomeRegistry);
}
@Override

View file

@ -4,7 +4,8 @@
"package": "ru.betterend.mixin.client",
"compatibilityLevel": "JAVA_8",
"client": [
"WorldRendererMixin"
"WorldRendererMixin",
"BackgroundRendererMixin"
],
"injectors": {
"defaultRequire": 1