Re-added mahogany trees

This commit is contained in:
Adubbz 2019-02-24 23:00:17 +11:00
parent 2002152d8a
commit 8e575c0b54
4 changed files with 132 additions and 30 deletions

View File

@ -20,6 +20,7 @@ public class BOPBiomeFeatures
public static final AbstractTreeFeature<NoFeatureConfig> OAK_TREE = new BasicTreeFeature.Builder().create();
public static final AbstractTreeFeature<NoFeatureConfig> BAYOU_TREE = new BayouTreeFeature.Builder().create();
public static final AbstractTreeFeature<NoFeatureConfig> BULB_TREE = new BulbTreeFeature.Builder().create();
public static final AbstractTreeFeature<NoFeatureConfig> MAHOGANY_TREE = new MahoganyTreeFeature.Builder().create();
public static final AbstractTreeFeature<NoFeatureConfig> BUSH = new BushTreeFeature.Builder().create();
public static final SurfaceBuilderConfig LOAMY_GRASS_DIRT_GRAVEL_SURFACE = new SurfaceBuilderConfig(BOPBlocks.loamy_grass_block.getDefaultState(), BOPBlocks.loamy_dirt.getDefaultState(), Blocks.GRAVEL.getDefaultState());

View File

@ -22,23 +22,29 @@ import net.minecraft.world.gen.feature.NoFeatureConfig;
public class ConiferousForestGrassFeature extends Feature<NoFeatureConfig>
{
public IBlockState func_202388_a(Random p_202388_1_) {
return p_202388_1_.nextInt(3) > 0 ? BOPBlocks.short_grass.getDefaultState() : (p_202388_1_.nextInt(2) > 0 ? Blocks.FERN.getDefaultState() : Blocks.GRASS.getDefaultState());
public IBlockState chooseGrassState(Random rand)
{
return rand.nextInt(3) > 0 ? BOPBlocks.short_grass.getDefaultState() : (rand.nextInt(2) > 0 ? Blocks.FERN.getDefaultState() : Blocks.GRASS.getDefaultState());
}
public boolean place(IWorld p_212245_1_, IChunkGenerator<? extends IChunkGenSettings> p_212245_2_, Random p_212245_3_, BlockPos p_212245_4_, NoFeatureConfig p_212245_5_) {
IBlockState iblockstate = this.func_202388_a(p_212245_3_);
@Override
public boolean place(IWorld world, IChunkGenerator<? extends IChunkGenSettings> generator, Random rand, BlockPos pos, NoFeatureConfig config)
{
IBlockState iblockstate = this.chooseGrassState(rand);
for(IBlockState iblockstate1 = p_212245_1_.getBlockState(p_212245_4_); (iblockstate1.isAir(p_212245_1_, p_212245_4_) || iblockstate1.isIn(BlockTags.LEAVES)) && p_212245_4_.getY() > 0; iblockstate1 = p_212245_1_.getBlockState(p_212245_4_)) {
p_212245_4_ = p_212245_4_.down();
for (IBlockState iblockstate1 = world.getBlockState(pos); (iblockstate1.isAir(world, pos) || iblockstate1.isIn(BlockTags.LEAVES)) && pos.getY() > 0; iblockstate1 = world.getBlockState(pos))
{
pos = pos.down();
}
int i = 0;
for(int j = 0; j < 128; ++j) {
BlockPos blockpos = p_212245_4_.add(p_212245_3_.nextInt(8) - p_212245_3_.nextInt(8), p_212245_3_.nextInt(4) - p_212245_3_.nextInt(4), p_212245_3_.nextInt(8) - p_212245_3_.nextInt(8));
if (p_212245_1_.isAirBlock(blockpos) && iblockstate.isValidPosition(p_212245_1_, blockpos)) {
p_212245_1_.setBlockState(blockpos, iblockstate, 2);
for (int j = 0; j < 128; ++j)
{
BlockPos blockpos = pos.add(rand.nextInt(8) - rand.nextInt(8), rand.nextInt(4) - rand.nextInt(4), rand.nextInt(8) - rand.nextInt(8));
if (world.isAirBlock(blockpos) && iblockstate.isValidPosition(world, blockpos))
{
world.setBlockState(blockpos, iblockstate, 2);
++i;
}
}

View File

@ -25,7 +25,16 @@ import java.util.Set;
public class BasicTreeFeature extends TreeFeatureBase
{
public static class Builder extends BuilderBase<BasicTreeFeature.Builder, BasicTreeFeature>
public static class Builder extends InnerBuilder<Builder, BasicTreeFeature>
{
@Override
public BasicTreeFeature create()
{
return new BasicTreeFeature(this.updateNeighbours, this.placeOn, this.replace, this.log, this.leaves, this.altLeaves, this.vine, this.hanging, this.trunkFruit, this.minHeight, this.maxHeight, this.leafLayers, this.leavesOffset, this.maxLeavesRadius, this.leavesLayerHeight, this.placeVinesOn, this.hangingChance);
}
}
protected static abstract class InnerBuilder<T extends BuilderBase, F extends TreeFeatureBase> extends BuilderBase<T, F>
{
protected int leafLayers;
protected int leavesOffset;
@ -34,16 +43,16 @@ public class BasicTreeFeature extends TreeFeatureBase
protected IBlockPosQuery placeVinesOn;
protected float hangingChance;
public Builder leafLayers(int a) {this.leafLayers = a; return this;}
public Builder leavesOffset(int a) {this.leavesOffset = a; return this;}
public Builder leavesLayerHeight(int a) {this.leavesLayerHeight = a; return this;}
public Builder maxLeavesRadius(int a) {this.maxLeavesRadius = a; return this;}
public T leafLayers(int a) {this.leafLayers = a; return (T)this;}
public T leavesOffset(int a) {this.leavesOffset = a; return (T)this;}
public T leavesLayerHeight(int a) {this.leavesLayerHeight = a; return (T)this;}
public T maxLeavesRadius(int a) {this.maxLeavesRadius = a; return (T)this;}
public Builder placeVinesOn(IBlockPosQuery a) {this.placeVinesOn = a; return this;}
public T placeVinesOn(IBlockPosQuery a) {this.placeVinesOn = a; return (T)this;}
public Builder hangingChance(float a) {this.hangingChance = a; return this;}
public T hangingChance(float a) {this.hangingChance = a; return (T)this;}
public Builder()
public InnerBuilder()
{
this.placeOn = (world, pos) ->
{
@ -68,20 +77,14 @@ public class BasicTreeFeature extends TreeFeatureBase
};
this.hangingChance = 0.0F;
}
@Override
public BasicTreeFeature create()
{
return new BasicTreeFeature(this.updateNeighbours, this.placeOn, this.replace, this.log, this.leaves, this.altLeaves, this.vine, this.hanging, this.trunkFruit, this.minHeight, this.maxHeight, this.leafLayers, this.leavesOffset, this.maxLeavesRadius, this.leavesLayerHeight, this.placeVinesOn, this.hangingChance);
}
}
private int leafLayers;
private int leavesOffset;
private int maxLeavesRadius;
private int leavesLayerHeight;
private IBlockPosQuery placeVinesOn;
private float hangingChance;
protected int leafLayers;
protected int leavesOffset;
protected int maxLeavesRadius;
protected int leavesLayerHeight;
protected IBlockPosQuery placeVinesOn;
protected float hangingChance;
protected BasicTreeFeature(boolean notify, IBlockPosQuery placeOn, IBlockPosQuery replace, IBlockState log,
IBlockState leaves, IBlockState altLeaves, IBlockState vine, IBlockState hanging, IBlockState trunkFruit,

View File

@ -0,0 +1,92 @@
/*******************************************************************************
* 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.gen.feature.tree;
import biomesoplenty.api.block.BOPBlocks;
import biomesoplenty.common.util.block.IBlockPosQuery;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import java.util.Set;
public class MahoganyTreeFeature extends BasicTreeFeature
{
public static class Builder extends BasicTreeFeature.InnerBuilder<MahoganyTreeFeature.Builder, MahoganyTreeFeature>
{
public Builder()
{
this.log = BOPBlocks.mahogany_log.getDefaultState();
this.leaves = BOPBlocks.mahogany_leaves.getDefaultState();
this.minHeight = 10;
this.maxHeight = 15;
this.leavesLayerHeight = 1;
}
@Override
public MahoganyTreeFeature create()
{
return new MahoganyTreeFeature(this.updateNeighbours, this.placeOn, this.replace, this.log, this.leaves, this.altLeaves, this.vine, this.hanging, this.trunkFruit, this.minHeight, this.maxHeight, this.leafLayers, this.leavesOffset, this.maxLeavesRadius, this.leavesLayerHeight, this.placeVinesOn, this.hangingChance);
}
}
protected MahoganyTreeFeature(boolean notify, IBlockPosQuery placeOn, IBlockPosQuery replace, IBlockState log,
IBlockState leaves, IBlockState altLeaves, IBlockState vine, IBlockState hanging, IBlockState trunkFruit,
int minHeight, int maxHeight, int leafLayers, int leavesOffset, int maxLeavesRadius, int leavesLayerHeight,
IBlockPosQuery placeVinesOn, float hangingChance)
{
super(notify, placeOn, replace, log, leaves, altLeaves, vine, hanging, trunkFruit, minHeight, maxHeight, leafLayers, leavesOffset, maxLeavesRadius, leavesLayerHeight, placeVinesOn, hangingChance);
}
@Override
protected void generateTrunk(Set<BlockPos> changedBlocks, IWorld world, BlockPos start, int height)
{
int endHeight = height - this.leafLayers;
for (int layer = 0; layer <= endHeight - 3; layer++)
{
BlockPos middlePos = start.up(layer);
if (this.replace.matches(world, middlePos))
{
this.setLog(changedBlocks, world, middlePos);
}
}
//Generate upper branches
BlockPos branchStartPos = start.up(endHeight - 2);
int branchHeight = (this.leafLayers - 1) + 1;
generateBranch(changedBlocks, world, branchStartPos, EnumFacing.NORTH, branchHeight);
generateBranch(changedBlocks, world, branchStartPos, EnumFacing.EAST, branchHeight);
generateBranch(changedBlocks, world, branchStartPos, EnumFacing.SOUTH, branchHeight);
generateBranch(changedBlocks, world, branchStartPos, EnumFacing.WEST, branchHeight);
}
private void generateBranch(Set<BlockPos> changedBlocks, IWorld world, BlockPos middle, EnumFacing direction, int height)
{
BlockPos pos;
if (replace.matches(world, pos = middle.offset(direction))) this.setLog(changedBlocks, world, pos, direction.getAxis());
for (int i = 0; i <= height - 1; i++)
{
if (replace.matches(world, pos = middle.offset(direction, 2).up(i + 1))) this.setLog(changedBlocks, world, pos, EnumFacing.Axis.Y);
}
EnumFacing logDirection = direction.rotateY();
//Extend inner branches outwards to prevent decay
for (int i = -1; i <= 1; i++)
{
if (replace.matches(world, pos = middle.offset(direction, 3).offset(logDirection, i).up(height - 1))) this.setLog(changedBlocks, world, pos, logDirection.getAxis());
}
}
}