Skip to content

Commit

Permalink
Fix redwood saplings eating the other saplings around it when it does…
Browse files Browse the repository at this point in the history
…n't grow while using bonemeal. Closes #476
  • Loading branch information
alexbegt committed Feb 2, 2019
1 parent b41fd78 commit 8b0d81a
Showing 1 changed file with 19 additions and 1 deletion.
@@ -1,10 +1,12 @@
package com.progwml6.natura.overworld.block.saplings;

import java.util.List;
import java.util.Locale;
import java.util.Random;

import javax.annotation.Nonnull;

import com.google.common.collect.Lists;
import com.progwml6.natura.Natura;
import com.progwml6.natura.library.NaturaRegistry;
import com.progwml6.natura.overworld.NaturaOverworld;
Expand Down Expand Up @@ -35,6 +37,8 @@ public class BlockRedwoodSapling extends BlockSapling
{
public static PropertyEnum<SaplingType> FOLIAGE = PropertyEnum.create("foliage", SaplingType.class);

public List<BlockPos> redwoodSaplingPositions = Lists.newArrayList();

public BlockRedwoodSapling()
{
this.setCreativeTab(NaturaRegistry.tabWorld);
Expand Down Expand Up @@ -151,18 +155,31 @@ public void generateTree(@Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull
}

// replace saplings with air

this.replaceBlocksWithAir(worldIn, pos);

// try generating
gen.generateTree(rand, worldIn, pos);

if (worldIn.isAirBlock(pos))
{
this.replaceAirWithBlocks(worldIn, state);
worldIn.setBlockState(pos, state, 4);
}
}

private void replaceAirWithBlocks(World worldIn, IBlockState state)
{
for (BlockPos pos : redwoodSaplingPositions)
{
if (worldIn.isAirBlock(pos))
{
worldIn.setBlockState(pos, state, 4);
}
}

redwoodSaplingPositions.clear();
}

/**
* Check whether the given BlockPos has a Sapling of the given type
*/
Expand Down Expand Up @@ -204,6 +221,7 @@ public void replaceBlocksWithAir(World worldIn, BlockPos pos)
{
if (this.isRedwoodComplete(worldIn, pos.add(x, 0, z), SaplingType.REDWOOD))
{
redwoodSaplingPositions.add(pos.add(x, 0, z));
worldIn.setBlockToAir(pos.add(x, 0, z));
}
}
Expand Down

0 comments on commit 8b0d81a

Please sign in to comment.