Hooked up gen layers to the BoP world type

This commit is contained in:
Adubbz 2019-01-14 23:42:13 +11:00
parent 2d25e3d99b
commit eef4615a2d
3 changed files with 181 additions and 0 deletions

View file

@ -0,0 +1,144 @@
/*******************************************************************************
* 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;
import com.google.common.collect.Sets;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Biomes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeCache;
import net.minecraft.world.biome.provider.BiomeProvider;
import net.minecraft.world.biome.provider.OverworldBiomeProviderSettings;
import net.minecraft.world.gen.OverworldGenSettings;
import net.minecraft.world.gen.feature.structure.Structure;
import net.minecraft.world.gen.layer.GenLayer;
import net.minecraft.world.storage.WorldInfo;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.Set;
public class BOPBiomeProvider extends BiomeProvider
{
private final BiomeCache cache = new BiomeCache(this);
private final GenLayer genBiomes;
/** A GenLayer containing a factory to generate biome arrays for {@llink #getBiomes(int, int, int, int, boolean)} */
private final GenLayer biomeFactoryLayer;
private final Biome[] biomes = new Biome[]{Biomes.OCEAN, Biomes.PLAINS, Biomes.DESERT, Biomes.MOUNTAINS, Biomes.FOREST, Biomes.TAIGA, Biomes.SWAMP, Biomes.RIVER, Biomes.FROZEN_OCEAN, Biomes.FROZEN_RIVER, Biomes.SNOWY_TUNDRA, Biomes.SNOWY_MOUNTAINS, Biomes.MUSHROOM_FIELDS, Biomes.MUSHROOM_FIELD_SHORE, Biomes.BEACH, Biomes.DESERT_HILLS, Biomes.WOODED_HILLS, Biomes.TAIGA_HILLS, Biomes.MOUNTAIN_EDGE, Biomes.JUNGLE, Biomes.JUNGLE_HILLS, Biomes.JUNGLE_EDGE, Biomes.DEEP_OCEAN, Biomes.STONE_SHORE, Biomes.SNOWY_BEACH, Biomes.BIRCH_FOREST, Biomes.BIRCH_FOREST_HILLS, Biomes.DARK_FOREST, Biomes.SNOWY_TAIGA, Biomes.SNOWY_TAIGA_HILLS, Biomes.GIANT_TREE_TAIGA, Biomes.GIANT_TREE_TAIGA_HILLS, Biomes.WOODED_MOUNTAINS, Biomes.SAVANNA, Biomes.SAVANNA_PLATEAU, Biomes.BADLANDS, Biomes.WOODED_BADLANDS_PLATEAU, Biomes.BADLANDS_PLATEAU, Biomes.WARM_OCEAN, Biomes.LUKEWARM_OCEAN, Biomes.COLD_OCEAN, Biomes.DEEP_WARM_OCEAN, Biomes.DEEP_LUKEWARM_OCEAN, Biomes.DEEP_COLD_OCEAN, Biomes.DEEP_FROZEN_OCEAN, Biomes.SUNFLOWER_PLAINS, Biomes.DESERT_LAKES, Biomes.GRAVELLY_MOUNTAINS, Biomes.FLOWER_FOREST, Biomes.TAIGA_MOUNTAINS, Biomes.SWAMP_HILLS, Biomes.ICE_SPIKES, Biomes.MODIFIED_JUNGLE, Biomes.MODIFIED_JUNGLE_EDGE, Biomes.TALL_BIRCH_FOREST, Biomes.TALL_BIRCH_HILLS, Biomes.DARK_FOREST_HILLS, Biomes.SNOWY_TAIGA_MOUNTAINS, Biomes.GIANT_SPRUCE_TAIGA, Biomes.GIANT_SPRUCE_TAIGA_HILLS, Biomes.MODIFIED_GRAVELLY_MOUNTAINS, Biomes.SHATTERED_SAVANNA, Biomes.SHATTERED_SAVANNA_PLATEAU, Biomes.ERODED_BADLANDS, Biomes.MODIFIED_WOODED_BADLANDS_PLATEAU, Biomes.MODIFIED_BADLANDS_PLATEAU};
public BOPBiomeProvider(OverworldBiomeProviderSettings settingsProvider)
{
WorldInfo worldinfo = settingsProvider.getWorldInfo();
OverworldGenSettings settings = settingsProvider.getGeneratorSettings();
GenLayer[] agenlayer = BOPLayerUtil.createGenLayers(worldinfo.getSeed(), worldinfo.getGenerator(), settings);
this.genBiomes = agenlayer[0];
this.biomeFactoryLayer = agenlayer[1];
}
@Override
@Nullable
public Biome getBiome(BlockPos pos, @Nullable Biome defaultBiome)
{
return this.cache.getBiome(pos.getX(), pos.getZ(), defaultBiome);
}
@Override
public Biome[] getBiomes(int startX, int startZ, int xSize, int zSize)
{
return this.genBiomes.generateBiomes(startX, startZ, xSize, zSize, Biomes.DEFAULT);
}
@Override
public Biome[] getBiomes(int x, int z, int width, int length, boolean cacheFlag)
{
return cacheFlag && width == 16 && length == 16 && (x & 15) == 0 && (z & 15) == 0 ? this.cache.getCachedBiomes(x, z) : this.biomeFactoryLayer.generateBiomes(x, z, width, length, Biomes.DEFAULT);
}
@Override
public Set<Biome> getBiomesInSquare(int centerX, int centerZ, int sideLength)
{
int i = centerX - sideLength >> 2;
int j = centerZ - sideLength >> 2;
int k = centerX + sideLength >> 2;
int l = centerZ + sideLength >> 2;
int i1 = k - i + 1;
int j1 = l - j + 1;
Set<Biome> set = Sets.<Biome>newHashSet();
Collections.addAll(set, this.genBiomes.generateBiomes(i, j, i1, j1, (Biome)null));
return set;
}
@Override
@Nullable
public BlockPos findBiomePosition(int x, int z, int range, List<Biome> biomes, Random random)
{
int i = x - range >> 2;
int j = z - range >> 2;
int k = x + range >> 2;
int l = z + range >> 2;
int i1 = k - i + 1;
int j1 = l - j + 1;
Biome[] abiome = this.genBiomes.generateBiomes(i, j, i1, j1, (Biome)null);
BlockPos blockpos = null;
int k1 = 0;
for(int l1 = 0; l1 < i1 * j1; ++l1) {
int i2 = i + l1 % i1 << 2;
int j2 = j + l1 / i1 << 2;
if (biomes.contains(abiome[l1])) {
if (blockpos == null || random.nextInt(k1 + 1) == 0) {
blockpos = new BlockPos(i2, 0, j2);
}
++k1;
}
}
return blockpos;
}
@Override
public boolean hasStructure(Structure<?> structureIn)
{
return this.hasStructureCache.computeIfAbsent(structureIn, (p_205006_1_) ->
{
for (Biome biome : this.biomes)
{
if (biome.hasStructure(p_205006_1_))
{
return true;
}
}
return false;
});
}
@Override
public Set<IBlockState> getSurfaceBlocks()
{
if (this.topBlocksCache.isEmpty())
{
for (Biome biome : this.biomes)
{
this.topBlocksCache.add(biome.getSurfaceBuilderConfig().getTop());
}
}
return this.topBlocksCache;
}
@Override
public void tick()
{
this.cache.cleanupCache();
}
}

