diff --git a/src/java/mmm/materials/MTrees.java b/src/java/mmm/materials/MTrees.java index 197fed3..1266ed8 100644 --- a/src/java/mmm/materials/MTrees.java +++ b/src/java/mmm/materials/MTrees.java @@ -3,6 +3,7 @@ package mmm.materials; import mmm.utils.UMaths; import mmm.world.trees.WTBambooGenerator; +import mmm.world.trees.WTBigHeveaGenerator; import mmm.world.trees.WTHeveaGenerator; import net.minecraft.block.material.MapColor; @@ -21,6 +22,7 @@ public class MTrees .setBarkColor( MapColor.GRAY ) // .setBaseFireInfo( 5 , 8 ) // .setTreeGenerator( WTHeveaGenerator.createSaplingGen( ) ) // + .setBigTreeGenerator( WTBigHeveaGenerator.createSaplingGen( ) , .05f ) // .register( ); this.BAMBOO = new MTree( "bamboo" ) // diff --git a/src/java/mmm/world/trees/WTBigHeveaGenerator.java b/src/java/mmm/world/trees/WTBigHeveaGenerator.java new file mode 100644 index 0000000..222b7e7 --- /dev/null +++ b/src/java/mmm/world/trees/WTBigHeveaGenerator.java @@ -0,0 +1,136 @@ +package mmm.world.trees; + + +import java.util.Random; + +import mmm.materials.MLog; +import net.minecraft.block.BlockLog; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.math.BlockPos; + + + +public class WTBigHeveaGenerator + extends WTHeveaGenerator +{ + + public static WTBigHeveaGenerator createSaplingGen( ) + { + return new WTBigHeveaGenerator( ); + } + + + public WTBigHeveaGenerator( final boolean notify ) + { + super( notify ); + } + + + // Used for sapling gen + protected WTBigHeveaGenerator( ) + { + super( ); + } + + + @Override + protected RuntimeData determineTreeSize( final BlockPos position , final Random rand ) + { + final int leavesHeight = rand.nextInt( 4 ) + 4; + final int trunkBottom = rand.nextInt( 2 ) + 3; + final int totalHeight = trunkBottom + leavesHeight * 5 / 2; + return new RuntimeData( position , leavesHeight , totalHeight ); + } + + + @Override + protected void makeTrunk( final RuntimeData rtd , final Random rand , final int leavesHeight , + final int trunkHeight ) + { + final MLog logVertical = this.getTreeMaterials( ).LOG; + final IBlockState logXAxis = logVertical.getDefaultState( ).withProperty( BlockLog.LOG_AXIS , + BlockLog.EnumAxis.X ); + final IBlockState logZAxis = logVertical.getDefaultState( ).withProperty( BlockLog.LOG_AXIS , + BlockLog.EnumAxis.Z ); + + // Trunk + for ( int y = 0 ; y < trunkHeight ; y++ ) { + rtd.setBlock( leavesHeight , y , leavesHeight , logVertical , E_BlockRequirement.VANILLA ); + rtd.setRequirement( leavesHeight , y , leavesHeight , E_BlockRequirement.VANILLA ); + } + + // Branches + final int totalLeavesHeight = leavesHeight * 5 / 2; + int y = rtd.height - totalLeavesHeight + 2 + rand.nextInt( 2 ); + boolean xAxis = rand.nextBoolean( ); + boolean positive = rand.nextBoolean( ); + while ( y < rtd.height - 1 ) { + final int x = xAxis ? positive ? leavesHeight + 1 : leavesHeight - 1 : leavesHeight; + final int z = xAxis ? leavesHeight : positive ? leavesHeight + 1 : leavesHeight - 1; + final int xDir = xAxis ? positive ? 1 : -1 : 0; + final int zDir = xAxis ? 0 : positive ? 1 : -1; + if ( this.tryBranch( rtd , rand , x , y , z , xDir , zDir , xAxis ? logXAxis : logZAxis ) ) { + y += 2 + rand.nextInt( 2 ); + positive = ! ( xAxis || positive ) || xAxis && positive; + xAxis = !xAxis; + } else { + y++; + } + } + } + + + private boolean tryBranch( final RuntimeData rtd , final Random rand , final int x , final int y , final int z , + final int xDir , final int zDir , final IBlockState log ) + { + int rx = x , ry = y , rz = z; + boolean generated = false; + while ( this.canPlaceBranch( rtd , rx , ry , rz ) ) { + generated = true; + + rtd.setBlock( rx , ry , rz , log , E_BlockRequirement.VANILLA ); + rtd.setRequirement( rx , ry , rz , E_BlockRequirement.VANILLA ); + + rx += xDir; + if ( rand.nextInt( 4 ) != 0 ) { + ry++; + } + rz += zDir; + + if ( rand.nextInt( 10 ) == 0 ) { + final int rDir = rand.nextInt( 2 ) * 2 - 1; + if ( zDir == 0 ) { + rz += rDir; + } else { + rx += rDir; + } + } + } + return generated; + } + + + private boolean canPlaceBranch( final RuntimeData rtd , final int rx , final int ry , final int rz ) + { + for ( int i = -1 ; i <= 1 ; i++ ) { + for ( int j = -1 ; j <= 1 ; j++ ) { + for ( int k = -1 ; k <= 1 ; k++ ) { + final int cx = rx + i; + final int cy = ry + j; + final int cz = rz + k; + if ( cx < 0 || cy < 0 || cz < 0 || cx >= rtd.xSize || cy > rtd.height || cz > rtd.zSize ) { + return false; + } + + final IBlockState bs = rtd.getBlockState( cx , cy , cz ); + if ( bs == null + || i == 0 && j == 0 && k == 0 && bs.getBlock( ) != this.getTreeMaterials( ).LEAVES ) { + return false; + } + } + } + } + return true; + } + +} diff --git a/src/java/mmm/world/trees/WTHeveaGenerator.java b/src/java/mmm/world/trees/WTHeveaGenerator.java index 6203c67..a7a34f6 100644 --- a/src/java/mmm/world/trees/WTHeveaGenerator.java +++ b/src/java/mmm/world/trees/WTHeveaGenerator.java @@ -3,8 +3,8 @@ package mmm.world.trees; import java.util.Random; -import mmm.materials.MLeaves; import mmm.materials.Materials; +import net.minecraft.block.BlockLeaves; import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; @@ -27,7 +27,7 @@ public class WTHeveaGenerator // Used for sapling gen - private WTHeveaGenerator( ) + protected WTHeveaGenerator( ) { super( true , null ); } @@ -48,20 +48,28 @@ public class WTHeveaGenerator final int leavesHeight = ( rtd.xSize - 1 ) / 2; final int totalLeavesHeight = leavesHeight * 5 / 2; final int trunkBottom = rtd.height - totalLeavesHeight; - final int lowerPart = trunkBottom + leavesHeight * 2; - final int centre = leavesHeight; final int trunkHeight = Math.max( trunkBottom + 1 , rtd.height - ( 1 + rand.nextInt( leavesHeight ) ) ); + this.makeLeaves( rtd , rand , leavesHeight , trunkBottom ); + this.makeTrunk( rtd , rand , leavesHeight , trunkHeight ); + } + + + protected void makeLeaves( final RuntimeData rtd , final Random rand , final int leavesHeight , + final int trunkBottom ) + { + final int lowerPart = trunkBottom + leavesHeight * 2; + // Lower part of the leaves - IBlockState leaves = this.getTreeMaterials( ).LEAVES.getDefaultState( )// - .withProperty( MLeaves.CHECK_DECAY , false ); + final IBlockState leaves = this.getTreeMaterials( ).LEAVES.getDefaultState( )// + .withProperty( BlockLeaves.CHECK_DECAY , false ); for ( int y = trunkBottom , i = 0 ; y < lowerPart ; y++ , i++ ) { final int radius = ( i >> 1 ) + 1; final int rSquare = radius * radius + ( i & 1 ); for ( int x = -radius ; x <= radius ; x++ ) { for ( int z = -radius ; z <= radius ; z++ ) { if ( x * x + z * z <= rSquare ) { - rtd.setBlock( centre + x , y , centre + z , leaves , E_BlockRequirement.SOFT ); + rtd.setBlock( leavesHeight + x , y , leavesHeight + z , leaves , E_BlockRequirement.SOFT ); } } } @@ -76,7 +84,7 @@ public class WTHeveaGenerator for ( int x = -radius ; x <= radius ; x++ ) { for ( int z = -radius ; z <= radius ; z++ ) { if ( x * x + z * z <= rSquare ) { - rtd.setBlock( centre + x , y , centre + z , leaves , E_BlockRequirement.SOFT ); + rtd.setBlock( leavesHeight + x , y , leavesHeight + z , leaves , E_BlockRequirement.SOFT ); } } } @@ -84,11 +92,16 @@ public class WTHeveaGenerator // Randomly remove leaves from corners rtd.removeCornerLeaves( rand , leaves , trunkBottom , rtd.height - 1 , .4f ); + } + + protected void makeTrunk( final RuntimeData rtd , final Random rand , final int leavesHeight , + final int trunkHeight ) + { // Trunk for ( int y = 0 ; y < trunkHeight ; y++ ) { - rtd.setBlock( centre , y , centre , this.getTreeMaterials( ).LOG , E_BlockRequirement.VANILLA ); - rtd.setRequirement( centre , y , centre , E_BlockRequirement.VANILLA ); + rtd.setBlock( leavesHeight , y , leavesHeight , this.getTreeMaterials( ).LOG , E_BlockRequirement.VANILLA ); + rtd.setRequirement( leavesHeight , y , leavesHeight , E_BlockRequirement.VANILLA ); } }