Added thin redwood trees to the Redwood Forest

This commit is contained in:
Forstride 2016-08-11 15:16:58 -04:00
parent 37fffaf09c
commit 36506a0499
3 changed files with 207 additions and 2 deletions

View file

@ -19,6 +19,7 @@ import biomesoplenty.common.world.generator.GeneratorWaterside;
import biomesoplenty.common.world.generator.GeneratorWeighted;
import biomesoplenty.common.world.generator.tree.GeneratorBush;
import biomesoplenty.common.world.generator.tree.GeneratorRedwoodTree;
import biomesoplenty.common.world.generator.tree.GeneratorRedwoodTreeThin;
import net.minecraft.block.BlockDirt;
import net.minecraft.block.BlockFlower;
import net.minecraft.block.BlockFlower.EnumFlowerType;
@ -56,9 +57,10 @@ public class BiomeGenRedwoodForest extends BOPBiome
this.addGenerator("sand", GeneratorStage.SAND_PASS2, (new GeneratorWaterside.Builder()).amountPerChunk(3).maxRadius(7).with(Blocks.SAND.getDefaultState()).create());
// trees
GeneratorWeighted treeGenerator = new GeneratorWeighted(25.0F);
GeneratorWeighted treeGenerator = new GeneratorWeighted(30.0F);
this.addGenerator("trees", GeneratorStage.TREE, treeGenerator);
treeGenerator.add("redwood", 5, (new GeneratorRedwoodTree.Builder()).log(BOPWoods.REDWOOD).leaves(BOPTrees.REDWOOD).create());
treeGenerator.add("redwood_thin", 2, (new GeneratorRedwoodTreeThin.Builder()).log(BOPWoods.REDWOOD).leaves(BOPTrees.REDWOOD).create());
treeGenerator.add("oak_bush", 1, (new GeneratorBush.Builder()).maxHeight(2).create());
// flowers
@ -122,9 +124,10 @@ public class BiomeGenRedwoodForest extends BOPBiome
GeneratorWeighted treeGen = (GeneratorWeighted)this.getGenerator("trees");
if (!settings.isEnabled(GeneratorType.TREES)) {this.removeGenerator("trees");
GeneratorWeighted treeGenerator = new GeneratorWeighted(25.0F);
GeneratorWeighted treeGenerator = new GeneratorWeighted(30.0F);
this.addGenerator("trees", GeneratorStage.TREE, treeGenerator);
treeGenerator.add("redwood", 5, (new GeneratorRedwoodTree.Builder()).log(BlockPlanks.EnumType.OAK).leaves(BlockPlanks.EnumType.OAK).create());
treeGenerator.add("redwood_thin", 2, (new GeneratorRedwoodTreeThin.Builder()).log(BlockPlanks.EnumType.OAK).leaves(BlockPlanks.EnumType.OAK).create());
treeGenerator.add("oak_bush", 1, (new GeneratorBush.Builder()).maxHeight(2).create());
}

View file

@ -40,6 +40,7 @@ import biomesoplenty.common.world.generator.tree.GeneratorPalmTree;
import biomesoplenty.common.world.generator.tree.GeneratorPineTree;
import biomesoplenty.common.world.generator.tree.GeneratorProfileTree;
import biomesoplenty.common.world.generator.tree.GeneratorRedwoodTree;
import biomesoplenty.common.world.generator.tree.GeneratorRedwoodTreeThin;
import biomesoplenty.common.world.generator.tree.GeneratorTaigaTree;
import biomesoplenty.common.world.generator.tree.GeneratorTwigletTree;
@ -77,6 +78,7 @@ public class ModGenerators
registerGenerator("crystals", GeneratorCrystals.class, new GeneratorCrystals.Builder());
registerGenerator("spike", GeneratorSpike.class, new GeneratorSpike.Builder());
registerGenerator("redwood_tree", GeneratorRedwoodTree.class, new GeneratorRedwoodTree.Builder());
registerGenerator("redwood_tree_thin", GeneratorRedwoodTreeThin.class, new GeneratorRedwoodTreeThin.Builder());
registerGenerator("mahogany_tree", GeneratorMahoganyTree.class, new GeneratorMahoganyTree.Builder());
registerGenerator("palm_tree", GeneratorPalmTree.class, new GeneratorPalmTree.Builder());
}

View file