View file

@ -0,0 +1,21 @@
/*******************************************************************************
* 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;
import net.minecraft.world.IWorld;
import net.minecraft.world.biome.provider.BiomeProvider;
import net.minecraft.world.gen.ChunkGeneratorOverworld;
import net.minecraft.world.gen.OverworldGenSettings;
public class ChunkGeneratorOverworldBOP extends ChunkGeneratorOverworld
{
public ChunkGeneratorOverworldBOP(IWorld world, BiomeProvider provider, OverworldGenSettings settings)
{
super(world, provider, settings);
}
}

View file

@ -7,7 +7,11 @@
******************************************************************************/
package biomesoplenty.common.world;
import net.minecraft.world.World;
import net.minecraft.world.WorldType;
import net.minecraft.world.biome.provider.OverworldBiomeProviderSettings;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraft.world.gen.OverworldGenSettings;
public class WorldTypeBOP extends WorldType
{
@ -15,4 +19,16 @@ public class WorldTypeBOP extends WorldType
{
super("BIOMESOP");
}
@Override
public IChunkGenerator<?> createChunkGenerator(World world)
{
// Mojang does this through a billion builders. Fuck that.
OverworldGenSettings overworldGenSettings = new OverworldGenSettings();
OverworldBiomeProviderSettings biomeProviderSettings = new OverworldBiomeProviderSettings();
biomeProviderSettings.setWorldInfo(world.getWorldInfo());
biomeProviderSettings.setGeneratorSettings(overworldGenSettings);
return new ChunkGeneratorOverworldBOP(world, new BOPBiomeProvider(biomeProviderSettings), overworldGenSettings);
}
}