From 6801ac63e1c54968bc9e46336f3fb91c327c358b Mon Sep 17 00:00:00 2001 From: Adubbz Date: Mon, 14 Jan 2019 11:08:52 +1100 Subject: [PATCH] More work on genlayers --- .../client/util/BiomeMapColours.java | 3 - .../client/util/GenLayerVisualizer.java | 38 ++++++--- .../common/world/BOPLayerUtil.java | 80 ++++++++++--------- .../common/world/BOPWorldSettings.java | 62 ++++++++++++++ 4 files changed, 134 insertions(+), 49 deletions(-) create mode 100644 src/main/java/biomesoplenty/common/world/BOPWorldSettings.java diff --git a/src/main/java/biomesoplenty/client/util/BiomeMapColours.java b/src/main/java/biomesoplenty/client/util/BiomeMapColours.java index 0fc168588..ad912898e 100644 --- a/src/main/java/biomesoplenty/client/util/BiomeMapColours.java +++ b/src/main/java/biomesoplenty/client/util/BiomeMapColours.java @@ -57,9 +57,6 @@ public class BiomeMapColours } } - if (biome == null) - return 0xFFFF0000; - if (biomeColours.containsKey(biome)) { return biomeColours.get(biome); } diff --git a/src/main/java/biomesoplenty/client/util/GenLayerVisualizer.java b/src/main/java/biomesoplenty/client/util/GenLayerVisualizer.java index 7d87c566e..996e67bf8 100644 --- a/src/main/java/biomesoplenty/client/util/GenLayerVisualizer.java +++ b/src/main/java/biomesoplenty/client/util/GenLayerVisualizer.java @@ -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> 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 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); diff --git a/src/main/java/biomesoplenty/common/world/BOPLayerUtil.java b/src/main/java/biomesoplenty/common/world/BOPLayerUtil.java index 90e1b6e38..8db2901f4 100644 --- a/src/main/java/biomesoplenty/common/world/BOPLayerUtil.java +++ b/src/main/java/biomesoplenty/common/world/BOPLayerUtil.java @@ -22,8 +22,9 @@ import java.util.function.LongFunction; public class BOPLayerUtil { - public static > IAreaFactory createBiomeAreaFactory(LongFunction contextFactory) + public static > IAreaFactory createInitialLandAndSeaProcedure(LongFunction contextFactory) { + // NOTE: Normally AddSnow, CoolWarm, HeatIce and Special GenLayers occur here, but we handle those ourselves IAreaFactory 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 > ImmutableList> buildOverworldProcedure(WorldType worldTypeIn, OverworldGenSettings settings, LongFunction contextFactory) { - IAreaFactory biomeAreaFactory = createBiomeAreaFactory(contextFactory); - IAreaFactory iareafactory1 = OceanLayer.INSTANCE.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 landSeaFactory = createInitialLandAndSeaProcedure(contextFactory); - int i = 4; - int j = i; + // Determines positions for all of the new ocean subbiomes added in 1.13 + IAreaFactory 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 riverAndSubBiomesInitFactory = GenLayerRiverInit.INSTANCE.apply(contextFactory.apply(100L), landSeaFactory); + riverAndSubBiomesInitFactory = LayerUtil.repeat(1000L, GenLayerZoom.NORMAL, riverAndSubBiomesInitFactory, 2, contextFactory); - IAreaFactory 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 lvt_8_1_ = worldTypeIn.getBiomeLayer(biomeAreaFactory, settings, contextFactory); - IAreaFactory 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 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 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 iareafactory5 = GenLayerVoronoiZoom.INSTANCE.apply((IContextExtended)contextFactory.apply(10L), lvt_8_1_); - return ImmutableList.>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 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> 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)); diff --git a/src/main/java/biomesoplenty/common/world/BOPWorldSettings.java b/src/main/java/biomesoplenty/common/world/BOPWorldSettings.java new file mode 100644 index 000000000..5ec56e489 --- /dev/null +++ b/src/main/java/biomesoplenty/common/world/BOPWorldSettings.java @@ -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; +}