More work on genlayers

This commit is contained in:
Adubbz 2019-01-14 11:08:52 +11:00
parent 728044dfba
commit 6801ac63e1
4 changed files with 134 additions and 49 deletions

View file

@ -57,9 +57,6 @@ public class BiomeMapColours
}
}
if (biome == null)
return 0xFFFF0000;
if (biomeColours.containsKey(biome)) {
return biomeColours.get(biome);
}

View file

@ -8,13 +8,18 @@
package biomesoplenty.client.util;
import biomesoplenty.common.world.BOPLayerUtil;
import com.google.common.collect.ImmutableList;
import net.minecraft.init.Biomes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldType;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.provider.BiomeProviderType;
import net.minecraft.world.biome.provider.OverworldBiomeProviderSettings;
import net.minecraft.world.gen.LazyAreaLayerContext;
import net.minecraft.world.gen.OverworldGenSettings;
import net.minecraft.world.gen.area.AreaDimension;
import net.minecraft.world.gen.area.IAreaFactory;
import net.minecraft.world.gen.area.LazyArea;
import net.minecraft.world.gen.layer.GenLayer;
import net.minecraft.world.gen.layer.LayerUtil;
import org.lwjgl.glfw.GLFW;
@ -73,7 +78,7 @@ public class GenLayerVisualizer
" color = texture(sampler, uv).rgb;\n" +
"}";
Biome[] biomes = new Biome[CANVAS_WIDTH * CANVAS_HEIGHT];
int[] biomeIds = new int[CANVAS_WIDTH * CANVAS_HEIGHT];
private int vertexBuffer = 0;
private int textureId = 0;
@ -154,19 +159,34 @@ public class GenLayerVisualizer
private void populateBiomeIds()
{
OverworldBiomeProviderSettings settingsProvider = BiomeProviderType.VANILLA_LAYERED.createSettings();
OverworldGenSettings overworldgensettings = settingsProvider.getGeneratorSettings();
GenLayer biomeGenLayer = BOPLayerUtil.buildOverworldProcedure(0, WorldType.DEFAULT, overworldgensettings)[0];
OverworldGenSettings settings = settingsProvider.getGeneratorSettings();
Biome[] biomes = biomeGenLayer.generateBiomes(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT, null);
int[] aint = new int[1];
ImmutableList<IAreaFactory<LazyArea>> factoryList = BOPLayerUtil.buildOverworldProcedure(WorldType.DEFAULT, settings, (seedModifier) -> {
++aint[0];
return new LazyAreaLayerContext(1, aint[0], 0, seedModifier);
});
if (biomes.length > (CANVAS_WIDTH * CANVAS_HEIGHT))
throw new RuntimeException("Too many biomes! " + biomes.length);
IAreaFactory<LazyArea> biomeAreaFactory = factoryList.get(0);
AreaDimension areaDimension = new AreaDimension(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
LazyArea area = biomeAreaFactory.make(areaDimension);
System.arraycopy(biomes, 0, this.biomes, 0, CANVAS_WIDTH * CANVAS_HEIGHT);
for (int i = 0; i < CANVAS_HEIGHT; ++i)
{
for (int j = 0; j < CANVAS_WIDTH; ++j)
{
this.biomeIds[j + i * CANVAS_WIDTH] = area.getValue(j, i);
}
}
}
private int getColourForBiome(Biome biome, BlockPos pos)
private int getColourForBiomeId(int biomeId, BlockPos pos)
{
Biome biome = Biome.getBiome(biomeId, null);
if (biome == null)
return 0xFFFF0000;
return BiomeMapColours.getBiomeMapColour(biome);
/*IBlockState topBlock = biome.getSurfaceBuilder().getConfig().getTop();
@ -187,7 +207,7 @@ public class GenLayerVisualizer
{
for (int y = 0; y < CANVAS_HEIGHT; y++)
{
int color = getColourForBiome(this.biomes[x + y * CANVAS_WIDTH], new BlockPos(x, 0, y));
int color = getColourForBiomeId(this.biomeIds[x + y * CANVAS_WIDTH], new BlockPos(x, 0, y));
color = ((color >> 16) & 0xFF | color & 0xFF00 | (color << 16) & 0xFF0000);

View file

@ -22,8 +22,9 @@ import java.util.function.LongFunction;
public class BOPLayerUtil
{
public static <T extends IArea, C extends IContextExtended<T>> IAreaFactory<T> createBiomeAreaFactory(LongFunction<C> contextFactory)
public static <T extends IArea, C extends IContextExtended<T>> IAreaFactory<T> createInitialLandAndSeaProcedure(LongFunction<C> contextFactory)
{
// NOTE: Normally AddSnow, CoolWarm, HeatIce and Special GenLayers occur here, but we handle those ourselves
IAreaFactory<T> factory = GenLayerIsland.INSTANCE.apply(contextFactory.apply(1L));
factory = GenLayerZoom.FUZZY.apply(contextFactory.apply(2000L), factory);
factory = GenLayerAddIsland.INSTANCE.apply(contextFactory.apply(1L), factory);
@ -42,65 +43,70 @@ public class BOPLayerUtil
factory = GenLayerAddIsland.INSTANCE.apply(contextFactory.apply(4L), factory);
factory = GenLayerAddMushroomIsland.INSTANCE.apply(contextFactory.apply(5L), factory);
factory = GenLayerDeepOcean.INSTANCE.apply(contextFactory.apply(4L), factory);
factory = LayerUtil.repeat(1000L, GenLayerZoom.NORMAL, factory, 0, contextFactory);
return factory;
}
public static <T extends IArea, C extends IContextExtended<T>> ImmutableList<IAreaFactory<T>> buildOverworldProcedure(WorldType worldTypeIn, OverworldGenSettings settings, LongFunction<C> contextFactory)
{
IAreaFactory<T> biomeAreaFactory = createBiomeAreaFactory(contextFactory);
IAreaFactory<T> iareafactory1 = OceanLayer.INSTANCE.<T>apply((IContextExtended)contextFactory.apply(2L));
iareafactory1 = LayerUtil.repeat(2001L, GenLayerZoom.NORMAL, iareafactory1, 6, contextFactory);
// Create the initial land and sea layer. Is also responsible for adding deep oceans
// and mushroom islands
IAreaFactory<T> landSeaFactory = createInitialLandAndSeaProcedure(contextFactory);
int i = 4;
int j = i;
// Determines positions for all of the new ocean subbiomes added in 1.13
IAreaFactory<T> oceanBiomeFactory = OceanLayer.INSTANCE.apply(contextFactory.apply(2L));
oceanBiomeFactory = LayerUtil.repeat(2001L, GenLayerZoom.NORMAL, oceanBiomeFactory, 6, contextFactory);
int biomeSize = 4;
int riverSize = biomeSize;
if (settings != null) {
i = settings.getBiomeSize();
j = settings.getRiverSize();
biomeSize = settings.getBiomeSize();
riverSize = settings.getRiverSize();
}
if (worldTypeIn == WorldType.LARGE_BIOMES) {
i = 6;
}
biomeSize = LayerUtil.getModdedBiomeSize(worldTypeIn, biomeSize);
i = LayerUtil.getModdedBiomeSize(worldTypeIn, i);
IAreaFactory<T> riverAndSubBiomesInitFactory = GenLayerRiverInit.INSTANCE.apply(contextFactory.apply(100L), landSeaFactory);
riverAndSubBiomesInitFactory = LayerUtil.repeat(1000L, GenLayerZoom.NORMAL, riverAndSubBiomesInitFactory, 2, contextFactory);
IAreaFactory<T> lvt_7_1_ = LayerUtil.repeat(1000L, GenLayerZoom.NORMAL, biomeAreaFactory, 0, contextFactory);
lvt_7_1_ = GenLayerRiverInit.INSTANCE.apply((IContextExtended)contextFactory.apply(100L), lvt_7_1_);
IAreaFactory<T> lvt_8_1_ = worldTypeIn.getBiomeLayer(biomeAreaFactory, settings, contextFactory);
IAreaFactory<T> lvt_9_1_ = LayerUtil.repeat(1000L, GenLayerZoom.NORMAL, lvt_7_1_, 2, contextFactory);
lvt_8_1_ = GenLayerHills.INSTANCE.apply((IContextExtended)contextFactory.apply(1000L), lvt_8_1_, lvt_9_1_);
lvt_7_1_ = LayerUtil.repeat(1000L, GenLayerZoom.NORMAL, lvt_7_1_, 2, contextFactory);
lvt_7_1_ = LayerUtil.repeat(1000L, GenLayerZoom.NORMAL, lvt_7_1_, j, contextFactory);
lvt_7_1_ = GenLayerRiver.INSTANCE.apply((IContextExtended)contextFactory.apply(1L), lvt_7_1_);
lvt_7_1_ = GenLayerSmooth.INSTANCE.apply((IContextExtended)contextFactory.apply(1000L), lvt_7_1_);
lvt_8_1_ = GenLayerRareBiome.INSTANCE.apply((IContextExtended)contextFactory.apply(1001L), lvt_8_1_);
IAreaFactory<T> biomesFactory = worldTypeIn.getBiomeLayer(landSeaFactory, settings, contextFactory);
biomesFactory = GenLayerHills.INSTANCE.apply(contextFactory.apply(1000L), biomesFactory, riverAndSubBiomesInitFactory);
for(int k = 0; k < i; ++k) {
lvt_8_1_ = GenLayerZoom.NORMAL.apply((IContextExtended)contextFactory.apply((long)(1000 + k)), lvt_8_1_);
// Develop the rivers branch
IAreaFactory<T> riversInitFactory = LayerUtil.repeat(1000L, GenLayerZoom.NORMAL, riverAndSubBiomesInitFactory, riverSize, contextFactory);
riversInitFactory = GenLayerRiver.INSTANCE.apply(contextFactory.apply(1L), riversInitFactory);
riversInitFactory = GenLayerSmooth.INSTANCE.apply(contextFactory.apply(1000L), riversInitFactory);
biomesFactory = GenLayerRareBiome.INSTANCE.apply(contextFactory.apply(1001L), biomesFactory);
for(int k = 0; k < biomeSize; ++k) {
biomesFactory = GenLayerZoom.NORMAL.apply((IContextExtended)contextFactory.apply((long)(1000 + k)), biomesFactory);
if (k == 0) {
lvt_8_1_ = GenLayerAddIsland.INSTANCE.apply((IContextExtended)contextFactory.apply(3L), lvt_8_1_);
biomesFactory = GenLayerAddIsland.INSTANCE.apply((IContextExtended)contextFactory.apply(3L), biomesFactory);
}
if (k == 1 || i == 1) {
lvt_8_1_ = GenLayerShore.INSTANCE.apply((IContextExtended)contextFactory.apply(1000L), lvt_8_1_);
if (k == 1 || biomeSize == 1) {
biomesFactory = GenLayerShore.INSTANCE.apply((IContextExtended)contextFactory.apply(1000L), biomesFactory);
}
}
lvt_8_1_ = GenLayerSmooth.INSTANCE.apply((IContextExtended)contextFactory.apply(1000L), lvt_8_1_);
lvt_8_1_ = GenLayerRiverMix.INSTANCE.apply((IContextExtended)contextFactory.apply(100L), lvt_8_1_, lvt_7_1_);
lvt_8_1_ = GenLayerMixOceans.INSTANCE.apply((IContextExtended)contextFactory.apply(100L), lvt_8_1_, iareafactory1);
IAreaFactory<T> iareafactory5 = GenLayerVoronoiZoom.INSTANCE.<T>apply((IContextExtended)contextFactory.apply(10L), lvt_8_1_);
return ImmutableList.<IAreaFactory<T>>of(biomeAreaFactory, iareafactory5, lvt_8_1_);
biomesFactory = GenLayerSmooth.INSTANCE.apply(contextFactory.apply(1000L), biomesFactory);
// Mix rivers into the biomes branch
biomesFactory = GenLayerRiverMix.INSTANCE.apply(contextFactory.apply(100L), biomesFactory, riversInitFactory);
biomesFactory = GenLayerMixOceans.INSTANCE.apply(contextFactory.apply(100L), biomesFactory, oceanBiomeFactory);
// Finish biomes with Voroni zoom
IAreaFactory<T> biomesFinal = GenLayerVoronoiZoom.INSTANCE.apply(contextFactory.apply(10L), biomesFactory);
return ImmutableList.of(biomesFactory, biomesFinal, biomesFactory);
}
public static GenLayer[] buildOverworldProcedure(long seed, WorldType typeIn, OverworldGenSettings settings)
{
int i = 1;
int[] aint = new int[1];
int[] layerCount = new int[1]; // Do this as an array to enable incrementing it in the lambda
ImmutableList<IAreaFactory<LazyArea>> immutablelist = buildOverworldProcedure(typeIn, settings, (p_202825_3_) -> {
++aint[0];
return new LazyAreaLayerContext(1, aint[0], seed, p_202825_3_);
++layerCount[0];
return new LazyAreaLayerContext(1, layerCount[0], seed, p_202825_3_);
});
GenLayer genlayer = new GenLayer(immutablelist.get(0));
GenLayer genlayer1 = new GenLayer(immutablelist.get(1));

View file

@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright 2014-2019, the Biomes O' Plenty Team
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
package biomesoplenty.common.world;
public class BOPWorldSettings
{
public enum LandMassScheme
{
VANILLA,
CONTINENTS,
ARCHIPELAGO
}
public enum TemperatureVariationScheme
{
LATITUDE,
SMALL_ZONES,
MEDIUM_ZONES,
LARGE_ZONES,
RANDOM
}
public enum RainfallVariationScheme
{
SMALL_ZONES,
MEDIUM_ZONES,
LARGE_ZONES,
RANDOM
}
public enum BiomeSize
{
TINY (2),
SMALL (3),
MEDIUM (4),
LARGE (5),
HUGE (6);
private final int value;
BiomeSize(int value)
{
this.value = value;
}
public int getValue()
{
return this.value;
}
}
public LandMassScheme landScheme = LandMassScheme.VANILLA;
public TemperatureVariationScheme tempScheme = TemperatureVariationScheme.MEDIUM_ZONES;
public RainfallVariationScheme rainScheme = RainfallVariationScheme.MEDIUM_ZONES;
public BiomeSize biomeSize = BiomeSize.MEDIUM;
public float amplitude = 1.0F;
}