From 62a336a25ce0bc3a4fe3c298bcd97948a0e673f0 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Fri, 10 Apr 2015 10:19:40 +1000 Subject: [PATCH] Added the Steppe biome --- .../biomesoplenty/api/biome/BOPBiomes.java | 1 + ...erator.java => GeneratorCustomizable.java} | 4 +- .../biome/generation/GeneratorWeighted.java | 2 +- .../biome/overworld/BiomeGenSteppe.java | 57 +++++++++++++++++++ .../biomesoplenty/common/init/ModBiomes.java | 2 + .../common/world/feature/GeneratorFlora.java | 4 +- .../common/world/feature/GeneratorGrass.java | 42 +++++++++++++- .../world/feature/GeneratorOreBase.java | 4 +- .../world/feature/GeneratorOreSingle.java | 2 +- .../feature/tree/GeneratorBasicTree.java | 4 +- 10 files changed, 110 insertions(+), 12 deletions(-) rename src/main/java/biomesoplenty/api/biome/generation/{CustomizableGenerator.java => GeneratorCustomizable.java} (93%) create mode 100644 src/main/java/biomesoplenty/common/biome/overworld/BiomeGenSteppe.java diff --git a/src/main/java/biomesoplenty/api/biome/BOPBiomes.java b/src/main/java/biomesoplenty/api/biome/BOPBiomes.java index 564cfc46d..4abbc9495 100644 --- a/src/main/java/biomesoplenty/api/biome/BOPBiomes.java +++ b/src/main/java/biomesoplenty/api/biome/BOPBiomes.java @@ -18,4 +18,5 @@ public class BOPBiomes public static Optional arctic = Optional.absent(); public static Optional crag = Optional.absent(); public static Optional originValley = Optional.absent(); + public static Optional steppe = Optional.absent(); } diff --git a/src/main/java/biomesoplenty/api/biome/generation/CustomizableGenerator.java b/src/main/java/biomesoplenty/api/biome/generation/GeneratorCustomizable.java similarity index 93% rename from src/main/java/biomesoplenty/api/biome/generation/CustomizableGenerator.java rename to src/main/java/biomesoplenty/api/biome/generation/GeneratorCustomizable.java index 243a2a0bf..e66230685 100644 --- a/src/main/java/biomesoplenty/api/biome/generation/CustomizableGenerator.java +++ b/src/main/java/biomesoplenty/api/biome/generation/GeneratorCustomizable.java @@ -8,13 +8,13 @@ package biomesoplenty.api.biome.generation; -public abstract class CustomizableGenerator implements IGenerator +public abstract class GeneratorCustomizable implements IGenerator { private final String identifier; private String name; private GeneratorStage stage; - protected CustomizableGenerator() + protected GeneratorCustomizable() { this.identifier = GeneratorRegistry.getIdentifier((Class)this.getClass()); diff --git a/src/main/java/biomesoplenty/api/biome/generation/GeneratorWeighted.java b/src/main/java/biomesoplenty/api/biome/generation/GeneratorWeighted.java index 1649fad1b..819f8c573 100644 --- a/src/main/java/biomesoplenty/api/biome/generation/GeneratorWeighted.java +++ b/src/main/java/biomesoplenty/api/biome/generation/GeneratorWeighted.java @@ -21,7 +21,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonSerializationContext; import com.google.gson.reflect.TypeToken; -public class GeneratorWeighted extends CustomizableGenerator +public class GeneratorWeighted extends GeneratorCustomizable { private List weightedEntries = new ArrayList(); diff --git a/src/main/java/biomesoplenty/common/biome/overworld/BiomeGenSteppe.java b/src/main/java/biomesoplenty/common/biome/overworld/BiomeGenSteppe.java new file mode 100644 index 000000000..583682b3d --- /dev/null +++ b/src/main/java/biomesoplenty/common/biome/overworld/BiomeGenSteppe.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright 2015, 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.biome.overworld; + +import net.minecraft.entity.passive.EntityHorse; +import net.minecraft.init.Blocks; +import net.minecraft.util.BlockPos; +import net.minecraftforge.common.BiomeManager.BiomeType; +import biomesoplenty.api.biome.BOPBiome; +import biomesoplenty.api.biome.generation.GeneratorStage; +import biomesoplenty.api.block.BOPBlocks; +import biomesoplenty.common.block.BlockFoliage; +import biomesoplenty.common.block.BlockFoliage.FoliageType; +import biomesoplenty.common.block.BlockGem; +import biomesoplenty.common.block.BlockGem.GemType; +import biomesoplenty.common.world.feature.GeneratorGrass; +import biomesoplenty.common.world.feature.GeneratorOreSingle; + +public class BiomeGenSteppe extends BOPBiome +{ + private static final Height biomeHeight = new Height(0.1F, 0.4F); + + public BiomeGenSteppe() + { + this.setHeight(biomeHeight); + this.setColor(13413215); + this.setTemperatureRainfall(0.7F, 0.05F); + + this.addWeight(BiomeType.DESERT, 5); + + this.spawnableCreatureList.add(new SpawnListEntry(EntityHorse.class, 5, 2, 6)); + + this.addGenerator("dead_bushes", GeneratorStage.DEAD_BUSH, new GeneratorGrass(3, Blocks.deadbush.getDefaultState(), 4)); + this.addGenerator("grass", GeneratorStage.GRASS, new GeneratorGrass(15, BOPBlocks.foliage.getDefaultState().withProperty(BlockFoliage.VARIANT, FoliageType.SHORTGRASS))); + this.addGenerator("ruby", GeneratorStage.SAND, new GeneratorOreSingle(BOPBlocks.gem_ore.getDefaultState().withProperty(BlockGem.VARIANT, GemType.RUBY), 12, 4, 32)); + } + + @Override + public int getGrassColorAtPos(BlockPos pos) + { + double noise = field_180281_af.func_151601_a((double)pos.getX() * 0.0225D, (double)pos.getZ() * 0.0225D); + return noise < -0.1D ? 13214328 : 12885629; + } + + @Override + public int getFoliageColorAtPos(BlockPos pos) + { + double noise = field_180281_af.func_151601_a((double)pos.getX() * 0.0225D, (double)pos.getZ() * 0.0225D); + return noise < -0.1D ? 13214328 : 12885629; + } +} diff --git a/src/main/java/biomesoplenty/common/init/ModBiomes.java b/src/main/java/biomesoplenty/common/init/ModBiomes.java index f18ea2d44..f575fc5c3 100644 --- a/src/main/java/biomesoplenty/common/init/ModBiomes.java +++ b/src/main/java/biomesoplenty/common/init/ModBiomes.java @@ -21,6 +21,7 @@ import biomesoplenty.common.biome.overworld.BiomeGenAlps; import biomesoplenty.common.biome.overworld.BiomeGenArctic; import biomesoplenty.common.biome.overworld.BiomeGenCrag; import biomesoplenty.common.biome.overworld.BiomeGenOriginValley; +import biomesoplenty.common.biome.overworld.BiomeGenSteppe; import biomesoplenty.common.command.BOPCommand; import biomesoplenty.common.util.config.JsonBiome; import biomesoplenty.common.world.WorldTypeBOP; @@ -49,6 +50,7 @@ public class ModBiomes arctic = registerBiome(new BiomeGenArctic().setBiomeName("Arctic"), "arctic"); crag = registerBiome(new BiomeGenCrag().setBiomeName("Crag"), "crag"); originValley = registerBiome(new BiomeGenOriginValley().setBiomeName("Origin Valley"), "origin_valley"); + steppe = registerBiome(new BiomeGenSteppe().setBiomeName("Steppe"), "steppe"); } private static void registerExternalBiomes() diff --git a/src/main/java/biomesoplenty/common/world/feature/GeneratorFlora.java b/src/main/java/biomesoplenty/common/world/feature/GeneratorFlora.java index 2d21adbbb..6bd381e00 100644 --- a/src/main/java/biomesoplenty/common/world/feature/GeneratorFlora.java +++ b/src/main/java/biomesoplenty/common/world/feature/GeneratorFlora.java @@ -19,12 +19,12 @@ import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.util.BlockPos; import net.minecraft.world.World; -import biomesoplenty.api.biome.generation.CustomizableGenerator; +import biomesoplenty.api.biome.generation.GeneratorCustomizable; import biomesoplenty.api.biome.generation.GeneratorWeightedEntry; import biomesoplenty.common.block.BlockDecoration; import biomesoplenty.common.util.biome.GeneratorUtils; -public class GeneratorFlora extends CustomizableGenerator +public class GeneratorFlora extends GeneratorCustomizable { protected int amountPerChunk; protected IBlockState state; diff --git a/src/main/java/biomesoplenty/common/world/feature/GeneratorGrass.java b/src/main/java/biomesoplenty/common/world/feature/GeneratorGrass.java index 841e26046..23be743ff 100644 --- a/src/main/java/biomesoplenty/common/world/feature/GeneratorGrass.java +++ b/src/main/java/biomesoplenty/common/world/feature/GeneratorGrass.java @@ -10,7 +10,12 @@ package biomesoplenty.common.world.feature; import java.util.Random; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonObject; +import com.google.gson.JsonSerializationContext; + import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; import net.minecraft.util.BlockPos; import net.minecraft.world.World; import biomesoplenty.common.block.BlockDecoration; @@ -18,6 +23,22 @@ import biomesoplenty.common.util.biome.GeneratorUtils; public class GeneratorGrass extends GeneratorFlora { + private int generationAttempts; + + public GeneratorGrass() {} + + public GeneratorGrass(int amountPerChunk, IBlockState state, int generationAttempts) + { + super(amountPerChunk, state); + + this.generationAttempts = generationAttempts; + } + + public GeneratorGrass(int amountPerChunk, IBlockState state) + { + this(amountPerChunk, state, 128); + } + @Override public void scatter(World world, Random random, BlockPos pos) { @@ -37,6 +58,7 @@ public class GeneratorGrass extends GeneratorFlora public boolean generate(World world, Random random, BlockPos pos) { Block block; + Block stateBlock = this.state.getBlock(); do { @@ -46,10 +68,10 @@ public class GeneratorGrass extends GeneratorFlora } while (pos.getY() > 0); - for (int i = 0; i < 128; i++) + for (int i = 0; i < this.generationAttempts; i++) { BlockPos genPos = pos.add(random.nextInt(8) - random.nextInt(8), random.nextInt(4) - random.nextInt(4), random.nextInt(8) - random.nextInt(8)); - boolean canStay = block instanceof BlockDecoration ? ((BlockDecoration)block).canBlockStay(world, genPos, this.state) : block.canPlaceBlockAt(world, genPos); + boolean canStay = stateBlock instanceof BlockDecoration ? ((BlockDecoration)stateBlock).canBlockStay(world, genPos, this.state) : stateBlock.canPlaceBlockAt(world, genPos); if (world.isAirBlock(genPos) && canStay) { @@ -59,4 +81,20 @@ public class GeneratorGrass extends GeneratorFlora return true; } + + @Override + public void writeToJson(JsonObject json, JsonSerializationContext context) + { + super.writeToJson(json, context); + + json.addProperty("generation_attempts", this.generationAttempts); + } + + @Override + public void readFromJson(JsonObject json, JsonDeserializationContext context) + { + super.readFromJson(json, context); + + this.generationAttempts = json.get("generation_attempts").getAsInt(); + } } diff --git a/src/main/java/biomesoplenty/common/world/feature/GeneratorOreBase.java b/src/main/java/biomesoplenty/common/world/feature/GeneratorOreBase.java index 1606d92f9..4c2e8bf37 100644 --- a/src/main/java/biomesoplenty/common/world/feature/GeneratorOreBase.java +++ b/src/main/java/biomesoplenty/common/world/feature/GeneratorOreBase.java @@ -15,14 +15,14 @@ import net.minecraft.world.World; import org.apache.commons.lang3.tuple.Pair; -import biomesoplenty.api.biome.generation.CustomizableGenerator; +import biomesoplenty.api.biome.generation.GeneratorCustomizable; import biomesoplenty.common.util.biome.GeneratorUtils; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonObject; import com.google.gson.JsonSerializationContext; -public abstract class GeneratorOreBase extends CustomizableGenerator +public abstract class GeneratorOreBase extends GeneratorCustomizable { protected int amountPerChunk; protected int minHeight; diff --git a/src/main/java/biomesoplenty/common/world/feature/GeneratorOreSingle.java b/src/main/java/biomesoplenty/common/world/feature/GeneratorOreSingle.java index 8f90bdff3..59863e7db 100644 --- a/src/main/java/biomesoplenty/common/world/feature/GeneratorOreSingle.java +++ b/src/main/java/biomesoplenty/common/world/feature/GeneratorOreSingle.java @@ -16,7 +16,7 @@ import net.minecraft.init.Blocks; import net.minecraft.util.BlockPos; import net.minecraft.world.World; import net.minecraft.world.gen.feature.WorldGenMinable; -import biomesoplenty.api.biome.generation.CustomizableGenerator; +import biomesoplenty.api.biome.generation.GeneratorCustomizable; import com.google.common.base.Predicate; import com.google.gson.JsonDeserializationContext; diff --git a/src/main/java/biomesoplenty/common/world/feature/tree/GeneratorBasicTree.java b/src/main/java/biomesoplenty/common/world/feature/tree/GeneratorBasicTree.java index ccc6a135f..69d241c9c 100644 --- a/src/main/java/biomesoplenty/common/world/feature/tree/GeneratorBasicTree.java +++ b/src/main/java/biomesoplenty/common/world/feature/tree/GeneratorBasicTree.java @@ -22,7 +22,7 @@ import net.minecraft.world.World; import org.apache.commons.lang3.tuple.Pair; -import biomesoplenty.api.biome.generation.CustomizableGenerator; +import biomesoplenty.api.biome.generation.GeneratorCustomizable; import biomesoplenty.api.biome.generation.GeneratorWeightedEntry; import biomesoplenty.common.util.biome.GeneratorUtils; @@ -30,7 +30,7 @@ import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonObject; import com.google.gson.JsonSerializationContext; -public class GeneratorBasicTree extends CustomizableGenerator +public class GeneratorBasicTree extends GeneratorCustomizable { private int amountPerChunk; private boolean updateNeighbours;