This commit is contained in:
modmuss50 2016-02-22 11:09:29 +00:00
parent e98bc2dbeb
commit 240b0029c8
3 changed files with 11 additions and 6 deletions

View file

@ -130,8 +130,8 @@ public class BlockRubberLog extends Block implements ITexturedBlock {
super.updateTick(worldIn, pos, state, rand);
if(!state.getValue(HAS_SAP)){
if(rand.nextInt(50) == 0){
EnumFacing facing = EnumFacing.getHorizontal(rand.nextInt(3));
if(worldIn.getBlockState(pos.down()).getBlock() == this && worldIn.getBlockState(pos.up()).getBlock() == this && worldIn.isAirBlock(pos.offset(facing))){
EnumFacing facing = EnumFacing.getHorizontal(rand.nextInt(4));
if(worldIn.getBlockState(pos.down()).getBlock() == this && worldIn.getBlockState(pos.up()).getBlock() == this){
worldIn.setBlockState(pos, state.withProperty(HAS_SAP, true).withProperty(SAP_SIDE, facing));
}
}

View file

@ -32,7 +32,9 @@ public class BlockRubberSapling extends BlockSapling {
return;
}
worldIn.setBlockToAir(pos);
new RubberTreeGenerator(false).generate(worldIn, rand, pos);
if(!new RubberTreeGenerator(false).generate(worldIn, rand, pos)){
worldIn.setBlockState(pos, state); //Re-add the sapling if the tree failed to grow
}
}
@Override

View file

@ -22,7 +22,7 @@ public class RubberTreeGenerator extends WorldGenerator {
}
public RubberTreeGenerator(boolean isWorldGen) {
super();
super(!isWorldGen);
this.isWorldGen = isWorldGen;
}
@ -62,6 +62,7 @@ public class RubberTreeGenerator extends WorldGenerator {
int yOffset;
int zOffset;
Block baseBlock = world.getBlockState(new BlockPos(x, y - 1, z)).getBlock();
boolean hasPlacedBlock = false;
if (baseBlock != null && baseBlock.canSustainPlant(world, new BlockPos(x, y - 1, z), EnumFacing.UP, (IPlantable) ModBlocks.rubberSapling) && y < worldHeight - treeHeight - 1) {
for (yOffset = y; yOffset <= y + 1 + treeHeight; ++yOffset) {
byte radius = 1;
@ -103,6 +104,7 @@ public class RubberTreeGenerator extends WorldGenerator {
Block block = world.getBlockState(new BlockPos(xOffset, yOffset, zOffset)).getBlock();
if (((xPos != center | zPos != center) || rand.nextInt(2) != 0 && var12 != 0) && (block == null || block.isLeaves(world, new BlockPos(xOffset, yOffset, zOffset)) || block.isAir(world, new BlockPos(xOffset, yOffset, zOffset)) || block.canBeReplacedByLeaves(world, new BlockPos(xOffset, yOffset, zOffset)))) {
this.setBlockAndNotifyAdequately(world, new BlockPos(xOffset, yOffset, zOffset), ModBlocks.rubberLeaves.getDefaultState());
hasPlacedBlock = true;
}
}
}
@ -116,7 +118,7 @@ public class RubberTreeGenerator extends WorldGenerator {
IBlockState newState = ModBlocks.rubberLog.getDefaultState();
boolean isAddingSap = false;
if(rand.nextInt(10) == 0){
newState = newState.withProperty(BlockRubberLog.HAS_SAP, true).withProperty(BlockRubberLog.SAP_SIDE, EnumFacing.getHorizontal(rand.nextInt(3)));
newState = newState.withProperty(BlockRubberLog.HAS_SAP, true).withProperty(BlockRubberLog.SAP_SIDE, EnumFacing.getHorizontal(rand.nextInt(4)));
isAddingSap = true;
}
if(isAddingSap){
@ -124,6 +126,7 @@ public class RubberTreeGenerator extends WorldGenerator {
} else {
this.setBlockAndNotifyAdequately(world, blockpos, newState);
}
hasPlacedBlock = true;
topLogPos = blockpos;
}
}
@ -134,7 +137,7 @@ public class RubberTreeGenerator extends WorldGenerator {
}
}
}
return true;
return hasPlacedBlock;
}
return false;
}