Trying to fix decaying heveas

+ Big heveas should make more branches
+ Utility to add logs in the leaves when a leaf block is too far from
any wood
+ Big/mega heveas use the above
This commit is contained in:
Emmanuel BENOîT 2016-07-11 21:50:26 +02:00
parent 219d95dc39
commit 56685f1c87
4 changed files with 158 additions and 27 deletions

View file

@ -70,7 +70,7 @@ public abstract class A_WTTreeGenerator
protected int getOffset( final int i , final int j , final int k ) 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 ) { if ( x < 0 || x >= this.xSize || y < 0 || y >= this.height || z < 0 || z >= this.zSize ) {
return true; return true;
@ -158,12 +158,148 @@ public abstract class A_WTTreeGenerator
return bs == null || bs.getMaterial( ) == Material.AIR; 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; private MTree materials;
public A_WTTreeGenerator( final boolean notify , MTree materials ) public A_WTTreeGenerator( final boolean notify , final MTree materials )
{ {
super( notify ); super( notify );
this.materials = materials; this.materials = materials;

View file

@ -48,7 +48,7 @@ public class WTHevea
final int leavesHeight = ( rtd.xSize - 1 ) / 2; final int leavesHeight = ( rtd.xSize - 1 ) / 2;
final int totalLeavesHeight = leavesHeight * 5 / 2; final int totalLeavesHeight = leavesHeight * 5 / 2;
final int trunkBottom = rtd.height - totalLeavesHeight; 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.makeLeaves( rtd , rand , leavesHeight , trunkBottom );
this.makeTrunk( rtd , rand , leavesHeight , trunkHeight ); this.makeTrunk( rtd , rand , leavesHeight , trunkHeight );

View file

@ -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 @Override
protected void makeTrunk( final RuntimeData rtd , final Random rand , final int leavesHeight , protected void makeTrunk( final RuntimeData rtd , final Random rand , final int leavesHeight ,
final int trunkHeight ) final int trunkHeight )
@ -70,12 +79,11 @@ public class WTHeveaBig
final int xDir = xAxis ? positive ? 1 : -1 : 0; final int xDir = xAxis ? positive ? 1 : -1 : 0;
final int zDir = xAxis ? 0 : positive ? 1 : -1; final int zDir = xAxis ? 0 : positive ? 1 : -1;
if ( this.tryBranch( rtd , rand , x , y , z , xDir , zDir , xAxis ? logXAxis : logZAxis ) ) { 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; positive = ! ( xAxis || positive ) || xAxis && positive;
xAxis = !xAxis; 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 ) private boolean canPlaceBranch( final RuntimeData rtd , final int rx , final int ry , final int rz )
{ {
for ( int i = -1 ; i <= 1 ; i++ ) { return ! ( rtd.isEmpty( rx - 1 , ry , rz ) //
for ( int j = -1 ; j <= 1 ; j++ ) { || rtd.isEmpty( rx + 1 , ry , rz ) //
for ( int k = -1 ; k <= 1 ; k++ ) { || rtd.isEmpty( rx , ry - 1 , rz ) //
final int cx = rx + i; || rtd.isEmpty( rx , ry + 1 , rz ) //
final int cy = ry + j; || rtd.isEmpty( rx , ry , rz - 1 ) //
final int cz = rz + k; || rtd.isEmpty( rx , ry , rz + 1 ) );
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;
} }
} }

View file

@ -90,8 +90,8 @@ public class WTHeveaMega
this.makeLeaves( data , rand ); this.makeLeaves( data , rand );
this.makeTrunk( data , rand ); this.makeTrunk( data , rand );
this.makeBranches( data , rand ); this.makeBranches( data , rand );
data.removeCornerLeaves( rand , data.leaves , data.trunkBottom , data.height - 1 , .4f ); data.removeCornerLeaves( rand , data.leaves , data.trunkBottom , data.height - 1 , .4f );
data.fixer( data.logVertical , data.trunkX , data.trunkZ );
} }