diff --git a/src/java/mmm/world/trees/A_WTTreeGenerator.java b/src/java/mmm/world/trees/A_WTTreeGenerator.java index a58de6e..9d4965c 100644 --- a/src/java/mmm/world/trees/A_WTTreeGenerator.java +++ b/src/java/mmm/world/trees/A_WTTreeGenerator.java @@ -70,7 +70,7 @@ public abstract class A_WTTreeGenerator protected int getOffset( final int i , final int j , final int k ) { - return i + this.xSize * ( j + this.height * k ); + return k + this.zSize * ( j + this.height * i ); } @@ -149,7 +149,7 @@ public abstract class A_WTTreeGenerator } - private boolean isEmpty( final int x , final int y , final int z ) + public boolean isEmpty( final int x , final int y , final int z ) { if ( x < 0 || x >= this.xSize || y < 0 || y >= this.height || z < 0 || z >= this.zSize ) { return true; @@ -158,12 +158,148 @@ public abstract class A_WTTreeGenerator return bs == null || bs.getMaterial( ) == Material.AIR; } + + public void fixer( final IBlockState log , final int trunkX , final int trunkZ ) + { + final boolean fixedArea[] = new boolean[ this.blocks.length ]; + for ( int i = 0 ; i < this.xSize ; i++ ) { + for ( int j = 0 ; j < this.height ; j++ ) { + for ( int k = 0 ; k < this.zSize ; k++ ) { + if ( !fixedArea[ this.getOffset( i , j , k ) ] ) { + this.fixLeaves( log , trunkX , trunkZ , i , j , k , fixedArea ); + } + } + } + } + } + + + private void fixLeaves( final IBlockState log , final int trunkX , final int trunkZ , final int x , + final int y , final int z , final boolean[] fixedArea ) + { + final IBlockState bs = this.getBlockState( x , y , z ); + if ( bs == null || ! ( bs.getBlock( ) instanceof BlockLeaves ) + || this.checkSurroundingBlocks( log , x , y , z ) ) { + return; + } + + final int xd = trunkX < x ? 1 : -1; + final int zd = trunkZ < z ? 1 : -1; + + for ( int i = -4 * xd ; i * xd <= 4 ; i += xd ) { + final int xi = x + i; + if ( xi < 0 || xi >= this.xSize ) { + continue; + } + + final int sx = i * i; + for ( int j = -4 ; j <= 4 ; j++ ) { + final int yj = y + j; + if ( yj < 0 || yj >= this.height ) { + continue; + } + + final int sz = sx + j * j; + for ( int k = -4 * zd ; k * zd <= 4 ; k += zd ) { + if ( i == 0 && j == 0 && k == 0 || sz + k * k >= 16 ) { + continue; + } + + final int zk = z + k; + if ( zk < 0 || zk >= this.zSize || fixedArea[ this.getOffset( xi , yj , zk ) ] ) { + continue; + } + + final IBlockState state = this.getBlockState( xi , yj , zk ); + if ( state == null || ! ( state.getBlock( ) instanceof BlockLeaves ) ) { + continue; + } + + if ( this.isEmpty( xi - 1 , yj , zk ) // + || this.isEmpty( xi + 1 , yj , zk ) // + || this.isEmpty( xi , yj - 1 , zk ) // + || this.isEmpty( xi , yj + 1 , zk ) // + || this.isEmpty( xi , yj , zk - 1 ) // + || this.isEmpty( xi , yj , zk + 1 ) ) { + continue; + } + + this.addFixAt( log , xi , yj , zk , fixedArea ); + return; + } + } + } + } + + + private void addFixAt( final IBlockState log , final int x , final int y , final int z , + final boolean[] fixedArea ) + { + this.setBlock( x , y , z , log , E_BlockRequirement.VANILLA ); + this.setRequirement( x , y , z , E_BlockRequirement.VANILLA ); + for ( int i = -2 ; i <= 2 ; i++ ) { + final int xi = x + i; + if ( xi < 0 || xi >= this.xSize ) { + continue; + } + for ( int j = -2 ; j <= 2 ; j++ ) { + final int yj = y + j; + if ( yj < 0 || yj >= this.height ) { + continue; + } + for ( int k = -2 ; k <= 2 ; k++ ) { + final int zk = z + k; + if ( zk < 0 || zk >= this.zSize ) { + continue; + } + fixedArea[ this.getOffset( xi , yj , zk ) ] = true; + } + } + } + } + + + private boolean checkSurroundingBlocks( final IBlockState log , final int x , final int y , final int z ) + { + for ( int i = -4 ; i <= 4 ; i++ ) { + final int xi = x + i; + if ( xi < 0 || xi >= this.xSize ) { + continue; + } + + final int sx = i * i; + for ( int j = -4 ; j <= 4 ; j++ ) { + final int yj = y + j; + if ( yj < 0 || yj >= this.height ) { + continue; + } + + final int sz = sx + j * j; + for ( int k = -4 ; k <= 4 ; k++ ) { + if ( i == 0 && j == 0 && k == 0 || sz + k * k >= 16 ) { + continue; + } + + final int zk = z + k; + if ( zk < 0 || zk >= this.zSize ) { + continue; + } + + final IBlockState bs = this.getBlockState( xi , yj , zk ); + if ( bs != null && bs.getBlock( ) == log.getBlock( ) ) { + return true; + } + } + } + } + return false; + } } private MTree materials; - public A_WTTreeGenerator( final boolean notify , MTree materials ) + public A_WTTreeGenerator( final boolean notify , final MTree materials ) { super( notify ); this.materials = materials; diff --git a/src/java/mmm/world/trees/WTHevea.java b/src/java/mmm/world/trees/WTHevea.java index c4af913..e4980ca 100644 --- a/src/java/mmm/world/trees/WTHevea.java +++ b/src/java/mmm/world/trees/WTHevea.java @@ -48,7 +48,7 @@ public class WTHevea final int leavesHeight = ( rtd.xSize - 1 ) / 2; final int totalLeavesHeight = leavesHeight * 5 / 2; final int trunkBottom = rtd.height - totalLeavesHeight; - final int trunkHeight = Math.max( trunkBottom + 1 , rtd.height - ( 1 + rand.nextInt( leavesHeight ) ) ); + final int trunkHeight = Math.max( trunkBottom + 1 , rtd.height - ( 1 + rand.nextInt( 2 ) ) ); this.makeLeaves( rtd , rand , leavesHeight , trunkBottom ); this.makeTrunk( rtd , rand , leavesHeight , trunkHeight ); diff --git a/src/java/mmm/world/trees/WTHeveaBig.java b/src/java/mmm/world/trees/WTHeveaBig.java index c5f0613..6ca61cf 100644 --- a/src/java/mmm/world/trees/WTHeveaBig.java +++ b/src/java/mmm/world/trees/WTHeveaBig.java @@ -43,6 +43,15 @@ public class WTHeveaBig } + @Override + protected void generateTreeBlocks( final RuntimeData rtd , final Random rand ) + { + super.generateTreeBlocks( rtd , rand ); + final int centre = ( rtd.xSize - 1 ) / 2; + rtd.fixer( this.getTreeMaterials( ).LOG.getDefaultState( ) , centre , centre ); + } + + @Override protected void makeTrunk( final RuntimeData rtd , final Random rand , final int leavesHeight , final int trunkHeight ) @@ -70,12 +79,11 @@ public class WTHeveaBig 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 ); + y += rand.nextInt( 2 ); positive = ! ( xAxis || positive ) || xAxis && positive; xAxis = !xAxis; - } else { - y++; } + y++; } } @@ -112,25 +120,12 @@ public class WTHeveaBig 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; + return ! ( rtd.isEmpty( rx - 1 , ry , rz ) // + || rtd.isEmpty( rx + 1 , ry , rz ) // + || rtd.isEmpty( rx , ry - 1 , rz ) // + || rtd.isEmpty( rx , ry + 1 , rz ) // + || rtd.isEmpty( rx , ry , rz - 1 ) // + || rtd.isEmpty( rx , ry , rz + 1 ) ); } } diff --git a/src/java/mmm/world/trees/WTHeveaMega.java b/src/java/mmm/world/trees/WTHeveaMega.java index fedf2c3..32e0bce 100644 --- a/src/java/mmm/world/trees/WTHeveaMega.java +++ b/src/java/mmm/world/trees/WTHeveaMega.java @@ -90,8 +90,8 @@ public class WTHeveaMega this.makeLeaves( data , rand ); this.makeTrunk( data , rand ); this.makeBranches( data , rand ); - data.removeCornerLeaves( rand , data.leaves , data.trunkBottom , data.height - 1 , .4f ); + data.fixer( data.logVertical , data.trunkX , data.trunkZ ); }