Fog rendering
This commit is contained in:
parent
32126bd9b0
commit
2fdad6aee8
6 changed files with 221 additions and 243 deletions
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue