From d7e36a8ac0feac04ab6a7fca57c7ac197b173d39 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Sun, 4 Aug 2019 22:04:37 +1000 Subject: [PATCH] Added support for Nether biomes --- .../biome/nether/AshenInfernoBiome.java | 3 + .../common/world/BOPNetherLayerUtil.java | 71 +++++++++++ .../common/world/NetherBiomeProvider.java | 116 ++++++++++++++++++ .../common/world/WorldTypeBOP.java | 11 +- .../common/world/layer/GenLayerLand.java | 20 +++ .../world/layer/GenLayerNetherBiome.java | 31 +++++ 6 files changed, 249 insertions(+), 3 deletions(-) create mode 100644 src/main/java/biomesoplenty/common/world/BOPNetherLayerUtil.java create mode 100644 src/main/java/biomesoplenty/common/world/NetherBiomeProvider.java create mode 100644 src/main/java/biomesoplenty/common/world/layer/GenLayerLand.java create mode 100644 src/main/java/biomesoplenty/common/world/layer/GenLayerNetherBiome.java diff --git a/src/main/java/biomesoplenty/common/biome/nether/AshenInfernoBiome.java b/src/main/java/biomesoplenty/common/biome/nether/AshenInfernoBiome.java index 53c5e121b..43b251c5e 100644 --- a/src/main/java/biomesoplenty/common/biome/nether/AshenInfernoBiome.java +++ b/src/main/java/biomesoplenty/common/biome/nether/AshenInfernoBiome.java @@ -1,6 +1,7 @@ package biomesoplenty.common.biome.nether; import biomesoplenty.api.block.BOPBlocks; +import biomesoplenty.api.enums.BOPClimates; import biomesoplenty.common.biome.NetherBiomeBOP; import biomesoplenty.common.world.gen.feature.BOPBiomeFeatures; import biomesoplenty.common.world.gen.feature.SplotchConfig; @@ -46,5 +47,7 @@ public class AshenInfernoBiome extends NetherBiomeBOP this.addSpawn(EntityClassification.MONSTER, new SpawnListEntry(EntityType.ZOMBIE_PIGMAN, 80, 4, 4)); this.addSpawn(EntityClassification.MONSTER, new SpawnListEntry(EntityType.MAGMA_CUBE, 20, 4, 4)); this.addSpawn(EntityClassification.MONSTER, new SpawnListEntry(EntityType.ENDERMAN, 1, 4, 4)); + + this.addWeight(BOPClimates.HELL, 3); } } diff --git a/src/main/java/biomesoplenty/common/world/BOPNetherLayerUtil.java b/src/main/java/biomesoplenty/common/world/BOPNetherLayerUtil.java new file mode 100644 index 000000000..afd4260e7 --- /dev/null +++ b/src/main/java/biomesoplenty/common/world/BOPNetherLayerUtil.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * 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 biomesoplenty.common.world.layer.*; +import biomesoplenty.common.world.layer.traits.LazyAreaLayerContextBOP; +import com.google.common.collect.ImmutableList; +import net.minecraft.util.registry.Registry; +import net.minecraft.world.WorldType; +import net.minecraft.world.biome.Biomes; +import net.minecraft.world.gen.IExtendedNoiseRandom; +import net.minecraft.world.gen.OverworldGenSettings; +import net.minecraft.world.gen.area.IArea; +import net.minecraft.world.gen.area.IAreaFactory; +import net.minecraft.world.gen.area.LazyArea; +import net.minecraft.world.gen.layer.*; + +import java.util.function.LongFunction; + +public class BOPNetherLayerUtil +{ + public static > IAreaFactory createBiomeFactory(IAreaFactory landFactory, LongFunction contextFactory) + { + IAreaFactory biomeFactory = GenLayerNetherBiome.INSTANCE.apply(contextFactory.apply(200L)); + // magnify the biome layer + biomeFactory = LayerUtil.repeat(1000L, ZoomLayer.NORMAL, biomeFactory, 2, contextFactory); + return biomeFactory; + } + + public static > ImmutableList> createAreaFactories(WorldType worldType, OverworldGenSettings settings, LongFunction contextFactory) + { + int biomeSize = 3; + + // The nether has no oceans, only land + IAreaFactory landFactory = GenLayerLand.INSTANCE.apply(contextFactory.apply(1L)); + + // Allocate the biomes + IAreaFactory biomesFactory = createBiomeFactory(landFactory, contextFactory); + + // Zoom more based on the biome size + for (int i = 0; i < biomeSize; ++i) + { + biomesFactory = ZoomLayer.NORMAL.apply(contextFactory.apply((long)(1000 + i)), biomesFactory); + if (i == 0) biomesFactory = AddIslandLayer.INSTANCE.apply(contextFactory.apply(3L), biomesFactory); + if (i == 1 || biomeSize == 1) biomesFactory = GenLayerShoreBOP.INSTANCE.apply(contextFactory.apply(1000L), biomesFactory); + } + + biomesFactory = SmoothLayer.INSTANCE.apply(contextFactory.apply(1000L), biomesFactory); + + // Finish biomes with Voroni zoom + IAreaFactory voroniZoomBiomesFactory = VoroniZoomLayer.INSTANCE.apply(contextFactory.apply(10L), biomesFactory); + return ImmutableList.of(biomesFactory, voroniZoomBiomesFactory, biomesFactory); + } + + public static Layer[] createGenLayers(long seed, WorldType worldType, OverworldGenSettings settings) + { + ImmutableList> factoryList = createAreaFactories(worldType, settings, (seedModifier) -> + { + return new LazyAreaLayerContextBOP(1, seed, seedModifier); + }); + Layer biomesLayer = new Layer(factoryList.get(0)); + Layer voroniZoomBiomesLayer = new Layer(factoryList.get(1)); + Layer biomesLayer2 = new Layer(factoryList.get(2)); + return new Layer[]{biomesLayer, voroniZoomBiomesLayer, biomesLayer2}; + } +} diff --git a/src/main/java/biomesoplenty/common/world/NetherBiomeProvider.java b/src/main/java/biomesoplenty/common/world/NetherBiomeProvider.java new file mode 100644 index 000000000..f1aff6334 --- /dev/null +++ b/src/main/java/biomesoplenty/common/world/NetherBiomeProvider.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * 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.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.Biomes; +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.Layer; +import net.minecraft.world.gen.layer.LayerUtil; +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 NetherBiomeProvider extends BiomeProvider +{ + private final Layer genBiomes; + private final Layer biomeFactoryLayer; + + public NetherBiomeProvider(OverworldBiomeProviderSettings settingsProvider) + { + this.topBlocksCache.add(Blocks.NETHERRACK.getDefaultState()); + + WorldInfo worldinfo = settingsProvider.getWorldInfo(); + OverworldGenSettings overworldgensettings = settingsProvider.getGeneratorSettings(); + Layer[] alayer = BOPNetherLayerUtil.createGenLayers(worldinfo.getSeed(), worldinfo.getGenerator(), overworldgensettings); + this.genBiomes = alayer[0]; + this.biomeFactoryLayer = alayer[1]; + } + + @Override + public Biome getBiome(int x, int y) { + return this.biomeFactoryLayer.func_215738_a(x, y); + } + + @Override + public Biome func_222366_b(int p_222366_1_, int p_222366_2_) + { + return this.genBiomes.func_215738_a(p_222366_1_, p_222366_2_); + } + + @Override + public Biome[] getBiomes(int x, int z, int width, int length, boolean cacheFlag) + { + return this.biomeFactoryLayer.generateBiomes(x, z, width, length); + } + + @Override + public Set 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 set = Sets.newHashSet(); + Collections.addAll(set, this.genBiomes.generateBiomes(i, j, i1, j1)); + return set; + } + + @Nullable + public BlockPos findBiomePosition(int x, int z, int range, List 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); + 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 true; + } + + @Override + public Set getSurfaceBlocks() + { + return this.topBlocksCache; + } +} diff --git a/src/main/java/biomesoplenty/common/world/WorldTypeBOP.java b/src/main/java/biomesoplenty/common/world/WorldTypeBOP.java index 2f90b4f85..1b1677bf5 100644 --- a/src/main/java/biomesoplenty/common/world/WorldTypeBOP.java +++ b/src/main/java/biomesoplenty/common/world/WorldTypeBOP.java @@ -38,14 +38,19 @@ public class WorldTypeBOP extends WorldType return new ChunkGeneratorOverworldBOP(world, new BOPBiomeProvider(biomeProviderSettings), overworldGenSettings); } - /*else if (world.getDimension().getType() == DimensionType.THE_NETHER) + else if (world.getDimension().getType() == DimensionType.THE_NETHER) { NetherGenSettings nethergensettings = ChunkGeneratorType.CAVES.createSettings(); nethergensettings.setDefaultBlock(Blocks.NETHERRACK.getDefaultState()); nethergensettings.setDefaultFluid(Blocks.LAVA.getDefaultState()); - return ChunkGeneratorType.CAVES.create(world, BiomeProviderType.FIXED.create(BiomeProviderType.FIXED.createSettings().setBiome(BOPBiomes.undergarden.get())), nethergensettings); + + // The nether shares biome provider settings with the overworld + OverworldBiomeProviderSettings biomeProviderSettings = new OverworldBiomeProviderSettings(); + biomeProviderSettings.setWorldInfo(world.getWorldInfo()); + + return ChunkGeneratorType.CAVES.create(world, new NetherBiomeProvider(biomeProviderSettings), nethergensettings); } - else if (world.getDimension().getType() == DimensionType.THE_END) + /*else if (world.getDimension().getType() == DimensionType.THE_END) { BlockPos SPAWN = new BlockPos(100, 50, 0); diff --git a/src/main/java/biomesoplenty/common/world/layer/GenLayerLand.java b/src/main/java/biomesoplenty/common/world/layer/GenLayerLand.java new file mode 100644 index 000000000..70e4cebb3 --- /dev/null +++ b/src/main/java/biomesoplenty/common/world/layer/GenLayerLand.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * 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.layer; + +import net.minecraft.world.gen.INoiseRandom; +import net.minecraft.world.gen.layer.traits.IAreaTransformer0; + +public enum GenLayerLand implements IAreaTransformer0 +{ + INSTANCE; + + public int apply(INoiseRandom random, int x, int z) { + return 1; + } +} diff --git a/src/main/java/biomesoplenty/common/world/layer/GenLayerNetherBiome.java b/src/main/java/biomesoplenty/common/world/layer/GenLayerNetherBiome.java new file mode 100644 index 000000000..96923ca15 --- /dev/null +++ b/src/main/java/biomesoplenty/common/world/layer/GenLayerNetherBiome.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * 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.layer; + +import biomesoplenty.api.enums.BOPClimates; +import biomesoplenty.init.ModBiomes; +import net.minecraft.util.registry.Registry; +import net.minecraft.world.biome.Biomes; +import net.minecraft.world.gen.INoiseRandom; +import net.minecraft.world.gen.area.IArea; +import net.minecraft.world.gen.layer.traits.IAreaTransformer0; +import net.minecraft.world.gen.layer.traits.IAreaTransformer1; +import net.minecraft.world.gen.layer.traits.IAreaTransformer2; +import net.minecraft.world.gen.layer.traits.IDimOffset0Transformer; +import net.minecraftforge.common.BiomeManager; + +public enum GenLayerNetherBiome implements IAreaTransformer0, IDimOffset0Transformer +{ + INSTANCE; + + @Override + public int apply(INoiseRandom context, int x, int z) + { + return Registry.BIOME.getId(BOPClimates.HELL.getRandomBiome(context, Biomes.NETHER)); + } +}