From 8e575c0b547ed2a9781a3b14a4a56688f0c13d9d Mon Sep 17 00:00:00 2001 From: Adubbz Date: Sun, 24 Feb 2019 23:00:17 +1100 Subject: [PATCH] Re-added mahogany trees --- .../world/gen/feature/BOPBiomeFeatures.java | 1 + .../feature/ConiferousForestGrassFeature.java | 26 ++++-- .../gen/feature/tree/BasicTreeFeature.java | 43 +++++---- .../gen/feature/tree/MahoganyTreeFeature.java | 92 +++++++++++++++++++ 4 files changed, 132 insertions(+), 30 deletions(-) create mode 100644 src/main/java/biomesoplenty/common/world/gen/feature/tree/MahoganyTreeFeature.java diff --git a/src/main/java/biomesoplenty/common/world/gen/feature/BOPBiomeFeatures.java b/src/main/java/biomesoplenty/common/world/gen/feature/BOPBiomeFeatures.java index 64bafc8fb..fc78057f6 100644 --- a/src/main/java/biomesoplenty/common/world/gen/feature/BOPBiomeFeatures.java +++ b/src/main/java/biomesoplenty/common/world/gen/feature/BOPBiomeFeatures.java @@ -20,6 +20,7 @@ public class BOPBiomeFeatures public static final AbstractTreeFeature OAK_TREE = new BasicTreeFeature.Builder().create(); public static final AbstractTreeFeature BAYOU_TREE = new BayouTreeFeature.Builder().create(); public static final AbstractTreeFeature BULB_TREE = new BulbTreeFeature.Builder().create(); + public static final AbstractTreeFeature MAHOGANY_TREE = new MahoganyTreeFeature.Builder().create(); public static final AbstractTreeFeature 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()); diff --git a/src/main/java/biomesoplenty/common/world/gen/feature/ConiferousForestGrassFeature.java b/src/main/java/biomesoplenty/common/world/gen/feature/ConiferousForestGrassFeature.java index 5c43ee913..d10b95e09 100644 --- a/src/main/java/biomesoplenty/common/world/gen/feature/ConiferousForestGrassFeature.java +++ b/src/main/java/biomesoplenty/common/world/gen/feature/ConiferousForestGrassFeature.java @@ -22,23 +22,29 @@ import net.minecraft.world.gen.feature.NoFeatureConfig; public class ConiferousForestGrassFeature extends Feature { - 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 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 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; } } diff --git a/src/main/java/biomesoplenty/common/world/gen/feature/tree/BasicTreeFeature.java b/src/main/java/biomesoplenty/common/world/gen/feature/tree/BasicTreeFeature.java index c522759ae..b57717a0d 100644 --- a/src/main/java/biomesoplenty/common/world/gen/feature/tree/BasicTreeFeature.java +++ b/src/main/java/biomesoplenty/common/world/gen/feature/tree/BasicTreeFeature.java @@ -25,7 +25,16 @@ import java.util.Set; public class BasicTreeFeature extends TreeFeatureBase { - public static class Builder extends BuilderBase + public static class Builder extends InnerBuilder + { + @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 extends BuilderBase { 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, diff --git a/src/main/java/biomesoplenty/common/world/gen/feature/tree/MahoganyTreeFeature.java b/src/main/java/biomesoplenty/common/world/gen/feature/tree/MahoganyTreeFeature.java new file mode 100644 index 000000000..f70bac47c --- /dev/null +++ b/src/main/java/biomesoplenty/common/world/gen/feature/tree/MahoganyTreeFeature.java @@ -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 + { + 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 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 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()); + } + } +}