Skip to content

Commit

Permalink
Use Forge crop events (#456)
Browse files Browse the repository at this point in the history
* Fix for #455 Natura crops, bush, cactus growing not using Forge's onCropsGrowPre/Post events, breaking compatibility with some mods

* Fix for gradle project name from nature to Natura - was breaking gradle project import into Eclipse

* Possible fix for Github markdown not being detected by Github for README.md formatting

* Review change
  • Loading branch information
Stormwind99 authored and Alexander (alexbegt) committed Jul 22, 2018
1 parent 2458dcf commit 4bf4f4c
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 50 deletions.
6 changes: 3 additions & 3 deletions README.md
@@ -1,4 +1,4 @@
#[Natura](http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/1294968-natura)
# [Natura](http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/1294968-natura)

We work all day and we work all night
The mandrake gives us quite a fright
Expand All @@ -8,10 +8,10 @@ While we search for herbs to grow
Heyo, Redwood trees! Chop them all day long~
Heyo, Redwood trees! Chop them all day long~

##Development
## Development
Install Forge as usual, and setup your IDE as with any other Forge project. Forge Multipart, and CClib must be installed to `forge/mcp/jars/mods/` from the Forge File Server: [ForgeMultipart](http://files.minecraftforge.net/ForgeMultipart/) and [CClib](http://files.minecraftforge.net/CodeChickenLib/). The DEVELOPMENT version of NEI must be installed to the same directory from [Chicken Bones Site](http://www.chickenbones.craftsaddle.org/Files/New_Versions/links.php). Tinkers' Construct must be installed as well from [dvs1](https://dvs1.progwml6.com/jenkins/job/TConstruct_1.7.x/).

##Issue reporting
## Issue reporting
Please include the following:

* Minecraft version
Expand Down
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.common.ForgeHooks;

public class BlockNetherBerryBush extends BlockEnumBerryBush
{
Expand Down Expand Up @@ -65,8 +66,10 @@ public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random ra
{
;
}

boolean canGrow = (rand.nextInt(75) == 0);

if (rand.nextInt(75) == 0)
if (ForgeHooks.onCropsGrowPre(worldIn, pos, state, canGrow))
{
int age = state.getValue(AGE).intValue();

Expand All @@ -79,6 +82,8 @@ public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random ra
{
worldIn.setBlockState(pos.up(), this.getDefaultState().withProperty(AGE, Integer.valueOf(0)), 2);
}

ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos));
}
}
}
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;

public class BlockOverworldBerryBush extends BlockEnumBerryBush
{
Expand Down Expand Up @@ -59,20 +60,27 @@ public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random ra
{
;
}

boolean canGrow = (rand.nextInt(20) == 0);

if (rand.nextInt(20) == 0 && worldIn.getLightFromNeighbors(pos) >= 8)
if (worldIn.getLightFromNeighbors(pos) >= 8)
{
int age = state.getValue(AGE).intValue();

if (age < 3)
{
worldIn.setBlockState(pos, this.getDefaultState().withProperty(AGE, Integer.valueOf(age + 1)), 2);
}

if (rand.nextInt(3) == 0 && height < 3 && worldIn.getBlockState(pos.up()).getBlock() == Blocks.AIR && age >= 2)
{
worldIn.setBlockState(pos.up(), this.getDefaultState().withProperty(AGE, Integer.valueOf(0)), 2);
}
if (ForgeHooks.onCropsGrowPre(worldIn, pos, state, canGrow))
{
int age = state.getValue(AGE).intValue();

if (age < 3)
{
worldIn.setBlockState(pos, this.getDefaultState().withProperty(AGE, Integer.valueOf(age + 1)), 2);
}

if (rand.nextInt(3) == 0 && height < 3 && worldIn.getBlockState(pos.up()).getBlock() == Blocks.AIR && age >= 2)
{
worldIn.setBlockState(pos.up(), this.getDefaultState().withProperty(AGE, Integer.valueOf(0)), 2);
}

ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos));
}
}
}

