Skip to content

Commit

Permalink
Pull changes from 1.11: Add Forge events and fix redwood sapling issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbegt committed Nov 2, 2017
1 parent ef28578 commit 5c1bd36
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Expand Up @@ -19,6 +19,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 @@ -79,9 +80,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,7 @@ 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 +192,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 5c1bd36

Please sign in to comment.