Skip to content

Commit

Permalink
Add forge growth events to natura's crops and hopefully fix redwood t…
Browse files Browse the repository at this point in the history
…rees not replacing the saplings (405)
  • Loading branch information
alexbegt committed Nov 2, 2017
1 parent f4b7880 commit 67a440b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Expand Up @@ -20,6 +20,7 @@
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;

public abstract class BlockOverworldCrops extends BlockBush implements IGrowable
{
Expand Down Expand Up @@ -80,9 +81,11 @@ public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random ra
{
float f = getGrowthChance(this, worldIn, pos);

if (rand.nextInt((int) (25.0F / f) + 1) == 0)
if (ForgeHooks.onCropsGrowPre(worldIn, pos, state, rand.nextInt((int) (25.0F / f) + 1) == 0))
{
worldIn.setBlockState(pos, this.withAge(i + 1), 2);

ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos));
}
}
}
Expand Down
Expand Up @@ -151,7 +151,8 @@ public void generateTree(@Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull
}

// replace saplings with air
worldIn.setBlockToAir(pos);

this.replaceBlocksWithAir(worldIn, pos);

// try generating
gen.generateTree(rand, worldIn, pos);
Expand Down Expand Up @@ -192,6 +193,23 @@ public boolean isRedwoodComplete(World worldIn, BlockPos pos, SaplingType type)
return iblockstate.getBlock() == this && iblockstate.getValue(FOLIAGE) == type;
}

/**
* Replaces redwood sapling's with air
*/
public void replaceBlocksWithAir(World worldIn, BlockPos pos)
{
for (int x = -3; x <= 3; x++)
{
for (int z = -3; z <= 3; z++)
{
if (this.isRedwoodComplete(worldIn, pos.add(x, 0, z), SaplingType.REDWOOD))
{
worldIn.setBlockToAir(pos.add(x, 0, z));
}
}
}
}

public enum SaplingType implements IStringSerializable, EnumBlock.IEnumMeta
{
REDWOOD;
Expand Down

0 comments on commit 67a440b

Please sign in to comment.