@ -0,0 +1,200 @@
/*******************************************************************************
* Copyright 2016, 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.generator.tree;
import java.util.Random;
import biomesoplenty.api.block.BlockQueries;
import biomesoplenty.api.block.IBlockPosQuery;
import biomesoplenty.api.config.IConfigObj;
import biomesoplenty.common.block.BlockBOPLeaves;
import biomesoplenty.common.block.BlockBOPLog;
import biomesoplenty.common.enums.BOPTrees;
import biomesoplenty.common.enums.BOPWoods;
import biomesoplenty.common.util.biome.GeneratorUtils;
import biomesoplenty.common.world.generator.GeneratorSpike;
import net.minecraft.block.BlockOldLeaf;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class GeneratorRedwoodTreeThin extends GeneratorTreeBase
{
public static class Builder extends GeneratorTreeBase.InnerBuilder<Builder, GeneratorRedwoodTreeThin> implements IGeneratorBuilder<GeneratorRedwoodTreeThin>
{
public Builder()
{
this.amountPerChunk = 1.0F;
this.minHeight = 30;
this.maxHeight = 50;
this.placeOn = BlockQueries.fertile;
this.replace = BlockQueries.replaceable;
this.log = BlockBOPLog.paging.getVariantState(BOPWoods.REDWOOD);
this.leaves = BlockBOPLeaves.paging.getVariantState(BOPTrees.REDWOOD).withProperty(BlockOldLeaf.CHECK_DECAY, Boolean.valueOf(false));
this.vine = null;
this.hanging = null;
this.trunkFruit = null;
this.altLeaves = null;
}
@Override
public GeneratorRedwoodTreeThin create()
{
return new GeneratorRedwoodTreeThin(this.amountPerChunk, this.placeOn, this.replace, this.log, this.leaves, this.vine, this.hanging, this.trunkFruit, this.altLeaves, this.minHeight, this.maxHeight);
}
}
protected GeneratorRedwoodTreeThin(float amountPerChunk, IBlockPosQuery placeOn, IBlockPosQuery replace, IBlockState log, IBlockState leaves, IBlockState vine, IBlockState hanging, IBlockState trunkFruit, IBlockState altLeaves, int minHeight, int maxHeight)
{
super(amountPerChunk, placeOn, replace, log, leaves, vine, hanging, trunkFruit, altLeaves, minHeight, maxHeight);
}
public boolean canPlaceHere(World world, BlockPos pos, int height, int radius)
{
if (pos.getY() < 1 || pos.getY() + height > 255)
{
return false;
}
for (int y = pos.getY(); y <= pos.getY() + height; ++y)
{
for (int x = pos.getX() - radius; x <= pos.getX() + radius; ++x)
{
for (int z = pos.getZ() - radius; z <= pos.getZ() + radius; ++z)
{
if (y == pos.getY() && !this.placeOn.matches(world, new BlockPos(x, y - 1, z)))
{
return false;
}
if (!this.replace.matches(world, new BlockPos(x, y, z)))
{
return false;
}
}
}
}
return true;
}
public void generateTrunk(World world, Random random, BlockPos pos, int trunkHeight)
{
for (int i = 0; i < trunkHeight; i++)
{
this.setLog(world, pos);
pos = pos.up();
}
}
public void generateBranches(World world, Random rand, BlockPos pos, int length)
{
//Iterate over the possible directions
for (EnumFacing direction = EnumFacing.NORTH; direction.ordinal() < 5; direction = EnumFacing.values()[direction.ordinal() + 1])
{
EnumFacing.Axis axis = direction.getAxis();
EnumFacing sideways = direction.rotateY();
for (int i = 1; i <= length; i++)
{
BlockPos pos1 = pos.offset(direction, i);
this.setLog(world, pos1, axis);
}
}
}
public void generateLeafLayer(World world, Random rand, BlockPos pos, int leafLayerNum)
{
//Repeat in intervals of 6, 2 small radius, 4 large
int index = leafLayerNum % 7;
int leavesRadius;
//Alternate between a smaller radius and a larger radius
if (index < 2) leavesRadius = 1;
else leavesRadius = 2;
//This may break for larger radii however it will do for this purpose
double increment = 0.05D;
for (int radius = leavesRadius; radius >= 0; radius--)
{
for (double angle = 0.0F; angle <= Math.PI * 2; angle += increment)
{
BlockPos leavesPos = pos.add(Math.round(radius * Math.cos(angle)), 0, Math.round(radius * Math.sin(angle)));
if (radius < leavesRadius || index < 2 || rand.nextInt(4) == 0)
this.setLeaves(world, leavesPos);
}
}
}
@Override
public boolean generate(World world, Random random, BlockPos pos)
{
// Move down until we reach the ground
while (pos.getY() > 1 && world.isAirBlock(pos) || world.getBlockState(pos).getBlock().isLeaves(world.getBlockState(pos), world, pos)) {pos = pos.down();}
// Choose heights
int height = GeneratorUtils.nextIntBetween(random, this.minHeight, this.maxHeight);
if (height < 20) {return false;}
// Move up to space above ground
pos = pos.up();
GeneratorSpike spikeGenerator = (new GeneratorSpike.Builder().with(this.log).replace(BlockQueries.anything).minRadius(2).maxRadius(2).minHeight(3).maxHeight(6).create());
// check that there's room and if the blocks below are suitable
if (!spikeGenerator.canPlaceHere(world, pos, height, 2)) {return false;}
//Generate the base of the tree
spikeGenerator.generate(world, random, pos);
BlockPos trunkTop = pos;
//Move upwards until the block above this is air
for (; !world.isAirBlock(trunkTop.up()); trunkTop = trunkTop.up())
{
if (trunkTop.getY() >= 255)
{
return false;
}
}
int baseHeight = trunkTop.getY() - pos.getY();
int trunkHeight = height - baseHeight;
//Generate the trunk to 1 block below the height
this.generateTrunk(world, random, pos, height - 1);
//Generate the layers of leaves
for (int i = 0; i < trunkHeight * 0.75F; i++)
{
this.generateLeafLayer(world, random, pos.up(height - i), i);
}
GeneratorBush bushGenerator = new GeneratorBush.Builder().amountPerChunk(2F).log(this.log).leaves(this.leaves).placeOn(this.log).maxHeight(2).create();
//Add bushes around the base
for (int i = 0; i < 10; i++)
{
bushGenerator.generate(world, random, pos.add(random.nextInt(5) - 5, baseHeight, random.nextInt(5) - 5));
}
return true;
}
@Override
public void configure(IConfigObj conf)
{
this.amountPerChunk = conf.getFloat("amountPerChunk", this.amountPerChunk);
this.minHeight = conf.getInt("minHeight", this.minHeight);
this.maxHeight = conf.getInt("minHeight", this.maxHeight);
this.placeOn = conf.getBlockPosQuery("placeOn", this.placeOn);
this.replace = conf.getBlockPosQuery("replace", this.replace);
this.log = conf.getBlockState("logState", this.log);
this.leaves = conf.getBlockState("leavesState", this.leaves);
}
}