mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 03:49:14 +00:00
Added events for crop growth (#3320)
This commit is contained in:
1 parent
42e0fbbb02
commit
998a78c3c1
9 files changed
+191
-14
No files matched your search
@@ -1163,4 +1163,16 @@ public class ForgeHooks
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new ThrowableImpactEvent(throwable, ray));
|
||||
}
|
||||
|
||||
public static boolean onCropsGrowPre(World worldIn, BlockPos pos, IBlockState state, boolean def)
|
||||
{
|
||||
BlockEvent ev = new BlockEvent.CropGrowEvent.Pre(worldIn,pos,state);
|
||||
MinecraftForge.EVENT_BUS.post(ev);
|
||||
return (ev.getResult() == Event.Result.ALLOW || (ev.getResult() == Event.Result.DEFAULT && def));
|
||||
}
|
||||
|
||||
public static void onCropsGrowPost(World worldIn, BlockPos pos, IBlockState state, IBlockState blockState)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new BlockEvent.CropGrowEvent.Post(worldIn, pos, state, worldIn.getBlockState(pos)));
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,8 @@ import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.util.BlockSnapshot;
|
||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event.Result;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
@@ -285,5 +287,60 @@ public class BlockEvent extends Event
|
||||
super(world, pos, state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a crop block grows. See subevents.
|
||||
*
|
||||
*/
|
||||
public static class CropGrowEvent extends BlockEvent
|
||||
{
|
||||
public CropGrowEvent(World world, BlockPos pos, IBlockState state)
|
||||
{
|
||||
super(world, pos, state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when any "growing age" blocks (for example cacti, chorus plants, or crops
|
||||
* in vanilla) attempt to advance to the next growth age state during a random tick.<br>
|
||||
* <br>
|
||||
* {@link Result#DEFAULT} will pass on to the vanilla growth mechanics.<br>
|
||||
* {@link Result#ALLOW} will force the plant to advance a growth stage.<br>
|
||||
* {@link Result#DENY} will prevent the plant from advancing a growth stage.<br>
|
||||
* <br>
|
||||
* This event is not {@link Cancelable}.<br>
|
||||
* <br>
|
||||
*/
|
||||
@HasResult
|
||||
public static class Pre extends CropGrowEvent
|
||||
{
|
||||
public Pre(World world, BlockPos pos, IBlockState state)
|
||||
{
|
||||
super(world, pos, state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when "growing age" blocks (for example cacti, chorus plants, or crops
|
||||
* in vanilla) have successfully grown. The block's original state is available,
|
||||
* in addition to its new state.<br>
|
||||
* <br>
|
||||
* This event is not {@link Cancelable}.<br>
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
*/
|
||||
public static class Post extends CropGrowEvent
|
||||
{
|
||||
private final IBlockState originalState;
|
||||
public Post(World world, BlockPos pos, IBlockState original, IBlockState state)
|
||||
{
|
||||
super(world, pos, state);
|
||||
originalState = original;
|
||||
}
|
||||
|
||||
public IBlockState getOriginalState()
|
||||
{
|
||||
return originalState;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user