diff --git a/src/main/java/biomesoplenty/api/biome/BOPBiomes.java b/src/main/java/biomesoplenty/api/biome/BOPBiomes.java index 4abbc9495..620b37934 100644 --- a/src/main/java/biomesoplenty/api/biome/BOPBiomes.java +++ b/src/main/java/biomesoplenty/api/biome/BOPBiomes.java @@ -19,4 +19,5 @@ public class BOPBiomes public static Optional crag = Optional.absent(); public static Optional originValley = Optional.absent(); public static Optional steppe = Optional.absent(); + public static Optional thicket = Optional.absent(); } diff --git a/src/main/java/biomesoplenty/common/biome/overworld/BiomeGenOriginValley.java b/src/main/java/biomesoplenty/common/biome/overworld/BiomeGenOriginValley.java index 61967e703..8d87132c9 100644 --- a/src/main/java/biomesoplenty/common/biome/overworld/BiomeGenOriginValley.java +++ b/src/main/java/biomesoplenty/common/biome/overworld/BiomeGenOriginValley.java @@ -42,13 +42,11 @@ public class BiomeGenOriginValley extends BOPBiome GeneratorBasicTree treeGenerator = new GeneratorBasicTree(4, false, 5, 8, Blocks.log.getDefaultState(), BOPBlocks.leaves_2.getDefaultState().withProperty(BlockBOPLeaves.getVariantProperty(BlockBOPLeaves2.PAGENUM), AllTrees.ORIGIN)); - this.addGenerator("trees", GeneratorStage.TREE, treeGenerator); GeneratorWeighted flowerGenerator = new GeneratorWeighted(); flowerGenerator.add(8, new GeneratorFlora(4, BOPBlocks.flower2.getDefaultState().withProperty(BlockBOPFlower2.VARIANT, FlowerType.ROSE))); flowerGenerator.add(10, new GeneratorFlora(4, Blocks.yellow_flower.getDefaultState())); - this.addGenerator("flowers", GeneratorStage.FLOWERS, flowerGenerator); } diff --git a/src/main/java/biomesoplenty/common/biome/overworld/BiomeGenThicket.java b/src/main/java/biomesoplenty/common/biome/overworld/BiomeGenThicket.java new file mode 100644 index 000000000..f3f95f885 --- /dev/null +++ b/src/main/java/biomesoplenty/common/biome/overworld/BiomeGenThicket.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * 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.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.biome.generation.GeneratorWeighted; +import biomesoplenty.api.block.BOPBlocks; +import biomesoplenty.common.block.BlockFoliage; +import biomesoplenty.common.block.BlockGem; +import biomesoplenty.common.block.BlockFoliage.FoliageType; +import biomesoplenty.common.block.BlockGem.GemType; +import biomesoplenty.common.world.feature.GeneratorFlora; +import biomesoplenty.common.world.feature.GeneratorOreSingle; +import biomesoplenty.common.world.feature.tree.GeneratorBasicTree; +import biomesoplenty.common.world.feature.tree.GeneratorBush; + +public class BiomeGenThicket extends BOPBiome +{ + private static final Height biomeHeight = new Height(0.1F, 0.1F); + + public BiomeGenThicket() + { + this.setHeight(biomeHeight); + this.setColor(7248193); + this.setTemperatureRainfall(0.6F, 0.2F); + + this.addWeight(BiomeType.COOL, 5); + + GeneratorWeighted treeGenerator = new GeneratorWeighted(); + treeGenerator.add(1, new GeneratorBasicTree(17, false, 4, 3, Blocks.log.getDefaultState(), Blocks.leaves.getDefaultState())); + treeGenerator.add(4, new GeneratorBush(17, Blocks.log.getDefaultState(), Blocks.leaves.getDefaultState())); + this.addGenerator("trees", GeneratorStage.TREE, treeGenerator); + + //TODO: Add the rest of the generators, requires plant blocks + this.addGenerator("flowers", GeneratorStage.FLOWERS, new GeneratorFlora(5, Blocks.red_flower.getDefaultState())); + //this.addGenerator("thorns", GeneratorStage.FLOWERS, new GeneratorFlora(55, BOPBlocks.foliage.getDefaultState().withProperty(BlockBOPPlant., FoliageType.LEAFPILE)); + this.addGenerator("leaf_piles", GeneratorStage.FLOWERS, new GeneratorFlora(5, BOPBlocks.foliage.getDefaultState().withProperty(BlockFoliage.VARIANT, FoliageType.LEAFPILE))); + this.addGenerator("dead_leaf_piles", GeneratorStage.FLOWERS, new GeneratorFlora(10, BOPBlocks.foliage.getDefaultState().withProperty(BlockFoliage.VARIANT, FoliageType.DEADLEAFPILE))); + + this.addGenerator("amber", GeneratorStage.SAND, new GeneratorOreSingle(BOPBlocks.gem_ore.getDefaultState().withProperty(BlockGem.VARIANT, GemType.AMBER), 12, 4, 32)); + } + + @Override + public int getGrassColorAtPos(BlockPos pos) + { + return 11049591; + } + + @Override + public int getFoliageColorAtPos(BlockPos pos) + { + return 10854765; + } +} diff --git a/src/main/java/biomesoplenty/common/init/ModBiomes.java b/src/main/java/biomesoplenty/common/init/ModBiomes.java index f575fc5c3..ed144fe55 100644 --- a/src/main/java/biomesoplenty/common/init/ModBiomes.java +++ b/src/main/java/biomesoplenty/common/init/ModBiomes.java @@ -22,6 +22,7 @@ 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.biome.overworld.BiomeGenThicket; import biomesoplenty.common.command.BOPCommand; import biomesoplenty.common.util.config.JsonBiome; import biomesoplenty.common.world.WorldTypeBOP; @@ -51,6 +52,7 @@ public class ModBiomes crag = registerBiome(new BiomeGenCrag().setBiomeName("Crag"), "crag"); originValley = registerBiome(new BiomeGenOriginValley().setBiomeName("Origin Valley"), "origin_valley"); steppe = registerBiome(new BiomeGenSteppe().setBiomeName("Steppe"), "steppe"); + thicket = registerBiome(new BiomeGenThicket().setBiomeName("Thicket"), "thicket"); } private static void registerExternalBiomes() diff --git a/src/main/java/biomesoplenty/common/init/ModGenerators.java b/src/main/java/biomesoplenty/common/init/ModGenerators.java index 355052817..ebb6571d2 100644 --- a/src/main/java/biomesoplenty/common/init/ModGenerators.java +++ b/src/main/java/biomesoplenty/common/init/ModGenerators.java @@ -16,6 +16,7 @@ import biomesoplenty.common.world.feature.GeneratorGrass; import biomesoplenty.common.world.feature.GeneratorOreCluster; import biomesoplenty.common.world.feature.GeneratorOreSingle; import biomesoplenty.common.world.feature.tree.GeneratorBasicTree; +import biomesoplenty.common.world.feature.tree.GeneratorBush; public class ModGenerators { @@ -26,6 +27,7 @@ public class ModGenerators registerGenerator("weighted", GeneratorWeighted.class); registerGenerator("weighted_entry", GeneratorWeightedEntry.class); registerGenerator("basic_tree", GeneratorBasicTree.class); + registerGenerator("bush", GeneratorBush.class); registerGenerator("flora", GeneratorFlora.class); registerGenerator("grass", GeneratorGrass.class); } diff --git a/src/main/java/biomesoplenty/common/world/feature/tree/GeneratorBush.java b/src/main/java/biomesoplenty/common/world/feature/tree/GeneratorBush.java new file mode 100644 index 000000000..73a4e4d63 --- /dev/null +++ b/src/main/java/biomesoplenty/common/world/feature/tree/GeneratorBush.java @@ -0,0 +1,127 @@ +/******************************************************************************* + * 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.world.feature.tree; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockSapling; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; +import net.minecraft.world.World; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonObject; +import com.google.gson.JsonSerializationContext; + +import biomesoplenty.api.biome.generation.GeneratorCustomizable; +import biomesoplenty.common.util.biome.GeneratorUtils; + +public class GeneratorBush extends GeneratorCustomizable +{ + private int amountPerChunk; + private IBlockState log; + private IBlockState leaves; + + public GeneratorBush() {} + + public GeneratorBush(int amountPerChunk, IBlockState log, IBlockState leaves) + { + this.amountPerChunk = amountPerChunk; + this.log = log; + this.leaves = leaves; + } + + @Override + public void scatter(World world, Random random, BlockPos pos) + { + for (int i = 0; i < amountPerChunk; i++) + { + int x = random.nextInt(16) + 8; + int z = random.nextInt(16) + 8; + BlockPos genPos = world.getHeight(pos.add(x, 0, z)); + + generate(world, random, genPos); + } + } + + @Override + public boolean generate(World world, Random random, BlockPos pos) + { + Block block; + + //Move down until we reach the ground + do + { + block = world.getBlockState(pos).getBlock(); + if (!block.isAir(world, pos) && !block.isLeaves(world, pos)) break; + pos = pos.down(); + } + while (pos.getY() > 0); + + //Check if the ground block can sustain a sapling before generating above it + if (block.canSustainPlant(world, pos, EnumFacing.UP, ((BlockSapling)Blocks.sapling))) + { + pos = pos.up(); + world.setBlockState(pos, this.log, 2); + + //Generate a bush 3 blocks tall, with the bottom block already set to a log + for (int y = pos.getY(); y <= pos.getY() + 2; ++y) + { + //Determines the distance away from the bottom of the bush + int currentLayer = y - pos.getY(); + //Reduces the radius closer to the top of the bush + int leavesRadius = 2 - currentLayer; + + for (int x = pos.getX() - leavesRadius; x <= pos.getX() + leavesRadius; ++x) + { + int xDiff = x - pos.getX(); + + for (int z = pos.getZ() - leavesRadius; z <= pos.getZ() + leavesRadius; ++z) + { + int zDiff = z - pos.getZ(); + + //Randomly prevent the generation of leaves on the corners of each layer + if (Math.abs(xDiff) != leavesRadius || Math.abs(zDiff) != leavesRadius || random.nextInt(2) != 0) + { + BlockPos leavesPos = new BlockPos(x, y, z); + + //Ensures the leaves can replace surrounding blocks, preventing the existing log from being overriden alongside + //other terrain + if (world.getBlockState(leavesPos).getBlock().canBeReplacedByLeaves(world, leavesPos)) + { + world.setBlockState(leavesPos, this.leaves, 2); + } + } + } + } + } + } + + return true; + } + + @Override + public void writeToJson(JsonObject json, JsonSerializationContext context) + { + json.addProperty("amount_per_chunk", this.amountPerChunk); + json.add("log_state", context.serialize(this.log)); + json.add("leaves_state", context.serialize(this.leaves)); + } + + @Override + public void readFromJson(JsonObject json, JsonDeserializationContext context) + { + this.amountPerChunk = json.get("amount_per_chunk").getAsInt(); + this.log = GeneratorUtils.deserializeStateNonNull(json, "log_state", context); + this.leaves = GeneratorUtils.deserializeStateNonNull(json, "leaves_state", context); + } +}