Expand Down
Expand Up @@ -27,6 +27,7 @@
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
Expand Down Expand Up @@ -287,34 +288,41 @@ protected BlockStateContainer createBlockState()
@Override
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (worldIn.getWorldInfo().isRaining() && rand.nextInt(20) == 0 && worldIn.isAirBlock(pos.up()))
if (worldIn.getWorldInfo().isRaining() && worldIn.isAirBlock(pos.up()))
{
switch (rand.nextInt(4))
{
case 0:
if (worldIn.isAirBlock(pos.north()))
{
worldIn.setBlockState(pos.north(), NaturaOverworld.saguaroFruit.getDefaultState().withProperty(BlockSaguaroFruit.FACING, EnumFacing.SOUTH), 3);
}
break;
case 1:
if (worldIn.isAirBlock(pos.east()))
{
worldIn.setBlockState(pos.east(), NaturaOverworld.saguaroFruit.getDefaultState().withProperty(BlockSaguaroFruit.FACING, EnumFacing.WEST), 3);
}
break;
case 2:
if (worldIn.isAirBlock(pos.south()))
{
worldIn.setBlockState(pos.south(), NaturaOverworld.saguaroFruit.getDefaultState().withProperty(BlockSaguaroFruit.FACING, EnumFacing.NORTH), 3);
}
break;
case 3:
if (worldIn.isAirBlock(pos.west()))
{
worldIn.setBlockState(pos.west(), NaturaOverworld.saguaroFruit.getDefaultState().withProperty(BlockSaguaroFruit.FACING, EnumFacing.EAST), 3);
}
break;
boolean canGrow = (rand.nextInt(20) == 0);

if (ForgeHooks.onCropsGrowPre(worldIn, pos, state, canGrow))
{
switch (rand.nextInt(4))
{
case 0:
if (worldIn.isAirBlock(pos.north()))
{
worldIn.setBlockState(pos.north(), NaturaOverworld.saguaroFruit.getDefaultState().withProperty(BlockSaguaroFruit.FACING, EnumFacing.SOUTH), 3);
}
break;
case 1:
if (worldIn.isAirBlock(pos.east()))
{
worldIn.setBlockState(pos.east(), NaturaOverworld.saguaroFruit.getDefaultState().withProperty(BlockSaguaroFruit.FACING, EnumFacing.WEST), 3);
}
break;
case 2:
if (worldIn.isAirBlock(pos.south()))
{
worldIn.setBlockState(pos.south(), NaturaOverworld.saguaroFruit.getDefaultState().withProperty(BlockSaguaroFruit.FACING, EnumFacing.NORTH), 3);
}
break;
case 3:
if (worldIn.isAirBlock(pos.west()))
{
worldIn.setBlockState(pos.west(), NaturaOverworld.saguaroFruit.getDefaultState().withProperty(BlockSaguaroFruit.FACING, EnumFacing.EAST), 3);
}
break;
}

ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos));
}
}
}
Expand Down
Expand Up @@ -22,6 +22,7 @@
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
Expand Down Expand Up @@ -67,14 +68,21 @@ public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random ra
{
int age = state.getValue(AGE).intValue();

if (age == 0 && rand.nextInt(200) == 0)
boolean canGrow = (rand.nextInt(200) == 0);

if (ForgeHooks.onCropsGrowPre(worldIn, pos, state, canGrow))
{
worldIn.setBlockState(pos, state.withProperty(AGE, age + 1), 3);
}
else if (age == 1 && rand.nextInt(200) == 0)
{
SaguaroGenerator gen = new SaguaroGenerator(NaturaOverworld.saguaro.getDefaultState(), true, true);
gen.generateSaguaro(rand, worldIn, pos);
if (age == 0)
{
worldIn.setBlockState(pos, state.withProperty(AGE, age + 1), 3);
}
else if (age == 1)
{
SaguaroGenerator gen = new SaguaroGenerator(NaturaOverworld.saguaro.getDefaultState(), true, true);
gen.generateSaguaro(rand, worldIn, pos);
}

ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos));
}
}

Expand Down

0 comments on commit 4bf4f4c

Please sign in to comment.