<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://forge.gemwire.uk/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=EERussianguy</id>
	<title>Forge Community Wiki - User contributions [en-gb]</title>
	<link rel="self" type="application/atom+xml" href="https://forge.gemwire.uk/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=EERussianguy"/>
	<link rel="alternate" type="text/html" href="https://forge.gemwire.uk/wiki/Special:Contributions/EERussianguy"/>
	<updated>2026-06-02T04:36:59Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.0</generator>
	<entry>
		<id>https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2582</id>
		<title>Events/BlockEvent</title>
		<link rel="alternate" type="text/html" href="https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2582"/>
		<updated>2021-04-20T18:46:14Z</updated>

		<summary type="html">&lt;p&gt;EERussianguy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The variations of &amp;lt;code&amp;gt;BlockEvent&amp;lt;/code&amp;gt; let modders intercept interactions between the player and blocks in the world. All of these events have in common the following: the &amp;lt;code&amp;gt;World&amp;lt;/code&amp;gt; the action was taken in, and the &amp;lt;code&amp;gt;BlockPos&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that's being modified.&lt;br /&gt;
&lt;br /&gt;
== BreakEvent ==&lt;br /&gt;
This event is fired before a block is broken by a player. Predictably, cancelling this event prevents the block from getting broken. Modders have two extra variables to play with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getExpToDrop()&amp;lt;/code&amp;gt;: Returns how much experience ought to drop when the block is broken. Will be zero if the event is currently canceled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setExpToDrop()&amp;lt;/code&amp;gt;: Sets the experience that's going to drop manually.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlayer()&amp;lt;/code&amp;gt;: Gets the player that's doing the action.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onBlockBreak(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getState().is(Blocks.SAND)) // use the base event to get the state and see what it is&lt;br /&gt;
        {&lt;br /&gt;
            event.setExpToDrop(10); // change the amount of experience we'll be dropping&lt;br /&gt;
            PlayerEntity player = event.getPlayer();&lt;br /&gt;
            if (player.getMainHandItem().getItem().equals(Items.DIAMOND_SHOVEL)) // check what we're holding&lt;br /&gt;
            {&lt;br /&gt;
                ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(Items.BONE)); // give a bone&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Stopping players from breaking a block&lt;br /&gt;
* Changing the XP drop of a vanilla block&lt;br /&gt;
* Modify the behavior of a tool&lt;br /&gt;
&lt;br /&gt;
== EntityPlaceEvent ==&lt;br /&gt;
This event is called when a block is placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt;: This is the entity placing the block. Note that this might not be a player! It can be null. This means you should null check the entity. By default, Forge adds this in three places: players placing blocks, endermen placing their held block, as well as ice placed by the Frost Walker enchantment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getBlockSnapshot()&amp;lt;/code&amp;gt;: Gets the snapshot of what's about to be placed. A &amp;lt;code&amp;gt;BlockSnapshot&amp;lt;/code&amp;gt; is just an object containing the dimension, position, NBT, and state of a block, along with some other info. Typically, this isn't necessary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedBlock()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedAgainst()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that was clicked in order to place the block. Imagine planting a flower on some dirt. The dirt would be the state here.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onEntityPlace(final BlockEvent.EntityPlaceEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getEntity() instanceof EndermanEntity)&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // prevent enderman placement&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* (See above) Changing how frost walker works based on certain conditions&lt;br /&gt;
* Preventing a block from being placed&lt;br /&gt;
* Changing the player's inventory when a block is placed&lt;br /&gt;
* Cause another block to be placed instead of another&lt;br /&gt;
&lt;br /&gt;
== EntityMultiPlaceEvent ==&lt;br /&gt;
This is the same as above except it's fired when a block causes another block to be replaced. A great example is beds, where placing one half of the bed causes another half to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getReplacedBlockSnapshots()&amp;lt;/code&amp;gt;: Everything is the same as before, except we now have a list of snapshots. How sweet.&lt;br /&gt;
&lt;br /&gt;
== NeighborNotifyEvent ==&lt;br /&gt;
This event is fired when a block tells its neighbors to update themselves. This happens all the time, typically with redstone blocks like tripwires or repeaters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNotifiedSides()&amp;lt;/code&amp;gt;: A set of &amp;lt;code&amp;gt;Direction&amp;lt;/code&amp;gt; values that were updated during the event. Sometimes, blocks will choose to exclude a side from being updated, but most often this will be all six directions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getForceRedstoneUpdate()&amp;lt;/code&amp;gt; This is a little funky. There's an option when blocks are set to force a redstone update. If that happened, this will be true. You typically won't need this.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onNeighborNotify(final BlockEvent.NeighborNotifyEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockPos eventPos = event.getPos();&lt;br /&gt;
        if (event.getState().is(Blocks.REDSTONE_WIRE)) // only do it for redstone&lt;br /&gt;
        {&lt;br /&gt;
            for (Direction direction : event.getNotifiedSides()) // cycle through notified directions&lt;br /&gt;
            {&lt;br /&gt;
                BlockPos pos = eventPos.relative(direction); // move to that spot&lt;br /&gt;
                if (world.isEmptyBlock(pos))&lt;br /&gt;
                {&lt;br /&gt;
                    world.setBlock(pos, Blocks.GLOWSTONE.defaultBlockState(), 3); // place glowstone&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Adding blocks that interact with redstone&lt;br /&gt;
* Making a block update detector block&lt;br /&gt;
&lt;br /&gt;
==CreateFluidSourceEvent==&lt;br /&gt;
This event controls creation of fluid sources. This is different than cancellable events, because it has a &amp;lt;code&amp;gt;Result&amp;lt;/code&amp;gt;. Setting it to &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; causes a source block to created, even if that's not normally what would happen. Setting it to &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; always prevents source creation.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onFluidSourceCreate(final BlockEvent.CreateFluidSourceEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorldReader world = event.getWorld();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getPos().getY() &amp;gt; 100)&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent source creation above y = 100&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== FluidPlaceBlockEvent ==&lt;br /&gt;
This event fires when fluids place blocks. Examples of this happening are: basalt, stone, cobblestone, obsidian, and fire (think lava pools). You can cancel this event to prevent placement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getLiquidPos()&amp;lt;/code&amp;gt; This is the liquid's position. For cases like cobble generation, this is the same as the original &amp;lt;code&amp;gt;getPos()&amp;lt;/code&amp;gt;. But for placing fire, this won't be the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNewState()&amp;lt;/code&amp;gt; Gets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setNewState()&amp;lt;/code&amp;gt; Sets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; What the block was before this event.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onFluidPlace(final BlockEvent.FluidPlaceBlockEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockState newState = event.getNewState();&lt;br /&gt;
        if (newState.is(Blocks.COBBLESTONE) &amp;amp;&amp;amp; world.dayTime() &amp;gt; 14000L)&lt;br /&gt;
        {&lt;br /&gt;
            event.setNewState(Blocks.ANDESITE.defaultBlockState()); // change the block if done during nighttime.&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing behavior of cobble generators&lt;br /&gt;
* Preventing cobble generators&lt;br /&gt;
* Adding more aggressive effects during fire spreading from lava&lt;br /&gt;
&lt;br /&gt;
== CropGrowEvent ==&lt;br /&gt;
These events are fired during crop growth. The &amp;lt;code&amp;gt;Pre&amp;lt;/code&amp;gt; event is fired before. It's fired when vanilla blocks try to  'grow' during random ticks (think cacti getting taller). Setting &amp;lt;code&amp;gt;DEFAULT&amp;lt;/code&amp;gt; as the result will cause no change. Setting &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; forces growth. Setting &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; prevents growth.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Post&amp;lt;/code&amp;gt; event is fired after growth.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; Get the state before growth happened.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onCropGrowPre(final BlockEvent.CropGrowEvent.Pre event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockState state = event.getState();&lt;br /&gt;
        if (state.is(Blocks.WHEAT))&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent wheat from growing&lt;br /&gt;
        }&lt;br /&gt;
        else if (state.is(Blocks.BAMBOO))&lt;br /&gt;
        {&lt;br /&gt;
            if (world.getRandom().nextFloat() &amp;gt; 0.2F) // take a 4/5 chance&lt;br /&gt;
            {&lt;br /&gt;
                event.setResult(Event.Result.DENY); // make bamboo grow less often&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
public void onCropsGrowPost(final BlockEvent.CropGrowEvent.Post event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getState().is(Blocks.WHEAT)) // check wheat&lt;br /&gt;
        {&lt;br /&gt;
            BlockState newState = event.getState();&lt;br /&gt;
            if (newState.is(Blocks.WHEAT)) // defensive check to make sure we can do this&lt;br /&gt;
            {&lt;br /&gt;
                world.setBlock(event.getPos(), newState.setValue(CropsBlock.AGE, 7), 3); // set max growth wheat&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing growth rate of crops&lt;br /&gt;
* Preventing crop growth under certain conditions&lt;br /&gt;
* Spawning an entity when something grows&lt;br /&gt;
&lt;br /&gt;
== FarmlandTrampleEvent ==&lt;br /&gt;
This event is fired when farmland gets trampled. You can cancel it to prevent trampling.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt; The entity that trampled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFallDistance()&amp;lt;/code&amp;gt; How far that entity fell&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onTrample(final BlockEvent.FarmlandTrampleEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getFallDistance() &amp;lt; 10.0F)&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // change conditions for trampling&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PortalSpawnEvent ==&lt;br /&gt;
This event is fired when a nether portal is created.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPortalSize()&amp;lt;/code&amp;gt; returns a &amp;lt;code&amp;gt;PortalSize&amp;lt;/code&amp;gt; object, basically only useful for determining if the portal is going to be valid or not.&lt;br /&gt;
&lt;br /&gt;
This is mostly used for preventing portal spawning in certain dimensions (even the overworld).&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onPortalLight(final BlockEvent.PortalSpawnEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        event.setCanceled(true);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== BlockToolInteractEvent ==&lt;br /&gt;
This event is fired on right click tool events, such as path creation, wood stripping, and farmland tilling. You have access to the player, the &amp;lt;code&amp;gt;ItemStack&amp;lt;/code&amp;gt; they're holding, and the &amp;lt;code&amp;gt;ToolType&amp;lt;/code&amp;gt; they have.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setFinalState()&amp;lt;/code&amp;gt;: Set what you want the result to be.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFinalState()&amp;lt;/code&amp;gt;: Returns what it will be changed to. This will normally just return whatever the original block is unless you or another modder has set it. It can't check, for example, if something *will* turn into farmland in the future.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onToolInteract(final BlockEvent.BlockToolInteractEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getHeldItemStack().getItem() == Items.NETHERITE_HOE)&lt;br /&gt;
        {&lt;br /&gt;
            event.setFinalState(Blocks.NETHERRACK.defaultBlockState()); // set the block to netherrack&lt;br /&gt;
            // note that this happens for any right click on a block, not just dirt&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this:&lt;br /&gt;
* Setting your custom farmland block during tilling&lt;br /&gt;
* Adding stripped wood behavior for other blocks&lt;br /&gt;
* Disable path creation&lt;/div&gt;</summary>
		<author><name>EERussianguy</name></author>
	</entry>
	<entry>
		<id>https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2581</id>
		<title>Events/BlockEvent</title>
		<link rel="alternate" type="text/html" href="https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2581"/>
		<updated>2021-04-20T18:20:37Z</updated>

		<summary type="html">&lt;p&gt;EERussianguy: /* CropGrowEvent */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The variations of &amp;lt;code&amp;gt;BlockEvent&amp;lt;/code&amp;gt; let modders intercept interactions between the player and blocks in the world. All of these events have in common the following: the &amp;lt;code&amp;gt;World&amp;lt;/code&amp;gt; the action was taken in, and the &amp;lt;code&amp;gt;BlockPos&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that's being modified.&lt;br /&gt;
&lt;br /&gt;
== BreakEvent ==&lt;br /&gt;
This event is fired before a block is broken by a player. Predictably, cancelling this event prevents the block from getting broken. Modders have two extra variables to play with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getExpToDrop()&amp;lt;/code&amp;gt;: Returns how much experience ought to drop when the block is broken. Will be zero if the event is currently canceled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setExpToDrop()&amp;lt;/code&amp;gt;: Sets the experience that's going to drop manually.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlayer()&amp;lt;/code&amp;gt;: Gets the player that's doing the action.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onBlockBreak(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getState().is(Blocks.SAND)) // use the base event to get the state and see what it is&lt;br /&gt;
        {&lt;br /&gt;
            event.setExpToDrop(10); // change the amount of experience we'll be dropping&lt;br /&gt;
            PlayerEntity player = event.getPlayer();&lt;br /&gt;
            if (player.getMainHandItem().getItem().equals(Items.DIAMOND_SHOVEL)) // check what we're holding&lt;br /&gt;
            {&lt;br /&gt;
                ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(Items.BONE)); // give a bone&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Stopping players from breaking a block&lt;br /&gt;
* Changing the XP drop of a vanilla block&lt;br /&gt;
* Modify the behavior of a tool&lt;br /&gt;
&lt;br /&gt;
== EntityPlaceEvent ==&lt;br /&gt;
This event is called when a block is placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt;: This is the entity placing the block. Note that this might not be a player! It can be null. This means you should null check the entity. By default, Forge adds this in three places: players placing blocks, endermen placing their held block, as well as ice placed by the Frost Walker enchantment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getBlockSnapshot()&amp;lt;/code&amp;gt;: Gets the snapshot of what's about to be placed. A &amp;lt;code&amp;gt;BlockSnapshot&amp;lt;/code&amp;gt; is just an object containing the dimension, position, NBT, and state of a block, along with some other info. Typically, this isn't necessary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedBlock()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedAgainst()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that was clicked in order to place the block. Imagine planting a flower on some dirt. The dirt would be the state here.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onEntityPlace(final BlockEvent.EntityPlaceEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getEntity() instanceof EndermanEntity)&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // prevent enderman placement&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* (See above) Changing how frost walker works based on certain conditions&lt;br /&gt;
* Preventing a block from being placed&lt;br /&gt;
* Changing the player's inventory when a block is placed&lt;br /&gt;
* Cause another block to be placed instead of another&lt;br /&gt;
&lt;br /&gt;
== EntityMultiPlaceEvent ==&lt;br /&gt;
This is the same as above except it's fired when a block causes another block to be replaced. A great example is beds, where placing one half of the bed causes another half to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getReplacedBlockSnapshots()&amp;lt;/code&amp;gt;: Everything is the same as before, except we now have a list of snapshots. How sweet.&lt;br /&gt;
&lt;br /&gt;
== NeighborNotifyEvent ==&lt;br /&gt;
This event is fired when a block tells its neighbors to update themselves. This happens all the time, typically with redstone blocks like tripwires or repeaters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNotifiedSides()&amp;lt;/code&amp;gt;: A set of &amp;lt;code&amp;gt;Direction&amp;lt;/code&amp;gt; values that were updated during the event. Sometimes, blocks will choose to exclude a side from being updated, but most often this will be all six directions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getForceRedstoneUpdate()&amp;lt;/code&amp;gt; This is a little funky. There's an option when blocks are set to force a redstone update. If that happened, this will be true. You typically won't need this.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onNeighborNotify(final BlockEvent.NeighborNotifyEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockPos eventPos = event.getPos();&lt;br /&gt;
        if (event.getState().is(Blocks.REDSTONE_WIRE)) // only do it for redstone&lt;br /&gt;
        {&lt;br /&gt;
            for (Direction direction : event.getNotifiedSides()) // cycle through notified directions&lt;br /&gt;
            {&lt;br /&gt;
                BlockPos pos = eventPos.relative(direction); // move to that spot&lt;br /&gt;
                if (world.isEmptyBlock(pos))&lt;br /&gt;
                {&lt;br /&gt;
                    world.setBlock(pos, Blocks.GLOWSTONE.defaultBlockState(), 3); // place glowstone&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Adding blocks that interact with redstone&lt;br /&gt;
* Making a block update detector block&lt;br /&gt;
&lt;br /&gt;
==CreateFluidSourceEvent==&lt;br /&gt;
This event controls creation of fluid sources. This is different than cancellable events, because it has a &amp;lt;code&amp;gt;Result&amp;lt;/code&amp;gt;. Setting it to &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; causes a source block to created, even if that's not normally what would happen. Setting it to &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; always prevents source creation.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onFluidSourceCreate(final BlockEvent.CreateFluidSourceEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorldReader world = event.getWorld();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getPos().getY() &amp;gt; 100)&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent source creation above y = 100&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== FluidPlaceBlockEvent ==&lt;br /&gt;
This event fires when fluids place blocks. Examples of this happening are: basalt, stone, cobblestone, obsidian, and fire (think lava pools). You can cancel this event to prevent placement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getLiquidPos()&amp;lt;/code&amp;gt; This is the liquid's position. For cases like cobble generation, this is the same as the original &amp;lt;code&amp;gt;getPos()&amp;lt;/code&amp;gt;. But for placing fire, this won't be the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNewState()&amp;lt;/code&amp;gt; Gets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setNewState()&amp;lt;/code&amp;gt; Sets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; What the block was before this event.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onFluidPlace(final BlockEvent.FluidPlaceBlockEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockState newState = event.getNewState();&lt;br /&gt;
        if (newState.is(Blocks.COBBLESTONE) &amp;amp;&amp;amp; world.dayTime() &amp;gt; 14000L)&lt;br /&gt;
        {&lt;br /&gt;
            event.setNewState(Blocks.ANDESITE.defaultBlockState()); // change the block if done during nighttime.&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing behavior of cobble generators&lt;br /&gt;
* Preventing cobble generators&lt;br /&gt;
* Adding more aggressive effects during fire spreading from lava&lt;br /&gt;
&lt;br /&gt;
== CropGrowEvent ==&lt;br /&gt;
These events are fired during crop growth. The &amp;lt;code&amp;gt;Pre&amp;lt;/code&amp;gt; event is fired before. It's fired when vanilla blocks try to  'grow' during random ticks (think cacti getting taller). Setting &amp;lt;code&amp;gt;DEFAULT&amp;lt;/code&amp;gt; as the result will cause no change. Setting &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; forces growth. Setting &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; prevents growth.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Post&amp;lt;/code&amp;gt; event is fired after growth.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; Get the state before growth happened.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onCropGrowPre(final BlockEvent.CropGrowEvent.Pre event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockState state = event.getState();&lt;br /&gt;
        if (state.is(Blocks.WHEAT))&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent wheat from growing&lt;br /&gt;
        }&lt;br /&gt;
        else if (state.is(Blocks.BAMBOO))&lt;br /&gt;
        {&lt;br /&gt;
            if (world.getRandom().nextFloat() &amp;gt; 0.2F) // take a 4/5 chance&lt;br /&gt;
            {&lt;br /&gt;
                event.setResult(Event.Result.DENY); // make bamboo grow less often&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
public void onCropsGrowPost(final BlockEvent.CropGrowEvent.Post event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getState().is(Blocks.WHEAT)) // check wheat&lt;br /&gt;
        {&lt;br /&gt;
            BlockState newState = event.getState();&lt;br /&gt;
            if (newState.is(Blocks.WHEAT)) // defensive check to make sure we can do this&lt;br /&gt;
            {&lt;br /&gt;
                world.setBlock(event.getPos(), newState.setValue(CropsBlock.AGE, 7), 3); // set max growth wheat&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing growth rate of crops&lt;br /&gt;
* Preventing crop growth under certain conditions&lt;br /&gt;
* Spawning an entity when something grows&lt;br /&gt;
&lt;br /&gt;
== FarmlandTrampleEvent ==&lt;br /&gt;
This event is fired when farmland gets trampled. You can cancel it to prevent trampling.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt; The entity that trampled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFallDistance()&amp;lt;/code&amp;gt; How far that entity fell&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onTrample(final BlockEvent.FarmlandTrampleEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getFallDistance() &amp;lt; 10.0F)&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // change conditions for trampling&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PortalSpawnEvent ==&lt;br /&gt;
This event is fired when a nether portal is created.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPortalSize()&amp;lt;/code&amp;gt; returns a &amp;lt;code&amp;gt;PortalSize&amp;lt;/code&amp;gt; object, basically only useful for determining if the portal is going to be valid or not.&lt;br /&gt;
&lt;br /&gt;
This is mostly used for preventing portal spawning in certain dimensions (even the overworld).&lt;br /&gt;
&lt;br /&gt;
== BlockToolInteractEvent ==&lt;br /&gt;
This event is fired on right click tool events, such as path creation, wood stripping, and farmland tilling. You have access to the player, the &amp;lt;code&amp;gt;ItemStack&amp;lt;/code&amp;gt; they're holding, and the &amp;lt;code&amp;gt;ToolType&amp;lt;/code&amp;gt; they have.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setFinalState()&amp;lt;/code&amp;gt;: Set what you want the result to be.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFinalState()&amp;lt;/code&amp;gt;: Returns what it will be changed to. This will normally just return whatever the original block is unless you or another modder has set it. It can't check, for example, if something *will* turn into farmland in the future.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onToolInteract(final BlockEvent.BlockToolInteractEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getHeldItemStack().getItem() == Items.NETHERITE_HOE)&lt;br /&gt;
        {&lt;br /&gt;
            event.setFinalState(Blocks.NETHERRACK.defaultBlockState()); // set the block to netherrack&lt;br /&gt;
            // note that this happens for any right click on a block, not just dirt&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this:&lt;br /&gt;
* Setting your custom farmland block during tilling&lt;br /&gt;
* Adding stripped wood behavior for other blocks&lt;br /&gt;
* Disable path creation&lt;/div&gt;</summary>
		<author><name>EERussianguy</name></author>
	</entry>
	<entry>
		<id>https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2580</id>
		<title>Events/BlockEvent</title>
		<link rel="alternate" type="text/html" href="https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2580"/>
		<updated>2021-04-20T18:05:35Z</updated>

		<summary type="html">&lt;p&gt;EERussianguy: more runtime issues&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The variations of &amp;lt;code&amp;gt;BlockEvent&amp;lt;/code&amp;gt; let modders intercept interactions between the player and blocks in the world. All of these events have in common the following: the &amp;lt;code&amp;gt;World&amp;lt;/code&amp;gt; the action was taken in, and the &amp;lt;code&amp;gt;BlockPos&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that's being modified.&lt;br /&gt;
&lt;br /&gt;
== BreakEvent ==&lt;br /&gt;
This event is fired before a block is broken by a player. Predictably, cancelling this event prevents the block from getting broken. Modders have two extra variables to play with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getExpToDrop()&amp;lt;/code&amp;gt;: Returns how much experience ought to drop when the block is broken. Will be zero if the event is currently canceled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setExpToDrop()&amp;lt;/code&amp;gt;: Sets the experience that's going to drop manually.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlayer()&amp;lt;/code&amp;gt;: Gets the player that's doing the action.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onBlockBreak(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getState().is(Blocks.SAND)) // use the base event to get the state and see what it is&lt;br /&gt;
        {&lt;br /&gt;
            event.setExpToDrop(10); // change the amount of experience we'll be dropping&lt;br /&gt;
            PlayerEntity player = event.getPlayer();&lt;br /&gt;
            if (player.getMainHandItem().getItem().equals(Items.DIAMOND_SHOVEL)) // check what we're holding&lt;br /&gt;
            {&lt;br /&gt;
                ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(Items.BONE)); // give a bone&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Stopping players from breaking a block&lt;br /&gt;
* Changing the XP drop of a vanilla block&lt;br /&gt;
* Modify the behavior of a tool&lt;br /&gt;
&lt;br /&gt;
== EntityPlaceEvent ==&lt;br /&gt;
This event is called when a block is placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt;: This is the entity placing the block. Note that this might not be a player! It can be null. This means you should null check the entity. By default, Forge adds this in three places: players placing blocks, endermen placing their held block, as well as ice placed by the Frost Walker enchantment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getBlockSnapshot()&amp;lt;/code&amp;gt;: Gets the snapshot of what's about to be placed. A &amp;lt;code&amp;gt;BlockSnapshot&amp;lt;/code&amp;gt; is just an object containing the dimension, position, NBT, and state of a block, along with some other info. Typically, this isn't necessary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedBlock()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedAgainst()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that was clicked in order to place the block. Imagine planting a flower on some dirt. The dirt would be the state here.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onEntityPlace(final BlockEvent.EntityPlaceEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getEntity() instanceof EndermanEntity)&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // prevent enderman placement&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* (See above) Changing how frost walker works based on certain conditions&lt;br /&gt;
* Preventing a block from being placed&lt;br /&gt;
* Changing the player's inventory when a block is placed&lt;br /&gt;
* Cause another block to be placed instead of another&lt;br /&gt;
&lt;br /&gt;
== EntityMultiPlaceEvent ==&lt;br /&gt;
This is the same as above except it's fired when a block causes another block to be replaced. A great example is beds, where placing one half of the bed causes another half to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getReplacedBlockSnapshots()&amp;lt;/code&amp;gt;: Everything is the same as before, except we now have a list of snapshots. How sweet.&lt;br /&gt;
&lt;br /&gt;
== NeighborNotifyEvent ==&lt;br /&gt;
This event is fired when a block tells its neighbors to update themselves. This happens all the time, typically with redstone blocks like tripwires or repeaters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNotifiedSides()&amp;lt;/code&amp;gt;: A set of &amp;lt;code&amp;gt;Direction&amp;lt;/code&amp;gt; values that were updated during the event. Sometimes, blocks will choose to exclude a side from being updated, but most often this will be all six directions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getForceRedstoneUpdate()&amp;lt;/code&amp;gt; This is a little funky. There's an option when blocks are set to force a redstone update. If that happened, this will be true. You typically won't need this.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onNeighborNotify(final BlockEvent.NeighborNotifyEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockPos eventPos = event.getPos();&lt;br /&gt;
        if (event.getState().is(Blocks.REDSTONE_WIRE)) // only do it for redstone&lt;br /&gt;
        {&lt;br /&gt;
            for (Direction direction : event.getNotifiedSides()) // cycle through notified directions&lt;br /&gt;
            {&lt;br /&gt;
                BlockPos pos = eventPos.relative(direction); // move to that spot&lt;br /&gt;
                if (world.isEmptyBlock(pos))&lt;br /&gt;
                {&lt;br /&gt;
                    world.setBlock(pos, Blocks.GLOWSTONE.defaultBlockState(), 3); // place glowstone&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Adding blocks that interact with redstone&lt;br /&gt;
* Making a block update detector block&lt;br /&gt;
&lt;br /&gt;
==CreateFluidSourceEvent==&lt;br /&gt;
This event controls creation of fluid sources. This is different than cancellable events, because it has a &amp;lt;code&amp;gt;Result&amp;lt;/code&amp;gt;. Setting it to &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; causes a source block to created, even if that's not normally what would happen. Setting it to &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; always prevents source creation.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onFluidSourceCreate(final BlockEvent.CreateFluidSourceEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorldReader world = event.getWorld();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getPos().getY() &amp;gt; 100)&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent source creation above y = 100&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== FluidPlaceBlockEvent ==&lt;br /&gt;
This event fires when fluids place blocks. Examples of this happening are: basalt, stone, cobblestone, obsidian, and fire (think lava pools). You can cancel this event to prevent placement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getLiquidPos()&amp;lt;/code&amp;gt; This is the liquid's position. For cases like cobble generation, this is the same as the original &amp;lt;code&amp;gt;getPos()&amp;lt;/code&amp;gt;. But for placing fire, this won't be the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNewState()&amp;lt;/code&amp;gt; Gets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setNewState()&amp;lt;/code&amp;gt; Sets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; What the block was before this event.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onFluidPlace(final BlockEvent.FluidPlaceBlockEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockState newState = event.getNewState();&lt;br /&gt;
        if (newState.is(Blocks.COBBLESTONE) &amp;amp;&amp;amp; world.dayTime() &amp;gt; 14000L)&lt;br /&gt;
        {&lt;br /&gt;
            event.setNewState(Blocks.ANDESITE.defaultBlockState()); // change the block if done during nighttime.&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing behavior of cobble generators&lt;br /&gt;
* Preventing cobble generators&lt;br /&gt;
* Adding more aggressive effects during fire spreading from lava&lt;br /&gt;
&lt;br /&gt;
== CropGrowEvent ==&lt;br /&gt;
These events are fired during crop growth. The &amp;lt;code&amp;gt;Pre&amp;lt;/code&amp;gt; event is fired before. It's fired when vanilla blocks try to  'grow' during random ticks (think cacti getting taller). Setting &amp;lt;code&amp;gt;DEFAULT&amp;lt;/code&amp;gt; as the result will cause no change. Setting &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; forces growth. Setting &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; prevents growth.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Post&amp;lt;/code&amp;gt; event is fired after growth.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; Get the state before growth happened.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onCropGrowPre(final BlockEvent.CropGrowEvent.Pre event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockState state = event.getState();&lt;br /&gt;
        if (state.is(Blocks.WHEAT))&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent wheat from growing&lt;br /&gt;
        }&lt;br /&gt;
        else if (state.is(Blocks.BAMBOO))&lt;br /&gt;
        {&lt;br /&gt;
            if (world.getRandom().nextFloat() &amp;gt; 0.2F) // take a 4/5 chance&lt;br /&gt;
            {&lt;br /&gt;
                event.setResult(Event.Result.DENY); // make bamboo grow less often&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing growth rate of crops&lt;br /&gt;
* Preventing crop growth under certain conditions&lt;br /&gt;
* Spawning an entity when something grows&lt;br /&gt;
&lt;br /&gt;
== FarmlandTrampleEvent ==&lt;br /&gt;
This event is fired when farmland gets trampled. You can cancel it to prevent trampling.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt; The entity that trampled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFallDistance()&amp;lt;/code&amp;gt; How far that entity fell&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onTrample(final BlockEvent.FarmlandTrampleEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getFallDistance() &amp;lt; 10.0F)&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // change conditions for trampling&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PortalSpawnEvent ==&lt;br /&gt;
This event is fired when a nether portal is created.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPortalSize()&amp;lt;/code&amp;gt; returns a &amp;lt;code&amp;gt;PortalSize&amp;lt;/code&amp;gt; object, basically only useful for determining if the portal is going to be valid or not.&lt;br /&gt;
&lt;br /&gt;
This is mostly used for preventing portal spawning in certain dimensions (even the overworld).&lt;br /&gt;
&lt;br /&gt;
== BlockToolInteractEvent ==&lt;br /&gt;
This event is fired on right click tool events, such as path creation, wood stripping, and farmland tilling. You have access to the player, the &amp;lt;code&amp;gt;ItemStack&amp;lt;/code&amp;gt; they're holding, and the &amp;lt;code&amp;gt;ToolType&amp;lt;/code&amp;gt; they have.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setFinalState()&amp;lt;/code&amp;gt;: Set what you want the result to be.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFinalState()&amp;lt;/code&amp;gt;: Returns what it will be changed to. This will normally just return whatever the original block is unless you or another modder has set it. It can't check, for example, if something *will* turn into farmland in the future.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onToolInteract(final BlockEvent.BlockToolInteractEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getHeldItemStack().getItem() == Items.NETHERITE_HOE)&lt;br /&gt;
        {&lt;br /&gt;
            event.setFinalState(Blocks.NETHERRACK.defaultBlockState()); // set the block to netherrack&lt;br /&gt;
            // note that this happens for any right click on a block, not just dirt&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this:&lt;br /&gt;
* Setting your custom farmland block during tilling&lt;br /&gt;
* Adding stripped wood behavior for other blocks&lt;br /&gt;
* Disable path creation&lt;/div&gt;</summary>
		<author><name>EERussianguy</name></author>
	</entry>
	<entry>
		<id>https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2579</id>
		<title>Events/BlockEvent</title>
		<link rel="alternate" type="text/html" href="https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2579"/>
		<updated>2021-04-20T17:49:47Z</updated>

		<summary type="html">&lt;p&gt;EERussianguy: some fixes&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The variations of &amp;lt;code&amp;gt;BlockEvent&amp;lt;/code&amp;gt; let modders intercept interactions between the player and blocks in the world. All of these events have in common the following: the &amp;lt;code&amp;gt;World&amp;lt;/code&amp;gt; the action was taken in, and the &amp;lt;code&amp;gt;BlockPos&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that's being modified.&lt;br /&gt;
&lt;br /&gt;
== BreakEvent ==&lt;br /&gt;
This event is fired before a block is broken by a player. Predictably, cancelling this event prevents the block from getting broken. Modders have two extra variables to play with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getExpToDrop()&amp;lt;/code&amp;gt;: Returns how much experience ought to drop when the block is broken. Will be zero if the event is currently canceled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setExpToDrop()&amp;lt;/code&amp;gt;: Sets the experience that's going to drop manually.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlayer()&amp;lt;/code&amp;gt;: Gets the player that's doing the action.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onBlockBreak(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getState().is(Blocks.SAND)) // use the base event to get the state and see what it is&lt;br /&gt;
        {&lt;br /&gt;
            event.setExpToDrop(10); // change the amount of experience we'll be dropping&lt;br /&gt;
            PlayerEntity player = event.getPlayer();&lt;br /&gt;
            if (player.getMainHandItem().getItem().equals(Items.DIAMOND_SHOVEL)) // check what we're holding&lt;br /&gt;
            {&lt;br /&gt;
                ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(Items.BONE)); // give a bone&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Stopping players from breaking a block&lt;br /&gt;
* Changing the XP drop of a vanilla block&lt;br /&gt;
* Modify the behavior of a tool&lt;br /&gt;
&lt;br /&gt;
== EntityPlaceEvent ==&lt;br /&gt;
This event is called when a block is placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt;: This is the entity placing the block. Note that this might not be a player! It can be null. This means you should null check the entity. By default, Forge adds this in three places: players placing blocks, endermen placing their held block, as well as ice placed by the Frost Walker enchantment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getBlockSnapshot()&amp;lt;/code&amp;gt;: Gets the snapshot of what's about to be placed. A &amp;lt;code&amp;gt;BlockSnapshot&amp;lt;/code&amp;gt; is just an object containing the dimension, position, NBT, and state of a block, along with some other info. Typically, this isn't necessary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedBlock()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedAgainst()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that was clicked in order to place the block. Imagine planting a flower on some dirt. The dirt would be the state here.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onEntityPlace(final BlockEvent.EntityPlaceEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getEntity() instanceof EndermanEntity)&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // prevent enderman placement&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* (See above) Changing how frost walker works based on certain conditions&lt;br /&gt;
* Preventing a block from being placed&lt;br /&gt;
* Changing the player's inventory when a block is placed&lt;br /&gt;
* Cause another block to be placed instead of another&lt;br /&gt;
&lt;br /&gt;
== EntityMultiPlaceEvent ==&lt;br /&gt;
This is the same as above except it's fired when a block causes another block to be replaced. A great example is beds, where placing one half of the bed causes another half to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getReplacedBlockSnapshots()&amp;lt;/code&amp;gt;: Everything is the same as before, except we now have a list of snapshots. How sweet.&lt;br /&gt;
&lt;br /&gt;
== NeighborNotifyEvent ==&lt;br /&gt;
This event is fired when a block tells its neighbors to update themselves. This happens all the time, typically with redstone blocks like tripwires or repeaters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNotifiedSides()&amp;lt;/code&amp;gt;: A set of &amp;lt;code&amp;gt;Direction&amp;lt;/code&amp;gt; values that were updated during the event. Sometimes, blocks will choose to exclude a side from being updated, but most often this will be all six directions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getForceRedstoneUpdate()&amp;lt;/code&amp;gt; This is a little funky. There's an option when blocks are set to force a redstone update. If that happened, this will be true. You typically won't need this.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onNeighborNotify(final BlockEvent.NeighborNotifyEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorld world = event.getWorld();&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockPos eventPos = event.getPos();&lt;br /&gt;
        if (event.getState().is(Blocks.REDSTONE_WIRE)) // only do it for redstone&lt;br /&gt;
        {&lt;br /&gt;
            for (Direction direction : event.getNotifiedSides()) // cycle through notified directions&lt;br /&gt;
            {&lt;br /&gt;
                BlockPos pos = eventPos.relative(direction); // move to that spot&lt;br /&gt;
                if (world.isEmptyBlock(pos))&lt;br /&gt;
                {&lt;br /&gt;
                    world.setBlock(pos, Blocks.GLOWSTONE.defaultBlockState(), 3); // place glowstone&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Adding blocks that interact with redstone&lt;br /&gt;
* Making a block update detector block&lt;br /&gt;
&lt;br /&gt;
==CreateFluidSourceEvent==&lt;br /&gt;
This event controls creation of fluid sources. This is different than cancellable events, because it has a &amp;lt;code&amp;gt;Result&amp;lt;/code&amp;gt;. Setting it to &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; causes a source block to created, even if that's not normally what would happen. Setting it to &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; always prevents source creation.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onFluidSourceCreate(final BlockEvent.CreateFluidSourceEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        IWorldReader world = event.getWorld();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getPos().getY() &amp;gt; 100)&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent source creation above y = 100&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== FluidPlaceBlockEvent ==&lt;br /&gt;
This event fires when fluids place blocks. Examples of this happening are: basalt, stone, cobblestone, obsidian, and fire (think lava pools). You can cancel this event to prevent placement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getLiquidPos()&amp;lt;/code&amp;gt; This is the liquid's position. For cases like cobble generation, this is the same as the original &amp;lt;code&amp;gt;getPos()&amp;lt;/code&amp;gt;. But for placing fire, this won't be the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNewState()&amp;lt;/code&amp;gt; Gets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setNewState()&amp;lt;/code&amp;gt; Sets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; What the block was before this event.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onFluidPlace(final BlockEvent.FluidPlaceBlockEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockState newState = event.getNewState();&lt;br /&gt;
        if (newState.is(Blocks.FIRE))&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // prevent fire placing from lava&lt;br /&gt;
        }&lt;br /&gt;
        else if (newState.is(Blocks.COBBLESTONE) &amp;amp;&amp;amp; event.getWorld().dayTime() &amp;gt; 14000L)&lt;br /&gt;
        {&lt;br /&gt;
            event.setNewState(Blocks.ANDESITE.defaultBlockState()); // change the block if done during nighttime.&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing behavior of cobble generators&lt;br /&gt;
* Preventing cobble generators&lt;br /&gt;
* Adding more aggressive effects during fire spreading from lava&lt;br /&gt;
&lt;br /&gt;
== CropGrowEvent ==&lt;br /&gt;
These events are fired during crop growth. The &amp;lt;code&amp;gt;Pre&amp;lt;/code&amp;gt; event is fired before. It's fired when vanilla blocks try to  'grow' during random ticks (think cacti getting taller). Setting &amp;lt;code&amp;gt;DEFAULT&amp;lt;/code&amp;gt; as the result will cause no change. Setting &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; forces growth. Setting &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; prevents growth.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Post&amp;lt;/code&amp;gt; event is fired after growth.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; Get the state before growth happened.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onCropGrowPre(final BlockEvent.CropGrowEvent.Pre event)&lt;br /&gt;
    {&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockState state = event.getState();&lt;br /&gt;
        if (state.is(Blocks.WHEAT))&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent wheat from growing&lt;br /&gt;
        }&lt;br /&gt;
        else if (state.is(Blocks.BAMBOO))&lt;br /&gt;
        {&lt;br /&gt;
            if (event.getWorld().getRandom().nextFloat() &amp;gt; 0.2F) // take a 4/5 chance&lt;br /&gt;
            {&lt;br /&gt;
                event.setResult(Event.Result.DENY); // make bamboo grow less often&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing growth rate of crops&lt;br /&gt;
* Preventing crop growth under certain conditions&lt;br /&gt;
* Spawning an entity when something grows&lt;br /&gt;
&lt;br /&gt;
== FarmlandTrampleEvent ==&lt;br /&gt;
This event is fired when farmland gets trampled. You can cancel it to prevent trampling.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt; The entity that trampled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFallDistance()&amp;lt;/code&amp;gt; How far that entity fell&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onTrample(final BlockEvent.FarmlandTrampleEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getFallDistance() &amp;lt; 10.0F)&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // change conditions for trampling&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PortalSpawnEvent ==&lt;br /&gt;
This event is fired when a nether portal is created.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPortalSize()&amp;lt;/code&amp;gt; returns a &amp;lt;code&amp;gt;PortalSize&amp;lt;/code&amp;gt; object, basically only useful for determining if the portal is going to be valid or not.&lt;br /&gt;
&lt;br /&gt;
This is mostly used for preventing portal spawning in certain dimensions (even the overworld).&lt;br /&gt;
&lt;br /&gt;
== BlockToolInteractEvent ==&lt;br /&gt;
This event is fired on right click tool events, such as path creation, wood stripping, and farmland tilling. You have access to the player, the &amp;lt;code&amp;gt;ItemStack&amp;lt;/code&amp;gt; they're holding, and the &amp;lt;code&amp;gt;ToolType&amp;lt;/code&amp;gt; they have.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setFinalState()&amp;lt;/code&amp;gt;: Set what you want the result to be.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFinalState()&amp;lt;/code&amp;gt;: Returns what it will be changed to.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onToolInteract(final BlockEvent.BlockToolInteractEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getFinalState().is(Blocks.FARMLAND) &amp;amp;&amp;amp; event.getHeldItemStack().getItem() == Items.NETHERITE_HOE)&lt;br /&gt;
        {&lt;br /&gt;
            event.setFinalState(Blocks.NETHERRACK.defaultBlockState()); // change the final state under certain conditions&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this:&lt;br /&gt;
* Setting your custom farmland block during tilling&lt;br /&gt;
* Adding stripped wood behavior for other blocks&lt;br /&gt;
* Disable path creation&lt;/div&gt;</summary>
		<author><name>EERussianguy</name></author>
	</entry>
	<entry>
		<id>https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2578</id>
		<title>Events/BlockEvent</title>
		<link rel="alternate" type="text/html" href="https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2578"/>
		<updated>2021-04-20T17:08:54Z</updated>

		<summary type="html">&lt;p&gt;EERussianguy: /* NeighborNotifyEvent */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The variations of &amp;lt;code&amp;gt;BlockEvent&amp;lt;/code&amp;gt; let modders intercept interactions between the player and blocks in the world. All of these events have in common the following: the &amp;lt;code&amp;gt;World&amp;lt;/code&amp;gt; the action was taken in, and the &amp;lt;code&amp;gt;BlockPos&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that's being modified.&lt;br /&gt;
&lt;br /&gt;
== BreakEvent ==&lt;br /&gt;
This event is fired before a block is broken by a player. Predictably, cancelling this event prevents the block from getting broken. Modders have two extra variables to play with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getExpToDrop()&amp;lt;/code&amp;gt;: Returns how much experience ought to drop when the block is broken. Will be zero if the event is currently canceled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setExpToDrop()&amp;lt;/code&amp;gt;: Sets the experience that's going to drop manually.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlayer()&amp;lt;/code&amp;gt;: Gets the player that's doing the action.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onBlockBreak(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getState().is(Blocks.SAND)) // use the base event to get the state and see what it is&lt;br /&gt;
        {&lt;br /&gt;
            event.setExpToDrop(10); // change the amount of experience we'll be dropping&lt;br /&gt;
            PlayerEntity player = event.getPlayer();&lt;br /&gt;
            if (player.getUseItem().getItem().is(Items.SHEARS)) // check if the player is holding shears&lt;br /&gt;
            {&lt;br /&gt;
                ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(Items.BONE)); // give a bone to the player!&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Stopping players from breaking a block&lt;br /&gt;
* Changing the XP drop of a vanilla block&lt;br /&gt;
* Modify the behavior of a tool&lt;br /&gt;
&lt;br /&gt;
== EntityPlaceEvent ==&lt;br /&gt;
This event is called when a block is placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt;: This is the entity placing the block. Note that this might not be a player! It can be null. This means you should null check the entity. By default, Forge adds this in three places: players placing blocks, endermen placing their held block, as well as ice placed by the Frost Walker enchantment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getBlockSnapshot()&amp;lt;/code&amp;gt;: Gets the snapshot of what's about to be placed. A &amp;lt;code&amp;gt;BlockSnapshot&amp;lt;/code&amp;gt; is just an object containing the dimension, position, NBT, and state of a block, along with some other info. Typically, this isn't necessary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedBlock()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedAgainst()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that was clicked in order to place the block. Imagine planting a flower on some dirt. The dirt would be the state here.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onEntityPlace(final BlockEvent.EntityPlaceEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        Entity entity = event.getEntity();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; entity != null) // check if the entity is null&lt;br /&gt;
        {&lt;br /&gt;
            Block block = event.getState().getBlock(); // get the block that was placed&lt;br /&gt;
            if (entity instanceof PlayerEntity &amp;amp;&amp;amp; block.is(Blocks.FROSTED_ICE))&lt;br /&gt;
            {&lt;br /&gt;
                event.setCanceled(true); // cancel the placing&lt;br /&gt;
                event.getWorld().setBlock(event.getPos(), Blocks.COBBLESTONE.defaultBlockState(), 3); // set cobble instead&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* (See above) Changing how frost walker works based on certain conditions&lt;br /&gt;
* Preventing a block from being placed&lt;br /&gt;
* Changing the player's inventory when a block is placed&lt;br /&gt;
* Cause another block to be placed instead of another&lt;br /&gt;
&lt;br /&gt;
== EntityMultiPlaceEvent ==&lt;br /&gt;
This is the same as above except it's fired when a block causes another block to be replaced. A great example is beds, where placing one half of the bed causes another half to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getReplacedBlockSnapshots()&amp;lt;/code&amp;gt;: Everything is the same as before, except we now have a list of snapshots. How sweet.&lt;br /&gt;
&lt;br /&gt;
== NeighborNotifyEvent ==&lt;br /&gt;
This event is fired when a block tells its neighbors to update themselves. This happens all the time, typically with redstone blocks like tripwires or repeaters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNotifiedSides()&amp;lt;/code&amp;gt;: A set of &amp;lt;code&amp;gt;Direction&amp;lt;/code&amp;gt; values that were updated during the event. Sometimes, blocks will choose to exclude a side from being updated, but most often this will be all six directions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getForceRedstoneUpdate()&amp;lt;/code&amp;gt; This is a little funky. There's an option when blocks are set to force a redstone update. If that happened, this will be true. You typically won't need this.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onNeighborNotify(final BlockEvent.NeighborNotifyEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide()) return;&lt;br /&gt;
        BlockPos eventPos = event.getPos();&lt;br /&gt;
        for (Direction direction : event.getNotifiedSides()) // cycle through notified directions&lt;br /&gt;
        {&lt;br /&gt;
            BlockPos pos = eventPos.relative(direction); // move to the direction given&lt;br /&gt;
            double x = pos.getX() + 0.5D; // move to center of the block&lt;br /&gt;
            double y = pos.getY() + 0.5D;&lt;br /&gt;
            double z = pos.getZ() + 0.5D;&lt;br /&gt;
            // add particle&lt;br /&gt;
            event.getWorld().addParticle(ParticleTypes.CLOUD, x, y, z, 0.0D, 0.0D, 0.0D);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Adding blocks that interact with redstone&lt;br /&gt;
* Making a block update detector block&lt;br /&gt;
&lt;br /&gt;
==CreateFluidSourceEvent==&lt;br /&gt;
This event controls creation of fluid sources. This is different than cancellable events, because it has a &amp;lt;code&amp;gt;Result&amp;lt;/code&amp;gt;. Setting it to &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; causes a source block to created, even if that's not normally what would happen. Setting it to &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; always prevents source creation.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onFluidSourceCreate(final BlockEvent.CreateFluidSourceEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getPos().getY() &amp;gt; 100)&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent source creation above y = 100&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== FluidPlaceBlockEvent ==&lt;br /&gt;
This event fires when fluids place blocks. Examples of this happening are: basalt, stone, cobblestone, obsidian, and fire (think lava pools). You can cancel this event to prevent placement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getLiquidPos()&amp;lt;/code&amp;gt; This is the liquid's position. For cases like cobble generation, this is the same as the original &amp;lt;code&amp;gt;getPos()&amp;lt;/code&amp;gt;. But for placing fire, this won't be the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNewState()&amp;lt;/code&amp;gt; Gets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setNewState()&amp;lt;/code&amp;gt; Sets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; What the block was before this event.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onFluidPlace(final BlockEvent.FluidPlaceBlockEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockState newState = event.getNewState();&lt;br /&gt;
        if (newState.is(Blocks.FIRE))&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // prevent fire placing from lava&lt;br /&gt;
        }&lt;br /&gt;
        else if (newState.is(Blocks.COBBLESTONE) &amp;amp;&amp;amp; event.getWorld().dayTime() &amp;gt; 14000L)&lt;br /&gt;
        {&lt;br /&gt;
            event.setNewState(Blocks.ANDESITE.defaultBlockState()); // change the block if done during nighttime.&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing behavior of cobble generators&lt;br /&gt;
* Preventing cobble generators&lt;br /&gt;
* Adding more aggressive effects during fire spreading from lava&lt;br /&gt;
&lt;br /&gt;
== CropGrowEvent ==&lt;br /&gt;
These events are fired during crop growth. The &amp;lt;code&amp;gt;Pre&amp;lt;/code&amp;gt; event is fired before. It's fired when vanilla blocks try to  'grow' during random ticks (think cacti getting taller). Setting &amp;lt;code&amp;gt;DEFAULT&amp;lt;/code&amp;gt; as the result will cause no change. Setting &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; forces growth. Setting &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; prevents growth.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Post&amp;lt;/code&amp;gt; event is fired after growth.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; Get the state before growth happened.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onCropGrowPre(final BlockEvent.CropGrowEvent.Pre event)&lt;br /&gt;
    {&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockState state = event.getState();&lt;br /&gt;
        if (state.is(Blocks.WHEAT))&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent wheat from growing&lt;br /&gt;
        }&lt;br /&gt;
        else if (state.is(Blocks.BAMBOO))&lt;br /&gt;
        {&lt;br /&gt;
            if (event.getWorld().getRandom().nextFloat() &amp;gt; 0.2F) // take a 4/5 chance&lt;br /&gt;
            {&lt;br /&gt;
                event.setResult(Event.Result.DENY); // make bamboo grow less often&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing growth rate of crops&lt;br /&gt;
* Preventing crop growth under certain conditions&lt;br /&gt;
* Spawning an entity when something grows&lt;br /&gt;
&lt;br /&gt;
== FarmlandTrampleEvent ==&lt;br /&gt;
This event is fired when farmland gets trampled. You can cancel it to prevent trampling.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt; The entity that trampled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFallDistance()&amp;lt;/code&amp;gt; How far that entity fell&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onTrample(final BlockEvent.FarmlandTrampleEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getFallDistance() &amp;lt; 10.0F)&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // change conditions for trampling&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PortalSpawnEvent ==&lt;br /&gt;
This event is fired when a nether portal is created.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPortalSize()&amp;lt;/code&amp;gt; returns a &amp;lt;code&amp;gt;PortalSize&amp;lt;/code&amp;gt; object, basically only useful for determining if the portal is going to be valid or not.&lt;br /&gt;
&lt;br /&gt;
This is mostly used for preventing portal spawning in certain dimensions (even the overworld).&lt;br /&gt;
&lt;br /&gt;
== BlockToolInteractEvent ==&lt;br /&gt;
This event is fired on right click tool events, such as path creation, wood stripping, and farmland tilling. You have access to the player, the &amp;lt;code&amp;gt;ItemStack&amp;lt;/code&amp;gt; they're holding, and the &amp;lt;code&amp;gt;ToolType&amp;lt;/code&amp;gt; they have.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setFinalState()&amp;lt;/code&amp;gt;: Set what you want the result to be.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFinalState()&amp;lt;/code&amp;gt;: Returns what it will be changed to.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onToolInteract(final BlockEvent.BlockToolInteractEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getFinalState().is(Blocks.FARMLAND) &amp;amp;&amp;amp; event.getHeldItemStack().getItem() == Items.NETHERITE_HOE)&lt;br /&gt;
        {&lt;br /&gt;
            event.setFinalState(Blocks.NETHERRACK.defaultBlockState()); // change the final state under certain conditions&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this:&lt;br /&gt;
* Setting your custom farmland block during tilling&lt;br /&gt;
* Adding stripped wood behavior for other blocks&lt;br /&gt;
* Disable path creation&lt;/div&gt;</summary>
		<author><name>EERussianguy</name></author>
	</entry>
	<entry>
		<id>https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2577</id>
		<title>Events/BlockEvent</title>
		<link rel="alternate" type="text/html" href="https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2577"/>
		<updated>2021-04-20T17:06:22Z</updated>

		<summary type="html">&lt;p&gt;EERussianguy: /* CreateFluidSourceEvent */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The variations of &amp;lt;code&amp;gt;BlockEvent&amp;lt;/code&amp;gt; let modders intercept interactions between the player and blocks in the world. All of these events have in common the following: the &amp;lt;code&amp;gt;World&amp;lt;/code&amp;gt; the action was taken in, and the &amp;lt;code&amp;gt;BlockPos&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that's being modified.&lt;br /&gt;
&lt;br /&gt;
== BreakEvent ==&lt;br /&gt;
This event is fired before a block is broken by a player. Predictably, cancelling this event prevents the block from getting broken. Modders have two extra variables to play with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getExpToDrop()&amp;lt;/code&amp;gt;: Returns how much experience ought to drop when the block is broken. Will be zero if the event is currently canceled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setExpToDrop()&amp;lt;/code&amp;gt;: Sets the experience that's going to drop manually.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlayer()&amp;lt;/code&amp;gt;: Gets the player that's doing the action.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onBlockBreak(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getState().is(Blocks.SAND)) // use the base event to get the state and see what it is&lt;br /&gt;
        {&lt;br /&gt;
            event.setExpToDrop(10); // change the amount of experience we'll be dropping&lt;br /&gt;
            PlayerEntity player = event.getPlayer();&lt;br /&gt;
            if (player.getUseItem().getItem().is(Items.SHEARS)) // check if the player is holding shears&lt;br /&gt;
            {&lt;br /&gt;
                ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(Items.BONE)); // give a bone to the player!&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Stopping players from breaking a block&lt;br /&gt;
* Changing the XP drop of a vanilla block&lt;br /&gt;
* Modify the behavior of a tool&lt;br /&gt;
&lt;br /&gt;
== EntityPlaceEvent ==&lt;br /&gt;
This event is called when a block is placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt;: This is the entity placing the block. Note that this might not be a player! It can be null. This means you should null check the entity. By default, Forge adds this in three places: players placing blocks, endermen placing their held block, as well as ice placed by the Frost Walker enchantment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getBlockSnapshot()&amp;lt;/code&amp;gt;: Gets the snapshot of what's about to be placed. A &amp;lt;code&amp;gt;BlockSnapshot&amp;lt;/code&amp;gt; is just an object containing the dimension, position, NBT, and state of a block, along with some other info. Typically, this isn't necessary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedBlock()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedAgainst()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that was clicked in order to place the block. Imagine planting a flower on some dirt. The dirt would be the state here.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onEntityPlace(final BlockEvent.EntityPlaceEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        Entity entity = event.getEntity();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; entity != null) // check if the entity is null&lt;br /&gt;
        {&lt;br /&gt;
            Block block = event.getState().getBlock(); // get the block that was placed&lt;br /&gt;
            if (entity instanceof PlayerEntity &amp;amp;&amp;amp; block.is(Blocks.FROSTED_ICE))&lt;br /&gt;
            {&lt;br /&gt;
                event.setCanceled(true); // cancel the placing&lt;br /&gt;
                event.getWorld().setBlock(event.getPos(), Blocks.COBBLESTONE.defaultBlockState(), 3); // set cobble instead&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* (See above) Changing how frost walker works based on certain conditions&lt;br /&gt;
* Preventing a block from being placed&lt;br /&gt;
* Changing the player's inventory when a block is placed&lt;br /&gt;
* Cause another block to be placed instead of another&lt;br /&gt;
&lt;br /&gt;
== EntityMultiPlaceEvent ==&lt;br /&gt;
This is the same as above except it's fired when a block causes another block to be replaced. A great example is beds, where placing one half of the bed causes another half to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getReplacedBlockSnapshots()&amp;lt;/code&amp;gt;: Everything is the same as before, except we now have a list of snapshots. How sweet.&lt;br /&gt;
&lt;br /&gt;
== NeighborNotifyEvent ==&lt;br /&gt;
This event is fired when a block tells its neighbors to update themselves. This happens all the time, typically with redstone blocks like tripwires or repeaters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNotifiedSides()&amp;lt;/code&amp;gt;: A set of &amp;lt;code&amp;gt;Direction&amp;lt;/code&amp;gt; values that were updated during the event. Sometimes, blocks will choose to exclude a side from being updated, but most often this will be all six directions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getForceRedstoneUpdate()&amp;lt;/code&amp;gt; This is a little funky. There's an option when blocks are set to force a redstone update. If that happened, this will be true. You typically won't need this.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onNeighborNotify(final BlockEvent.NeighborNotifyEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockPos eventPos = event.getPos();&lt;br /&gt;
        for (Direction direction : event.getNotifiedSides()) // cycle through notified directions&lt;br /&gt;
        {&lt;br /&gt;
            BlockPos pos = eventPos.relative(direction); // move to the direction given&lt;br /&gt;
            double x = pos.getX() + 0.5D; // move to center of the block&lt;br /&gt;
            double y = pos.getY() + 0.5D;&lt;br /&gt;
            double z = pos.getZ() + 0.5D;&lt;br /&gt;
            // add particle&lt;br /&gt;
            event.getWorld().addParticle(ParticleTypes.CLOUD, x, y, z, 0.0D, 0.0D, 0.0D);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Adding blocks that interact with redstone&lt;br /&gt;
* Making a block update detector block&lt;br /&gt;
&lt;br /&gt;
==CreateFluidSourceEvent==&lt;br /&gt;
This event controls creation of fluid sources. This is different than cancellable events, because it has a &amp;lt;code&amp;gt;Result&amp;lt;/code&amp;gt;. Setting it to &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; causes a source block to created, even if that's not normally what would happen. Setting it to &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; always prevents source creation.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onFluidSourceCreate(final BlockEvent.CreateFluidSourceEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getPos().getY() &amp;gt; 100)&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent source creation above y = 100&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== FluidPlaceBlockEvent ==&lt;br /&gt;
This event fires when fluids place blocks. Examples of this happening are: basalt, stone, cobblestone, obsidian, and fire (think lava pools). You can cancel this event to prevent placement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getLiquidPos()&amp;lt;/code&amp;gt; This is the liquid's position. For cases like cobble generation, this is the same as the original &amp;lt;code&amp;gt;getPos()&amp;lt;/code&amp;gt;. But for placing fire, this won't be the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNewState()&amp;lt;/code&amp;gt; Gets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setNewState()&amp;lt;/code&amp;gt; Sets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; What the block was before this event.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onFluidPlace(final BlockEvent.FluidPlaceBlockEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockState newState = event.getNewState();&lt;br /&gt;
        if (newState.is(Blocks.FIRE))&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // prevent fire placing from lava&lt;br /&gt;
        }&lt;br /&gt;
        else if (newState.is(Blocks.COBBLESTONE) &amp;amp;&amp;amp; event.getWorld().dayTime() &amp;gt; 14000L)&lt;br /&gt;
        {&lt;br /&gt;
            event.setNewState(Blocks.ANDESITE.defaultBlockState()); // change the block if done during nighttime.&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing behavior of cobble generators&lt;br /&gt;
* Preventing cobble generators&lt;br /&gt;
* Adding more aggressive effects during fire spreading from lava&lt;br /&gt;
&lt;br /&gt;
== CropGrowEvent ==&lt;br /&gt;
These events are fired during crop growth. The &amp;lt;code&amp;gt;Pre&amp;lt;/code&amp;gt; event is fired before. It's fired when vanilla blocks try to  'grow' during random ticks (think cacti getting taller). Setting &amp;lt;code&amp;gt;DEFAULT&amp;lt;/code&amp;gt; as the result will cause no change. Setting &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; forces growth. Setting &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; prevents growth.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Post&amp;lt;/code&amp;gt; event is fired after growth.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; Get the state before growth happened.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onCropGrowPre(final BlockEvent.CropGrowEvent.Pre event)&lt;br /&gt;
    {&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockState state = event.getState();&lt;br /&gt;
        if (state.is(Blocks.WHEAT))&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent wheat from growing&lt;br /&gt;
        }&lt;br /&gt;
        else if (state.is(Blocks.BAMBOO))&lt;br /&gt;
        {&lt;br /&gt;
            if (event.getWorld().getRandom().nextFloat() &amp;gt; 0.2F) // take a 4/5 chance&lt;br /&gt;
            {&lt;br /&gt;
                event.setResult(Event.Result.DENY); // make bamboo grow less often&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing growth rate of crops&lt;br /&gt;
* Preventing crop growth under certain conditions&lt;br /&gt;
* Spawning an entity when something grows&lt;br /&gt;
&lt;br /&gt;
== FarmlandTrampleEvent ==&lt;br /&gt;
This event is fired when farmland gets trampled. You can cancel it to prevent trampling.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt; The entity that trampled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFallDistance()&amp;lt;/code&amp;gt; How far that entity fell&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onTrample(final BlockEvent.FarmlandTrampleEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getFallDistance() &amp;lt; 10.0F)&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // change conditions for trampling&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PortalSpawnEvent ==&lt;br /&gt;
This event is fired when a nether portal is created.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPortalSize()&amp;lt;/code&amp;gt; returns a &amp;lt;code&amp;gt;PortalSize&amp;lt;/code&amp;gt; object, basically only useful for determining if the portal is going to be valid or not.&lt;br /&gt;
&lt;br /&gt;
This is mostly used for preventing portal spawning in certain dimensions (even the overworld).&lt;br /&gt;
&lt;br /&gt;
== BlockToolInteractEvent ==&lt;br /&gt;
This event is fired on right click tool events, such as path creation, wood stripping, and farmland tilling. You have access to the player, the &amp;lt;code&amp;gt;ItemStack&amp;lt;/code&amp;gt; they're holding, and the &amp;lt;code&amp;gt;ToolType&amp;lt;/code&amp;gt; they have.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setFinalState()&amp;lt;/code&amp;gt;: Set what you want the result to be.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFinalState()&amp;lt;/code&amp;gt;: Returns what it will be changed to.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onToolInteract(final BlockEvent.BlockToolInteractEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getFinalState().is(Blocks.FARMLAND) &amp;amp;&amp;amp; event.getHeldItemStack().getItem() == Items.NETHERITE_HOE)&lt;br /&gt;
        {&lt;br /&gt;
            event.setFinalState(Blocks.NETHERRACK.defaultBlockState()); // change the final state under certain conditions&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this:&lt;br /&gt;
* Setting your custom farmland block during tilling&lt;br /&gt;
* Adding stripped wood behavior for other blocks&lt;br /&gt;
* Disable path creation&lt;/div&gt;</summary>
		<author><name>EERussianguy</name></author>
	</entry>
	<entry>
		<id>https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2576</id>
		<title>Events/BlockEvent</title>
		<link rel="alternate" type="text/html" href="https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2576"/>
		<updated>2021-04-20T17:05:56Z</updated>

		<summary type="html">&lt;p&gt;EERussianguy: params&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The variations of &amp;lt;code&amp;gt;BlockEvent&amp;lt;/code&amp;gt; let modders intercept interactions between the player and blocks in the world. All of these events have in common the following: the &amp;lt;code&amp;gt;World&amp;lt;/code&amp;gt; the action was taken in, and the &amp;lt;code&amp;gt;BlockPos&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that's being modified.&lt;br /&gt;
&lt;br /&gt;
== BreakEvent ==&lt;br /&gt;
This event is fired before a block is broken by a player. Predictably, cancelling this event prevents the block from getting broken. Modders have two extra variables to play with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getExpToDrop()&amp;lt;/code&amp;gt;: Returns how much experience ought to drop when the block is broken. Will be zero if the event is currently canceled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setExpToDrop()&amp;lt;/code&amp;gt;: Sets the experience that's going to drop manually.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlayer()&amp;lt;/code&amp;gt;: Gets the player that's doing the action.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onBlockBreak(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getState().is(Blocks.SAND)) // use the base event to get the state and see what it is&lt;br /&gt;
        {&lt;br /&gt;
            event.setExpToDrop(10); // change the amount of experience we'll be dropping&lt;br /&gt;
            PlayerEntity player = event.getPlayer();&lt;br /&gt;
            if (player.getUseItem().getItem().is(Items.SHEARS)) // check if the player is holding shears&lt;br /&gt;
            {&lt;br /&gt;
                ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(Items.BONE)); // give a bone to the player!&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Stopping players from breaking a block&lt;br /&gt;
* Changing the XP drop of a vanilla block&lt;br /&gt;
* Modify the behavior of a tool&lt;br /&gt;
&lt;br /&gt;
== EntityPlaceEvent ==&lt;br /&gt;
This event is called when a block is placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt;: This is the entity placing the block. Note that this might not be a player! It can be null. This means you should null check the entity. By default, Forge adds this in three places: players placing blocks, endermen placing their held block, as well as ice placed by the Frost Walker enchantment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getBlockSnapshot()&amp;lt;/code&amp;gt;: Gets the snapshot of what's about to be placed. A &amp;lt;code&amp;gt;BlockSnapshot&amp;lt;/code&amp;gt; is just an object containing the dimension, position, NBT, and state of a block, along with some other info. Typically, this isn't necessary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedBlock()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedAgainst()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that was clicked in order to place the block. Imagine planting a flower on some dirt. The dirt would be the state here.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onEntityPlace(final BlockEvent.EntityPlaceEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        Entity entity = event.getEntity();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; entity != null) // check if the entity is null&lt;br /&gt;
        {&lt;br /&gt;
            Block block = event.getState().getBlock(); // get the block that was placed&lt;br /&gt;
            if (entity instanceof PlayerEntity &amp;amp;&amp;amp; block.is(Blocks.FROSTED_ICE))&lt;br /&gt;
            {&lt;br /&gt;
                event.setCanceled(true); // cancel the placing&lt;br /&gt;
                event.getWorld().setBlock(event.getPos(), Blocks.COBBLESTONE.defaultBlockState(), 3); // set cobble instead&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* (See above) Changing how frost walker works based on certain conditions&lt;br /&gt;
* Preventing a block from being placed&lt;br /&gt;
* Changing the player's inventory when a block is placed&lt;br /&gt;
* Cause another block to be placed instead of another&lt;br /&gt;
&lt;br /&gt;
== EntityMultiPlaceEvent ==&lt;br /&gt;
This is the same as above except it's fired when a block causes another block to be replaced. A great example is beds, where placing one half of the bed causes another half to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getReplacedBlockSnapshots()&amp;lt;/code&amp;gt;: Everything is the same as before, except we now have a list of snapshots. How sweet.&lt;br /&gt;
&lt;br /&gt;
== NeighborNotifyEvent ==&lt;br /&gt;
This event is fired when a block tells its neighbors to update themselves. This happens all the time, typically with redstone blocks like tripwires or repeaters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNotifiedSides()&amp;lt;/code&amp;gt;: A set of &amp;lt;code&amp;gt;Direction&amp;lt;/code&amp;gt; values that were updated during the event. Sometimes, blocks will choose to exclude a side from being updated, but most often this will be all six directions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getForceRedstoneUpdate()&amp;lt;/code&amp;gt; This is a little funky. There's an option when blocks are set to force a redstone update. If that happened, this will be true. You typically won't need this.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onNeighborNotify(final BlockEvent.NeighborNotifyEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockPos eventPos = event.getPos();&lt;br /&gt;
        for (Direction direction : event.getNotifiedSides()) // cycle through notified directions&lt;br /&gt;
        {&lt;br /&gt;
            BlockPos pos = eventPos.relative(direction); // move to the direction given&lt;br /&gt;
            double x = pos.getX() + 0.5D; // move to center of the block&lt;br /&gt;
            double y = pos.getY() + 0.5D;&lt;br /&gt;
            double z = pos.getZ() + 0.5D;&lt;br /&gt;
            // add particle&lt;br /&gt;
            event.getWorld().addParticle(ParticleTypes.CLOUD, x, y, z, 0.0D, 0.0D, 0.0D);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Adding blocks that interact with redstone&lt;br /&gt;
* Making a block update detector block&lt;br /&gt;
&lt;br /&gt;
== CreateFluidSourceEvent ==&lt;br /&gt;
This event controls creation of fluid sources. This is different than cancellable events, because it has a &amp;lt;code&amp;gt;Result&amp;lt;/code&amp;gt;. Setting it to &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; causes a source block to created, even if that's not normally what would happen. Setting it to &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; always prevents source creation.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onNeighborNotify(final BlockEvent.CreateFluidSourceEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getPos().getY() &amp;gt; 100)&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent source creation above y = 100&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== FluidPlaceBlockEvent ==&lt;br /&gt;
This event fires when fluids place blocks. Examples of this happening are: basalt, stone, cobblestone, obsidian, and fire (think lava pools). You can cancel this event to prevent placement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getLiquidPos()&amp;lt;/code&amp;gt; This is the liquid's position. For cases like cobble generation, this is the same as the original &amp;lt;code&amp;gt;getPos()&amp;lt;/code&amp;gt;. But for placing fire, this won't be the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNewState()&amp;lt;/code&amp;gt; Gets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setNewState()&amp;lt;/code&amp;gt; Sets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; What the block was before this event.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onFluidPlace(final BlockEvent.FluidPlaceBlockEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockState newState = event.getNewState();&lt;br /&gt;
        if (newState.is(Blocks.FIRE))&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // prevent fire placing from lava&lt;br /&gt;
        }&lt;br /&gt;
        else if (newState.is(Blocks.COBBLESTONE) &amp;amp;&amp;amp; event.getWorld().dayTime() &amp;gt; 14000L)&lt;br /&gt;
        {&lt;br /&gt;
            event.setNewState(Blocks.ANDESITE.defaultBlockState()); // change the block if done during nighttime.&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing behavior of cobble generators&lt;br /&gt;
* Preventing cobble generators&lt;br /&gt;
* Adding more aggressive effects during fire spreading from lava&lt;br /&gt;
&lt;br /&gt;
== CropGrowEvent ==&lt;br /&gt;
These events are fired during crop growth. The &amp;lt;code&amp;gt;Pre&amp;lt;/code&amp;gt; event is fired before. It's fired when vanilla blocks try to  'grow' during random ticks (think cacti getting taller). Setting &amp;lt;code&amp;gt;DEFAULT&amp;lt;/code&amp;gt; as the result will cause no change. Setting &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; forces growth. Setting &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; prevents growth.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Post&amp;lt;/code&amp;gt; event is fired after growth.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; Get the state before growth happened.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onCropGrowPre(final BlockEvent.CropGrowEvent.Pre event)&lt;br /&gt;
    {&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockState state = event.getState();&lt;br /&gt;
        if (state.is(Blocks.WHEAT))&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent wheat from growing&lt;br /&gt;
        }&lt;br /&gt;
        else if (state.is(Blocks.BAMBOO))&lt;br /&gt;
        {&lt;br /&gt;
            if (event.getWorld().getRandom().nextFloat() &amp;gt; 0.2F) // take a 4/5 chance&lt;br /&gt;
            {&lt;br /&gt;
                event.setResult(Event.Result.DENY); // make bamboo grow less often&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing growth rate of crops&lt;br /&gt;
* Preventing crop growth under certain conditions&lt;br /&gt;
* Spawning an entity when something grows&lt;br /&gt;
&lt;br /&gt;
== FarmlandTrampleEvent ==&lt;br /&gt;
This event is fired when farmland gets trampled. You can cancel it to prevent trampling.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt; The entity that trampled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFallDistance()&amp;lt;/code&amp;gt; How far that entity fell&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onTrample(final BlockEvent.FarmlandTrampleEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getFallDistance() &amp;lt; 10.0F)&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // change conditions for trampling&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PortalSpawnEvent ==&lt;br /&gt;
This event is fired when a nether portal is created.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPortalSize()&amp;lt;/code&amp;gt; returns a &amp;lt;code&amp;gt;PortalSize&amp;lt;/code&amp;gt; object, basically only useful for determining if the portal is going to be valid or not.&lt;br /&gt;
&lt;br /&gt;
This is mostly used for preventing portal spawning in certain dimensions (even the overworld).&lt;br /&gt;
&lt;br /&gt;
== BlockToolInteractEvent ==&lt;br /&gt;
This event is fired on right click tool events, such as path creation, wood stripping, and farmland tilling. You have access to the player, the &amp;lt;code&amp;gt;ItemStack&amp;lt;/code&amp;gt; they're holding, and the &amp;lt;code&amp;gt;ToolType&amp;lt;/code&amp;gt; they have.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setFinalState()&amp;lt;/code&amp;gt;: Set what you want the result to be.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFinalState()&amp;lt;/code&amp;gt;: Returns what it will be changed to.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onToolInteract(final BlockEvent.BlockToolInteractEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getFinalState().is(Blocks.FARMLAND) &amp;amp;&amp;amp; event.getHeldItemStack().getItem() == Items.NETHERITE_HOE)&lt;br /&gt;
        {&lt;br /&gt;
            event.setFinalState(Blocks.NETHERRACK.defaultBlockState()); // change the final state under certain conditions&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this:&lt;br /&gt;
* Setting your custom farmland block during tilling&lt;br /&gt;
* Adding stripped wood behavior for other blocks&lt;br /&gt;
* Disable path creation&lt;/div&gt;</summary>
		<author><name>EERussianguy</name></author>
	</entry>
	<entry>
		<id>https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2575</id>
		<title>Events/BlockEvent</title>
		<link rel="alternate" type="text/html" href="https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2575"/>
		<updated>2021-04-20T14:07:05Z</updated>

		<summary type="html">&lt;p&gt;EERussianguy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The variations of &amp;lt;code&amp;gt;BlockEvent&amp;lt;/code&amp;gt; let modders intercept interactions between the player and blocks in the world. All of these events have in common the following: the &amp;lt;code&amp;gt;World&amp;lt;/code&amp;gt; the action was taken in, and the &amp;lt;code&amp;gt;BlockPos&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that's being modified.&lt;br /&gt;
&lt;br /&gt;
== BreakEvent ==&lt;br /&gt;
This event is fired before a block is broken by a player. Predictably, cancelling this event prevents the block from getting broken. Modders have two extra variables to play with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getExpToDrop()&amp;lt;/code&amp;gt;: Returns how much experience ought to drop when the block is broken. Will be zero if the event is currently canceled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setExpToDrop()&amp;lt;/code&amp;gt;: Sets the experience that's going to drop manually.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlayer()&amp;lt;/code&amp;gt;: Gets the player that's doing the action.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onBlockBreak(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getState().is(Blocks.SAND)) // use the base event to get the state and see what it is&lt;br /&gt;
        {&lt;br /&gt;
            event.setExpToDrop(10); // change the amount of experience we'll be dropping&lt;br /&gt;
            PlayerEntity player = event.getPlayer();&lt;br /&gt;
            if (player.getUseItem().getItem().is(Items.SHEARS)) // check if the player is holding shears&lt;br /&gt;
            {&lt;br /&gt;
                ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(Items.BONE)); // give a bone to the player!&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Stopping players from breaking a block&lt;br /&gt;
* Changing the XP drop of a vanilla block&lt;br /&gt;
* Modify the behavior of a tool&lt;br /&gt;
&lt;br /&gt;
== EntityPlaceEvent ==&lt;br /&gt;
This event is called when a block is placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt;: This is the entity placing the block. Note that this might not be a player! It can be null. This means you should null check the entity. By default, Forge adds this in three places: players placing blocks, endermen placing their held block, as well as ice placed by the Frost Walker enchantment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getBlockSnapshot()&amp;lt;/code&amp;gt;: Gets the snapshot of what's about to be placed. A &amp;lt;code&amp;gt;BlockSnapshot&amp;lt;/code&amp;gt; is just an object containing the dimension, position, NBT, and state of a block, along with some other info. Typically, this isn't necessary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedBlock()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedAgainst()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that was clicked in order to place the block. Imagine planting a flower on some dirt. The dirt would be the state here.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onEntityPlace(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        Entity entity = event.getEntity();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; entity != null) // check if the entity is null&lt;br /&gt;
        {&lt;br /&gt;
            Block block = event.getState().getBlock(); // get the block that was placed&lt;br /&gt;
            if (entity instanceof PlayerEntity &amp;amp;&amp;amp; block.is(Blocks.FROSTED_ICE))&lt;br /&gt;
            {&lt;br /&gt;
                event.setCanceled(true); // cancel the placing&lt;br /&gt;
                event.getWorld().setBlock(event.getPos(), Blocks.COBBLESTONE.defaultBlockState(), 3); // set cobble instead&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* (See above) Changing how frost walker works based on certain conditions&lt;br /&gt;
* Preventing a block from being placed&lt;br /&gt;
* Changing the player's inventory when a block is placed&lt;br /&gt;
* Cause another block to be placed instead of another&lt;br /&gt;
&lt;br /&gt;
== EntityMultiPlaceEvent ==&lt;br /&gt;
This is the same as above except it's fired when a block causes another block to be replaced. A great example is beds, where placing one half of the bed causes another half to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getReplacedBlockSnapshots()&amp;lt;/code&amp;gt;: Everything is the same as before, except we now have a list of snapshots. How sweet.&lt;br /&gt;
&lt;br /&gt;
== NeighborNotifyEvent ==&lt;br /&gt;
This event is fired when a block tells its neighbors to update themselves. This happens all the time, typically with redstone blocks like tripwires or repeaters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNotifiedSides()&amp;lt;/code&amp;gt;: A set of &amp;lt;code&amp;gt;Direction&amp;lt;/code&amp;gt; values that were updated during the event. Sometimes, blocks will choose to exclude a side from being updated, but most often this will be all six directions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getForceRedstoneUpdate()&amp;lt;/code&amp;gt; This is a little funky. There's an option when blocks are set to force a redstone update. If that happened, this will be true. You typically won't need this.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onNeighborNotify(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockPos eventPos = event.getPos();&lt;br /&gt;
        for (Direction direction : event.getNotifiedSides()) // cycle through notified directions&lt;br /&gt;
        {&lt;br /&gt;
            BlockPos pos = eventPos.relative(direction); // move to the direction given&lt;br /&gt;
            double x = pos.getX() + 0.5D; // move to center of the block&lt;br /&gt;
            double y = pos.getY() + 0.5D;&lt;br /&gt;
            double z = pos.getZ() + 0.5D;&lt;br /&gt;
            // add particle&lt;br /&gt;
            event.getWorld().addParticle(ParticleTypes.CLOUD, x, y, z, 0.0D, 0.0D, 0.0D);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Adding blocks that interact with redstone&lt;br /&gt;
* Making a block update detector block&lt;br /&gt;
&lt;br /&gt;
== CreateFluidSourceEvent ==&lt;br /&gt;
This event controls creation of fluid sources. This is different than cancellable events, because it has a &amp;lt;code&amp;gt;Result&amp;lt;/code&amp;gt;. Setting it to &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; causes a source block to created, even if that's not normally what would happen. Setting it to &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; always prevents source creation.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onNeighborNotify(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getPos().getY() &amp;gt; 100)&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent source creation above y = 100&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== FluidPlaceBlockEvent ==&lt;br /&gt;
This event fires when fluids place blocks. Examples of this happening are: basalt, stone, cobblestone, obsidian, and fire (think lava pools). You can cancel this event to prevent placement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getLiquidPos()&amp;lt;/code&amp;gt; This is the liquid's position. For cases like cobble generation, this is the same as the original &amp;lt;code&amp;gt;getPos()&amp;lt;/code&amp;gt;. But for placing fire, this won't be the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNewState()&amp;lt;/code&amp;gt; Gets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setNewState()&amp;lt;/code&amp;gt; Sets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; What the block was before this event.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onBreak(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockState newState = event.getNewState();&lt;br /&gt;
        if (newState.is(Blocks.FIRE))&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // prevent fire placing from lava&lt;br /&gt;
        }&lt;br /&gt;
        else if (newState.is(Blocks.COBBLESTONE) &amp;amp;&amp;amp; event.getWorld().dayTime() &amp;gt; 14000L)&lt;br /&gt;
        {&lt;br /&gt;
            event.setNewState(Blocks.ANDESITE.defaultBlockState()); // change the block if done during nighttime.&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing behavior of cobble generators&lt;br /&gt;
* Preventing cobble generators&lt;br /&gt;
* Adding more aggressive effects during fire spreading from lava&lt;br /&gt;
&lt;br /&gt;
== CropGrowEvent ==&lt;br /&gt;
These events are fired during crop growth. The &amp;lt;code&amp;gt;Pre&amp;lt;/code&amp;gt; event is fired before. It's fired when vanilla blocks try to  'grow' during random ticks (think cacti getting taller). Setting &amp;lt;code&amp;gt;DEFAULT&amp;lt;/code&amp;gt; as the result will cause no change. Setting &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; forces growth. Setting &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; prevents growth.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Post&amp;lt;/code&amp;gt; event is fired after growth.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; Get the state before growth happened.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onCropGrowPre(final BlockEvent.CropGrowEvent.Pre event)&lt;br /&gt;
    {&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockState state = event.getState();&lt;br /&gt;
        if (state.is(Blocks.WHEAT))&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent wheat from growing&lt;br /&gt;
        }&lt;br /&gt;
        else if (state.is(Blocks.BAMBOO))&lt;br /&gt;
        {&lt;br /&gt;
            if (event.getWorld().getRandom().nextFloat() &amp;gt; 0.2F) // take a 4/5 chance&lt;br /&gt;
            {&lt;br /&gt;
                event.setResult(Event.Result.DENY); // make bamboo grow less often&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing growth rate of crops&lt;br /&gt;
* Preventing crop growth under certain conditions&lt;br /&gt;
* Spawning an entity when something grows&lt;br /&gt;
&lt;br /&gt;
== FarmlandTrampleEvent ==&lt;br /&gt;
This event is fired when farmland gets trampled. You can cancel it to prevent trampling.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt; The entity that trampled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFallDistance()&amp;lt;/code&amp;gt; How far that entity fell&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onTrample(final BlockEvent.FarmlandTrampleEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getFallDistance() &amp;lt; 10.0F)&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // change conditions for trampling&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PortalSpawnEvent ==&lt;br /&gt;
This event is fired when a nether portal is created.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPortalSize()&amp;lt;/code&amp;gt; returns a &amp;lt;code&amp;gt;PortalSize&amp;lt;/code&amp;gt; object, basically only useful for determining if the portal is going to be valid or not.&lt;br /&gt;
&lt;br /&gt;
This is mostly used for preventing portal spawning in certain dimensions (even the overworld).&lt;br /&gt;
&lt;br /&gt;
== BlockToolInteractEvent ==&lt;br /&gt;
This event is fired on right click tool events, such as path creation, wood stripping, and farmland tilling. You have access to the player, the &amp;lt;code&amp;gt;ItemStack&amp;lt;/code&amp;gt; they're holding, and the &amp;lt;code&amp;gt;ToolType&amp;lt;/code&amp;gt; they have.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setFinalState()&amp;lt;/code&amp;gt;: Set what you want the result to be.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFinalState()&amp;lt;/code&amp;gt;: Returns what it will be changed to.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onToolInteract(final BlockEvent.BlockToolInteractEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getFinalState().is(Blocks.FARMLAND) &amp;amp;&amp;amp; event.getHeldItemStack().getItem() == Items.NETHERITE_HOE)&lt;br /&gt;
        {&lt;br /&gt;
            event.setFinalState(Blocks.NETHERRACK.defaultBlockState()); // change the final state under certain conditions&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this:&lt;br /&gt;
* Setting your custom farmland block during tilling&lt;br /&gt;
* Adding stripped wood behavior for other blocks&lt;br /&gt;
* Disable path creation&lt;/div&gt;</summary>
		<author><name>EERussianguy</name></author>
	</entry>
	<entry>
		<id>https://forge.gemwire.uk/index.php?title=Events&amp;diff=2574</id>
		<title>Events</title>
		<link rel="alternate" type="text/html" href="https://forge.gemwire.uk/index.php?title=Events&amp;diff=2574"/>
		<updated>2021-04-20T13:44:24Z</updated>

		<summary type="html">&lt;p&gt;EERussianguy: revert link addition cause i can't figure it out&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Under construction}}&lt;br /&gt;
&lt;br /&gt;
An '''event''' is a signal that is fired on an '''event bus''' to inform registered listeners about some type of action or state. This is the primary way by which Forge allows mods to hook into vanilla and game behavior; Forge has an array of different events which are fired when different actions happen within the game, and mods may act upon receiving these events.  &lt;br /&gt;
&lt;br /&gt;
Additionally, mods may create their own events and fire them for other mods to listen for, allowing for higher compatibility. For a class to be considered an event, it must be a subclass of &amp;lt;code&amp;gt;Event&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Generic Events ==&lt;br /&gt;
'''Generic events''' are events which supply additional generic type information, allowing event listeners to filter based on that secondary type. Generic events must implement &amp;lt;code&amp;gt;IGenericEvent&amp;lt;T&amp;gt;&amp;lt;/code&amp;gt;, and return their generic type from the &amp;lt;code&amp;gt;IGenericEvent#getType()&amp;lt;/code&amp;gt; method. As a convenience, events that wish to be generic events may extend the &amp;lt;code&amp;gt;GenericEvent&amp;lt;T&amp;gt;&amp;lt;/code&amp;gt; instead of manually implementing the interface.&lt;br /&gt;
&lt;br /&gt;
For generic events, the generic type must be an exact match with the listener's generic type filter to pass; if an &amp;lt;code&amp;gt;AttachCapabilitiesEvent&amp;lt;ItemStack&amp;gt;&amp;lt;/code&amp;gt; is fired and a listener is listening for &amp;lt;code&amp;gt;AttachCapabilitiesEvent&amp;lt;Object&amp;gt;&amp;lt;/code&amp;gt;, the listener does not receive the event. A event listener may listen to events with any generic type by supplying a wildcard generic (&amp;lt;code&amp;gt;&amp;lt;?&amp;gt;&amp;lt;/code&amp;gt;). Nested generic types are ignored.&lt;br /&gt;
&lt;br /&gt;
== Cancellable Events ==&lt;br /&gt;
An event may be marked as '''cancellable''', which allows event listeners to cancel the event.&lt;br /&gt;
&lt;br /&gt;
A cancellable event may be cancelled by using &amp;lt;code&amp;gt;Event#setCanceled(true)&amp;lt;/code&amp;gt;. Attempting to call this method on a non-cancellable event will result in a &amp;lt;code&amp;gt;UnsupportedOperationException&amp;lt;/code&amp;gt;. A cancelled event behaves similarly to a regular noncancelled event, with one main difference: an event listener will not receive cancelled events unless they are explicitly registered to listen for cancelled events.&lt;br /&gt;
&lt;br /&gt;
To mark an event as cancellable, the event class should be annotated with &amp;lt;code&amp;gt;@Cancelable&amp;lt;/code&amp;gt;. This will automatically make &amp;lt;code&amp;gt;Event#isCancelable()&amp;lt;/code&amp;gt; return &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;. Modders may check if an event has a result through the presence of the annotation or by calling the given method.&lt;br /&gt;
&lt;br /&gt;
== Events with Results ==&lt;br /&gt;
An event may have a '''result''', which is an enum of &amp;lt;code&amp;gt;Event.Result&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Event.Result&amp;lt;/code&amp;gt; enum has three values: &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DEFAULT&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt;. The meaning of these result values is entirely dependent on the event itself.&lt;br /&gt;
 &lt;br /&gt;
An event's current result can be retrieved through &amp;lt;code&amp;gt;Event#getResult()&amp;lt;/code&amp;gt;. The result on an event can be set through &amp;lt;code&amp;gt;Event#setResult(Event.Result)&amp;lt;/code&amp;gt;. You can set the result for an event which is not marked as having a result, however this will cause nothing to happen if the event does not use the result value.&lt;br /&gt;
&lt;br /&gt;
To mark an event as having a result, the event class should be annotated with &amp;lt;code&amp;gt;@Event.HasResult&amp;lt;/code&amp;gt;. This will automatically make &amp;lt;code&amp;gt;Event#hasResult&amp;lt;/code&amp;gt; return &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;. Modders may check if an event has a result through the presence of the annotation or by calling the given method.&lt;br /&gt;
&lt;br /&gt;
== Event Bus ==&lt;br /&gt;
An '''event bus''' is an object which holds a list of event listeners, and the logic for firing the events. Events may be posted on these event buses, which then invokes the handlers. The main class for event buses is &amp;lt;code&amp;gt;IEventBus&amp;lt;/code&amp;gt;, and a bus is created using &amp;lt;code&amp;gt;BusBuilder&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Existing Buses ===&lt;br /&gt;
Forge exposes three main families of event buses: the main Forge event bus, the mod-specific event buses, and the network channel event buses.&lt;br /&gt;
&lt;br /&gt;
==== Main Forge Event Bus ====&lt;br /&gt;
The '''main Forge event bus''' is located at &amp;lt;code&amp;gt;MinecraftForge#EVENT_BUS&amp;lt;/code&amp;gt;, and is where most events relating to ingame actions or events are fired on, such as events for ticking, block interactions, and entity interactions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot; style=&amp;quot;border: 2px solid; border-radius: 2px; padding: 5px; margin: 1em; overflow:auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;font-weight:bold; line-height:1.6;&amp;quot;&amp;gt;List of events fired on the main Forge event bus&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
{{:Events/Forge bus}}&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Mod-Specific Event Buses ====&lt;br /&gt;
The '''mod-specific event buses''' are the family of event buses where mod-related initialization and registration events are fired, such as the events for [[Registration|registering objects]] or setup on different physical sides. Only events which implement &amp;lt;code&amp;gt;IModBusEvent&amp;lt;/code&amp;gt; may be fired or listened for on these event buses.&lt;br /&gt;
&lt;br /&gt;
Each loaded mod has their own instance of a mod-specific event bus. The mod-specific event bus for the currently loading mod can be retrieved from &amp;lt;code&amp;gt;FMLModContainer#getEventBus()&amp;lt;/code&amp;gt;, which is also accessible from &amp;lt;code&amp;gt;FMLJavaModLoadingContext#getModEventBus()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Tip|title=Tip|The mod-specific event buses are provided by the &amp;lt;code&amp;gt;javafml&amp;lt;/code&amp;gt; language provider which is builtin to Forge Mod Loader. Custom language providers may provide other ways for mods to receive the different mod-related initialization and registration events; see the documentation of your custom language provider for details.}}&lt;br /&gt;
&lt;br /&gt;
==== Network Channel Event Buses ====&lt;br /&gt;
The '''network channel event buses''' are the family of event buses where different network-related events are fired. Each registered [[Networking|networking channel]] has their own instance of an event-bus in &amp;lt;code&amp;gt;NetworkInstance&amp;lt;/code&amp;gt;, where only events pertinent to that channel are fired on.&lt;br /&gt;
&lt;br /&gt;
The network channel event buses cannot be accessed directly; &amp;lt;code&amp;gt;EventNetworkChannel&amp;lt;/code&amp;gt; provides methods to register events listeners to the event bus.&lt;br /&gt;
&lt;br /&gt;
== Event Listeners ==&lt;br /&gt;
An '''event listener''' (also known as an '''event handler''') is a class, object, or method registered to an event bus to capture for specific events (and their subclasses).&lt;br /&gt;
&lt;br /&gt;
[[File:Guide to Event Handlers.png|thumb|upright 0.9|A visual guide on how event listeners are registered.]]&lt;br /&gt;
&lt;br /&gt;
An event listener may be registered in three ways:&lt;br /&gt;
* The &amp;lt;code&amp;gt;IEventBus#register(Object)&amp;lt;/code&amp;gt; method on a class or instance;&lt;br /&gt;
* The &amp;lt;code&amp;gt;@EventBusSubscriber&amp;lt;/code&amp;gt; annotation on a class; or&lt;br /&gt;
* The &amp;lt;code&amp;gt;IEventBus#addListener&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;IEventBus#addGenericListener&amp;lt;/code&amp;gt; on a method reference or lambda.&lt;br /&gt;
&lt;br /&gt;
=== Priority and Receiving Cancelled Events ===&lt;br /&gt;
An event listener may be registered to a specific '''event priority''' and whether to '''receive cancelled events'''.&lt;br /&gt;
&lt;br /&gt;
The event priority levels allows a listener to react to an event before other event listeners of a lower level, such as to change the values within an event or cancel it outright.&lt;br /&gt;
&lt;br /&gt;
There are five levels of event listeners priority; in descending order from first to receive an event to last: &amp;lt;code&amp;gt;HIGHEST&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;HIGH&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;NORMAL&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LOW&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;LOWEST&amp;lt;/code&amp;gt;. Event listeners are registered by default on a priority of &amp;lt;code&amp;gt;NORMAL&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
An event listener normally never receives a cancelled event, however they may change this by being registered to receive these cancelled events. Non-cancellable events are unaffected by this, and will always be sent to all event listeners (in the order specified by their priority).&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;IEventBus.register&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
The &amp;lt;code&amp;gt;IEventBus#register(Object)&amp;lt;/code&amp;gt; method allows for registering an object instance or a &amp;lt;code&amp;gt;Class&amp;lt;?&amp;gt;&amp;lt;/code&amp;gt; to the event bus. The method exhibits two different behaviors, depending on what is passed into it:&lt;br /&gt;
&lt;br /&gt;
* '''an object instance''' - registers all ''instance or non-&amp;lt;code&amp;gt;static&amp;lt;/code&amp;gt;'' methods annotated with &amp;lt;code&amp;gt;@SubscribeEvent&amp;lt;/code&amp;gt; from the object&lt;br /&gt;
* '''a &amp;lt;code&amp;gt;Class&amp;lt;?&amp;gt;&amp;lt;/code&amp;gt; instance''' - registers all ''class or &amp;lt;code&amp;gt;static&amp;lt;/code&amp;gt;'' methods annotated with &amp;lt;code&amp;gt;@SubscribeEvent&amp;lt;/code&amp;gt; from the class which is represented by the passed in &amp;lt;code&amp;gt;Class&amp;lt;?&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab collapsed name=&amp;quot;Example of how event listeners are registered with the IEventBus.register method&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
class EventHandler {&lt;br /&gt;
	public static void nonAnnotatedStatic(Event event) {}&lt;br /&gt;
&lt;br /&gt;
	@SubscribeEvent&lt;br /&gt;
	public static void annotatedStatic(Event event) {}&lt;br /&gt;
&lt;br /&gt;
	public void nonAnnotatedInstance(Event event) {}&lt;br /&gt;
&lt;br /&gt;
	@SubscribeEvent&lt;br /&gt;
	public void annotatedInstance(Event event) {}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Within the execution of the program&lt;br /&gt;
IEventBus bus = ...;&lt;br /&gt;
&lt;br /&gt;
// This will register the &amp;quot;annotatedStatic&amp;quot; method from the class&lt;br /&gt;
bus.register(EventHandler.class);&lt;br /&gt;
// This would register &amp;quot;annotatedStatic&amp;quot;, but it is already registered&lt;br /&gt;
bus.register(EventHandler.class);&lt;br /&gt;
&lt;br /&gt;
EventHandler instanceA = new EventHandler();&lt;br /&gt;
EventHandler instanceB = new EventHandler();&lt;br /&gt;
&lt;br /&gt;
// This will register the &amp;quot;annotatedInstance&amp;quot; method from the instanceA object, and will not touch the instanceB object&lt;br /&gt;
bus.register(instanceA);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
If an &amp;lt;code&amp;gt;Event&amp;lt;/code&amp;gt; were to be fired on the event bus in the example above, the &amp;lt;code&amp;gt;EventHandler#annotatedStatic&amp;lt;/code&amp;gt; would receive the event, and the &amp;lt;code&amp;gt;annotatedInstance&amp;lt;/code&amp;gt; method from the &amp;lt;code&amp;gt;instanceA&amp;lt;/code&amp;gt; object instance would receive the event.&lt;br /&gt;
&lt;br /&gt;
Neither the unnannotated methods will receive the event, nor will the &amp;lt;code&amp;gt;annotatedInstance&amp;lt;/code&amp;gt; method from the &amp;lt;code&amp;gt;instanceB&amp;lt;/code&amp;gt; object instance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;tt&amp;gt;@SubscribeEvent&amp;lt;/tt&amp;gt; ====&lt;br /&gt;
The &amp;lt;code&amp;gt;@SubscribeEvent&amp;lt;/code&amp;gt; annotation is used to mark a method as an event listener when its containing class or object is registered using &amp;lt;code&amp;gt;IEventBus#register&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
They have two fields: &amp;lt;code&amp;gt;EventPriority priority&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;boolean receiveCancelled&amp;lt;/code&amp;gt;, which sets the event priority for the listener and whether the listener receives cancelled events, respectively.&lt;br /&gt;
&lt;br /&gt;
= WIP =&lt;br /&gt;
TODO: @EventBusSubscriber, addListener, Generic Events? (probably higher up)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Partial previous content of page, to be removed&amp;quot; collapsed&amp;gt;&lt;br /&gt;
== Forge and Mod Buses ==&lt;br /&gt;
There are two event buses of note to a mod: the '''main Forge event bus''', and the '''mod-specific event bus'''.&lt;br /&gt;
&lt;br /&gt;
The Forge event bus, which can be referenced through &amp;lt;code&amp;gt;MinecraftForge.EVENT_BUS&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;EventBusSubscriber.Bus.FORGE&amp;lt;/code&amp;gt; (the latter being an enum that provides handy references to both busses), fires events that depend solely on the game state. This means that:&lt;br /&gt;
* Entity Events&lt;br /&gt;
* Ticking Events&lt;br /&gt;
* Server Events&lt;br /&gt;
and more, are fired on the Forge bus.&lt;br /&gt;
&lt;br /&gt;
The Mod bus, referenced through &amp;lt;code&amp;gt;FMLJavaModLoadingContext.get().getModEventBus()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;EventBusSubscriber.Bus.MOD&amp;lt;/code&amp;gt;, fires events that depend solely on mod state, or which are used to initialise such.&lt;br /&gt;
This means that:&lt;br /&gt;
* Registration Events&lt;br /&gt;
* Mod Lifecycle Events&lt;br /&gt;
* Model Events (bake and register)&lt;br /&gt;
* Config Events&lt;br /&gt;
* Data Provider Events&lt;br /&gt;
and more, are fired on the Mod bus. See [[Stages of Modloading|mod loading events]]. Note that some of these are fired in parallel.&lt;br /&gt;
&lt;br /&gt;
== Sub Events ==&lt;br /&gt;
&lt;br /&gt;
Many events have different variations of themselves, these can be different but all based around one common factor (e.g. &amp;lt;code&amp;gt;PlayerEvent&amp;lt;/code&amp;gt;) or can be an event that has multiple phases (e.g. &amp;lt;code&amp;gt;PotionBrewEvent&amp;lt;/code&amp;gt;). Take note that if you listen to the parent event class, you will receive calls to your method for ''all'' subclasses.&lt;br /&gt;
&lt;br /&gt;
== Event Handlers ==&lt;br /&gt;
Event handlers are methods, which have four main properties. They are communicated to the event bus you want them to listen on, and when the event is posted on that bus, the hander is invoked.&lt;br /&gt;
&lt;br /&gt;
Event handlers' properties are as such:&lt;br /&gt;
- Registered to an event bus&lt;br /&gt;
- May be static or instance&lt;br /&gt;
- Have a single argument, which is used to determine the event that is being listened for&lt;br /&gt;
- The argument given is the instance of the Event being posted.&lt;br /&gt;
&lt;br /&gt;
Note that handlers may take the form of anonymous functions - lambdas.&lt;br /&gt;
&lt;br /&gt;
== Registering Event Handlers ==&lt;br /&gt;
Event handlers are registered typically one of four ways:&lt;br /&gt;
* &amp;lt;code&amp;gt;EventBusSubscriber&amp;lt;/code&amp;gt; (which requires a static, annotated handler method)&lt;br /&gt;
* &amp;lt;code&amp;gt;EventBus#register(T.class)&amp;lt;/code&amp;gt; (which requires a static, annotated handler method)&lt;br /&gt;
* &amp;lt;code&amp;gt;EventBus#register(new X())&amp;lt;/code&amp;gt; (which requires an instance, annotated handler method)&lt;br /&gt;
* &amp;lt;code&amp;gt;EventBus#addListener(Class::function)&amp;lt;/code&amp;gt; (which requires an instance, non-annotated handler method)&lt;br /&gt;
* as an extension of the above: &amp;lt;code&amp;gt;EventBus#&amp;lt;LivingHurtEvent&amp;gt;addListener(event -&amp;gt; { code })&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each of these will be explained in detail as follows.&lt;br /&gt;
&lt;br /&gt;
=== Annotated Event Handlers ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class MyForgeEventHandler {&lt;br /&gt;
    @SubscribeEvent&lt;br /&gt;
    public void pickupItem(EntityItemPickupEvent event) {&lt;br /&gt;
        System.out.println(&amp;quot;Item picked up!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This event handler listens for the &amp;lt;code&amp;gt;EntityItemPickupEvent&amp;lt;/code&amp;gt;, which is, as the name states, posted to the event bus whenever an &amp;lt;code&amp;gt;Entity&amp;lt;/code&amp;gt; picks up an item.&lt;br /&gt;
&lt;br /&gt;
This function would be registered with &amp;lt;code&amp;gt;EventBus#register(new X())&amp;lt;/code&amp;gt; in the above examples.&lt;br /&gt;
&lt;br /&gt;
=== Static Event Handlers ===&lt;br /&gt;
&lt;br /&gt;
An event handler may also be static. The handling method is still annotated with &amp;lt;code&amp;gt;@SubscribeEvent&amp;lt;/code&amp;gt; with the only difference from an instance handler is that it is also marked static. In order to register a static event handler, an instance of the class won’t do, the Class itself has to be passed in. An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class MyStaticForgeEventHandler {&lt;br /&gt;
    @SubscribeEvent&lt;br /&gt;
    public static void arrowNocked(ArrowNockEvent event) {&lt;br /&gt;
        System.out.println(&amp;quot;Arrow nocked!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which must be registered &amp;lt;code&amp;gt;EventBus#register(MyStaticForgeEventHandler.class)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3 id=&amp;quot;eventbussubscriber&amp;quot;&amp;gt;Using &amp;lt;tt style=&amp;quot;font-size: 100%&amp;quot;&amp;gt;@Mod.EventBusSubscriber&amp;lt;/tt&amp;gt;&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A class may be annotated with the &amp;lt;code&amp;gt;@Mod.EventBusSubscriber&amp;lt;/code&amp;gt; annotation. Such a class is automatically registered to the configured bus when the &amp;lt;code&amp;gt;@Mod&amp;lt;/code&amp;gt; class itself is constructed. This is essentially equivalent to adding &amp;lt;code&amp;gt;EventBus#register(AnnotatedClass.class);&amp;lt;/code&amp;gt; at the end of the &amp;lt;code&amp;gt;@Mod&amp;lt;/code&amp;gt; class's constructor.&lt;br /&gt;
&lt;br /&gt;
The mod ID must be specified unless your class is already annotated with an &amp;lt;code&amp;gt;@Mod&amp;lt;/code&amp;gt; annotation. You can pass the bus you want to listen to inside the &amp;lt;code&amp;gt;@Mod.EventBusSubscriber&amp;lt;/code&amp;gt; annotation.&lt;br /&gt;
&lt;br /&gt;
The bus registered with &amp;lt;code&amp;gt;EventBusSubscriber&amp;lt;/code&amp;gt; defaults to the Forge event bus.&lt;br /&gt;
&lt;br /&gt;
You can also specify the &amp;lt;code&amp;gt;Dist&amp;lt;/code&amp;gt;s to load this event subscriber on. This can be used to not load client specific event subscribers on the dedicated server.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example for a static event listener listening to &amp;lt;code&amp;gt;RenderWorldLastEvent&amp;lt;/code&amp;gt; which will only be called on the physical client: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
@Mod.EventBusSubscriber(modid = &amp;quot;examplemod&amp;quot;, dist = Dist.CLIENT)&lt;br /&gt;
public class MyStaticClientOnlyEventHandler {&lt;br /&gt;
    @SubscribeEvent&lt;br /&gt;
    public static void drawLast(RenderWorldLastEvent event) {&lt;br /&gt;
        System.out.println(&amp;quot;Drawing!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Tip/Important|This does not register an instance of the class; it registers the class itself (i.e. the event handling methods must be static).}}&lt;br /&gt;
&lt;br /&gt;
=== Non-Annotated Event Handlers ===&lt;br /&gt;
&lt;br /&gt;
Event handlers do not need to be annotated if they are directly referred to using &amp;lt;code&amp;gt;EventBus#addListener&amp;lt;/code&amp;gt; (or &amp;lt;code&amp;gt;EventBus#addGenericListener&amp;lt;/code&amp;gt; for generic events).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
@Mod(&amp;quot;examplemod&amp;quot;)&lt;br /&gt;
public class MyMainModClass {&lt;br /&gt;
&lt;br /&gt;
  public MyMainModClass() {&lt;br /&gt;
    FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(Entity.class, this::entityCap);&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  private void entityCap(AttachCapabilitiesEvent&amp;lt;Entity&amp;gt; event) {&lt;br /&gt;
    System.out.println(&amp;quot;Capability attached!&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Tip/Important|The generic passed into the event must be referenced directly within the code itself. Otherwise, the event will not be called whatsoever. For example, if you use &amp;lt;code&amp;gt;AttachCapabilitiesEvent&amp;lt;LivingEntity&amp;gt;&amp;lt;/code&amp;gt;, the event will never be called as no call of this event uses &amp;lt;code&amp;gt;LivingEntity&amp;lt;/code&amp;gt;, only &amp;lt;code&amp;gt;Entity&amp;lt;/code&amp;gt;.}}&lt;br /&gt;
&lt;br /&gt;
== Cancelling ==&lt;br /&gt;
&lt;br /&gt;
If an event can be cancelled, it will be marked with the &amp;lt;code&amp;gt;@Cancelable&amp;lt;/code&amp;gt; annotation, and the method &amp;lt;code&amp;gt;Event#isCancelable()&amp;lt;/code&amp;gt; will return &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;. The cancel state of a cancellable event may be modified by calling &amp;lt;code&amp;gt;Event#setCanceled(boolean canceled)&amp;lt;/code&amp;gt;, wherein passing the boolean value &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; is interpreted as cancelling the event, and passing the boolean value &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; is interpreted as “un-cancelling” the event.&lt;br /&gt;
&lt;br /&gt;
{{Tip/Important|Not all events can be cancelled! Attempting to cancel an event that is not cancellable will result in an unchecked &amp;lt;code&amp;gt;UnsupportedOperationException&amp;lt;/code&amp;gt; being thrown, which is expected to result in the game crashing. Always check that an event can be cancelled using &amp;lt;code&amp;gt;Event#isCancelable()&amp;lt;/code&amp;gt; before attempting to cancel it.}}&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
Some events have an &amp;lt;code&amp;gt;Event.Result&amp;lt;/code&amp;gt; as denoted by &amp;lt;code&amp;gt;@HasResult&amp;lt;/code&amp;gt;. A result can be one of three things: &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; which stops the event, &amp;lt;code&amp;gt;DEFAULT&amp;lt;/code&amp;gt; which uses the Vanilla behavior, and &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; which forces the action to take place, regardless of if it would have originally. The result of an event can be set by calling &amp;lt;code&amp;gt;setResult&amp;lt;/code&amp;gt; with an Event.Result on the event.&lt;br /&gt;
&lt;br /&gt;
{{Colored box|title=Information|content=Different events may use results in different ways, refer to the event's JavaDoc before using the result.}}&lt;br /&gt;
&lt;br /&gt;
== Priority ==&lt;br /&gt;
&lt;br /&gt;
Event handler methods have a priority. You can set the &amp;lt;code&amp;gt;priority&amp;lt;/code&amp;gt; of an event handler method by setting the priority value of the annotation or the listener. The priority can be any value of the &amp;lt;code&amp;gt;EventPriority&amp;lt;/code&amp;gt; enum (&amp;lt;code&amp;gt;HIGHEST&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;HIGH&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;NORMAL&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LOW&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;LOWEST&amp;lt;/code&amp;gt;). Event handlers with priority &amp;lt;code&amp;gt;HIGHEST&amp;lt;/code&amp;gt; are executed first and from there in descending order until &amp;lt;code&amp;gt;LOWEST&amp;lt;/code&amp;gt; events which are executed last.&lt;br /&gt;
&lt;br /&gt;
== Mod Event Bus ==&lt;br /&gt;
The mod event bus is primarily used for listening to lifecycle events in which mods should initialize. Many of these events are also ran in parallel so mods can be initialized at the same time. This does mean you cannot directly execute code from other mods in these events. Use the &amp;lt;code&amp;gt;InterModComms&amp;lt;/code&amp;gt; system for that.&lt;br /&gt;
&lt;br /&gt;
It is impossible for an event to be posted on the Mod bus that does not inherit the IModBusEvent interface.&lt;br /&gt;
Thus, this provides a good, easy way to tell which events are fired on this bus.&lt;br /&gt;
&lt;br /&gt;
These are the four most commonly used lifecycle events that are called during mod initialization on the mod event bus: &lt;br /&gt;
* &amp;lt;code&amp;gt;FMLCommonSetupEvent&amp;lt;/code&amp;gt; &lt;br /&gt;
* &amp;lt;code&amp;gt;FMLClientSetupEvent&amp;lt;/code&amp;gt; &amp;amp; &amp;lt;code&amp;gt;FMLDedicatedServerSetupEvent&amp;lt;/code&amp;gt; (''These events are only called on their respective [[Sides#Different_Kinds_of_Sides|physical side]].'')&lt;br /&gt;
* &amp;lt;code&amp;gt;InterModEnqueueEvent&amp;lt;/code&amp;gt; &lt;br /&gt;
* &amp;lt;code&amp;gt;InterModProcessEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These four lifecycle events are all ran in parallel. If you want to run code on the main thread during these events you can use the &amp;lt;code&amp;gt;enqueueWork&amp;lt;/code&amp;gt; methods within the events to do so.&lt;br /&gt;
&lt;br /&gt;
Next to the lifecycle events there are a few miscellaneous events that are fired on the mod event bus where you can register, set up, or initialize various things. Most of these events are not ran in parallel in contrast to the lifecycle events:&lt;br /&gt;
* &amp;lt;code&amp;gt;ColorHandlerEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;ModelBakeEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;TextureStitchEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;RegistryEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GatherDataEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;SoundLoadEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;ParticleFactoryRegisterEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;ModConfigEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A good rule of thumb: events are fired on the mod event bus when they should be handled during initialization of a mod. or where they are used to set state (eg. the config event.)&lt;br /&gt;
&lt;br /&gt;
Detailed information about these events will be found in their respective pages, once they are ready.&lt;br /&gt;
&lt;br /&gt;
== Forge Event Bus ==&lt;br /&gt;
The Forge event bus is where game state events are fired. If anything changes to do with the game, or anything happens that you would need to know about, there's a good chance it's sent here.&lt;br /&gt;
&lt;br /&gt;
A full list of the events fired here is as follows, split into discrete categories:&lt;br /&gt;
&lt;br /&gt;
{{Tree list}}&lt;br /&gt;
* &amp;lt;code&amp;gt;Event&amp;lt;/code&amp;gt; - ''The root event class''&lt;br /&gt;
** '''Rendering events''' ('''client-only''')&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderWorldLastEvent&amp;lt;/code&amp;gt; - Fired after world rendering to allow mods to add custom renders&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderHandEvent&amp;lt;/code&amp;gt; - Fired before and after the hand of the player is rendered in the first person POV&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderLivingEvent&amp;lt;/code&amp;gt; - Fired before and after a &amp;lt;code&amp;gt;LivingRenderer&amp;lt;/code&amp;gt; is executed&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderItemInFrameEvent&amp;lt;/code&amp;gt; - Fired before the item in an &amp;lt;code&amp;gt;ItemFrameEntity&amp;lt;/code&amp;gt; is rendered&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderBlockOverlayEvent&amp;lt;/code&amp;gt; - Fired before the block overlay for the player's screen is rendered&lt;br /&gt;
*** &amp;lt;code&amp;gt;DrawHighlightEvent&amp;lt;/code&amp;gt; - Fired before the block highlight outline is rendered&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderTooltipEvent&amp;lt;/code&amp;gt; - Fired before and during rendering of a text tooltip on a screen&lt;br /&gt;
*** &amp;lt;code&amp;gt;EntityViewRenderEvent&amp;lt;/code&amp;gt; - Superclass for events relating to the player's viewpoint&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderGameOverlayEvent&amp;lt;/code&amp;gt; - Superclass, fired for each element on the player's HUD or game overlay&lt;br /&gt;
*** &amp;lt;code&amp;gt;FOVUpdateEvent&amp;lt;/code&amp;gt; - Fired when the FOV of the player is requested (?)&lt;br /&gt;
** '''GUI/Screen events''' ('''client-only''')&lt;br /&gt;
*** &amp;lt;code&amp;gt;GuiScreenEvent&amp;lt;/code&amp;gt; - Superclass for events relating to &amp;lt;code&amp;gt;Screen&amp;lt;/code&amp;gt;s&lt;br /&gt;
*** &amp;lt;code&amp;gt;GuiContainerEvent&amp;lt;/code&amp;gt; - Superclsas for events relating to &amp;lt;code&amp;gt;ContainerScreen&amp;lt;/code&amp;gt;s&lt;br /&gt;
*** &amp;lt;code&amp;gt;GuiOpenEvent&amp;lt;/code&amp;gt; - Fired before a new screen is opened on the game window&lt;br /&gt;
** '''Superclass events''' - ''These events exist to be superclasses of other events''&lt;br /&gt;
*** &amp;lt;code&amp;gt;GenericEvent&amp;lt;/code&amp;gt; - ''from EventBus'', superclass of events which have a generic type&lt;br /&gt;
*** &amp;lt;code&amp;gt;BlockEvent&amp;lt;/code&amp;gt; - Superclass for events relating to a block within the world&lt;br /&gt;
*** &amp;lt;code&amp;gt;WorldEvent&amp;lt;/code&amp;gt; - Superclass for events relating to the world&lt;br /&gt;
*** &amp;lt;code&amp;gt;InputEvent&amp;lt;/code&amp;gt; - ('''client-only''') Superclass for events relating to the player's keyboard and mouse inputs&lt;br /&gt;
*** &amp;lt;code&amp;gt;NetworkEvent&amp;lt;/code&amp;gt; - Superclass for events relating to networking&lt;br /&gt;
*** &amp;lt;code&amp;gt;ExplosionEvent&amp;lt;/code&amp;gt; - Fired before an explosion explodes in the world&lt;br /&gt;
*** &amp;lt;code&amp;gt;SoundEvent&amp;lt;/code&amp;gt; - ('''client-only''') Superclass for events related to sounds&lt;br /&gt;
*** &amp;lt;code&amp;gt;EntityEvent&amp;lt;/code&amp;gt; - Superclass for events relating to entities&lt;br /&gt;
*** &amp;lt;code&amp;gt;TickEvent&amp;lt;/code&amp;gt; - Superclass for events fired before and after ticking&lt;br /&gt;
** '''Chat events'''&lt;br /&gt;
*** &amp;lt;code&amp;gt;ServerChatEvent&amp;lt;/code&amp;gt; ('''server-only''') - Fired when the server receives a chat message and before it relays the message&lt;br /&gt;
*** &amp;lt;code&amp;gt;ClientChatEvent&amp;lt;/code&amp;gt; ('''client-only''') - Fired before the client is about to send a chat message&lt;br /&gt;
*** &amp;lt;code&amp;gt;ClientChatReceivedEvent&amp;lt;/code&amp;gt; ('''client-only''') - Fired when the client receives a chat message from the server&lt;br /&gt;
** '''Data loading events'''&lt;br /&gt;
*** &amp;lt;code&amp;gt;RecipesUpdatedEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;BiomeLoadingEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;LootTableLoadEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;StructureSpawnListGatherEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
** '''Startup events'''&lt;br /&gt;
*** &amp;lt;code&amp;gt;AddReloadListenerEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;RegisterCommandsEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ServerLifecycleEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
** '''Gamemode events'''&lt;br /&gt;
*** &amp;lt;code&amp;gt;DifficultyChangeEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ClientPlayerChangeGamemodeEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
**'''Trade events'''&lt;br /&gt;
*** &amp;lt;code&amp;gt;WandererTradesEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;VillagerTradesEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
** '''Other events'''&lt;br /&gt;
*** &amp;lt;code&amp;gt;FurnaceFuelBurnTimeEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;BabyEntitySpawnEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;VillageSiegeEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;TagsUpdatedEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;PotionBrewEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ScreenshotEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;EnchantmentLevelSetEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;CommandEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;AnvilUpdateEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ItemAttributeModifierEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ClientPlayerNetworkEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ChunkWatchEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
{{Tree list/end}}&lt;br /&gt;
&lt;br /&gt;
Like before, each of these events (especially the Super Events, which contain most of the useful events in the game) will have their own article explaining their purpose and usefulness.&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;/div&gt;</summary>
		<author><name>EERussianguy</name></author>
	</entry>
	<entry>
		<id>https://forge.gemwire.uk/index.php?title=Events&amp;diff=2573</id>
		<title>Events</title>
		<link rel="alternate" type="text/html" href="https://forge.gemwire.uk/index.php?title=Events&amp;diff=2573"/>
		<updated>2021-04-20T13:43:29Z</updated>

		<summary type="html">&lt;p&gt;EERussianguy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Under construction}}&lt;br /&gt;
&lt;br /&gt;
An '''event''' is a signal that is fired on an '''event bus''' to inform registered listeners about some type of action or state. This is the primary way by which Forge allows mods to hook into vanilla and game behavior; Forge has an array of different events which are fired when different actions happen within the game, and mods may act upon receiving these events.  &lt;br /&gt;
&lt;br /&gt;
Additionally, mods may create their own events and fire them for other mods to listen for, allowing for higher compatibility. For a class to be considered an event, it must be a subclass of &amp;lt;code&amp;gt;Event&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Generic Events ==&lt;br /&gt;
'''Generic events''' are events which supply additional generic type information, allowing event listeners to filter based on that secondary type. Generic events must implement &amp;lt;code&amp;gt;IGenericEvent&amp;lt;T&amp;gt;&amp;lt;/code&amp;gt;, and return their generic type from the &amp;lt;code&amp;gt;IGenericEvent#getType()&amp;lt;/code&amp;gt; method. As a convenience, events that wish to be generic events may extend the &amp;lt;code&amp;gt;GenericEvent&amp;lt;T&amp;gt;&amp;lt;/code&amp;gt; instead of manually implementing the interface.&lt;br /&gt;
&lt;br /&gt;
For generic events, the generic type must be an exact match with the listener's generic type filter to pass; if an &amp;lt;code&amp;gt;AttachCapabilitiesEvent&amp;lt;ItemStack&amp;gt;&amp;lt;/code&amp;gt; is fired and a listener is listening for &amp;lt;code&amp;gt;AttachCapabilitiesEvent&amp;lt;Object&amp;gt;&amp;lt;/code&amp;gt;, the listener does not receive the event. A event listener may listen to events with any generic type by supplying a wildcard generic (&amp;lt;code&amp;gt;&amp;lt;?&amp;gt;&amp;lt;/code&amp;gt;). Nested generic types are ignored.&lt;br /&gt;
&lt;br /&gt;
== Cancellable Events ==&lt;br /&gt;
An event may be marked as '''cancellable''', which allows event listeners to cancel the event.&lt;br /&gt;
&lt;br /&gt;
A cancellable event may be cancelled by using &amp;lt;code&amp;gt;Event#setCanceled(true)&amp;lt;/code&amp;gt;. Attempting to call this method on a non-cancellable event will result in a &amp;lt;code&amp;gt;UnsupportedOperationException&amp;lt;/code&amp;gt;. A cancelled event behaves similarly to a regular noncancelled event, with one main difference: an event listener will not receive cancelled events unless they are explicitly registered to listen for cancelled events.&lt;br /&gt;
&lt;br /&gt;
To mark an event as cancellable, the event class should be annotated with &amp;lt;code&amp;gt;@Cancelable&amp;lt;/code&amp;gt;. This will automatically make &amp;lt;code&amp;gt;Event#isCancelable()&amp;lt;/code&amp;gt; return &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;. Modders may check if an event has a result through the presence of the annotation or by calling the given method.&lt;br /&gt;
&lt;br /&gt;
== Events with Results ==&lt;br /&gt;
An event may have a '''result''', which is an enum of &amp;lt;code&amp;gt;Event.Result&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Event.Result&amp;lt;/code&amp;gt; enum has three values: &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DEFAULT&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt;. The meaning of these result values is entirely dependent on the event itself.&lt;br /&gt;
 &lt;br /&gt;
An event's current result can be retrieved through &amp;lt;code&amp;gt;Event#getResult()&amp;lt;/code&amp;gt;. The result on an event can be set through &amp;lt;code&amp;gt;Event#setResult(Event.Result)&amp;lt;/code&amp;gt;. You can set the result for an event which is not marked as having a result, however this will cause nothing to happen if the event does not use the result value.&lt;br /&gt;
&lt;br /&gt;
To mark an event as having a result, the event class should be annotated with &amp;lt;code&amp;gt;@Event.HasResult&amp;lt;/code&amp;gt;. This will automatically make &amp;lt;code&amp;gt;Event#hasResult&amp;lt;/code&amp;gt; return &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;. Modders may check if an event has a result through the presence of the annotation or by calling the given method.&lt;br /&gt;
&lt;br /&gt;
== Event Bus ==&lt;br /&gt;
An '''event bus''' is an object which holds a list of event listeners, and the logic for firing the events. Events may be posted on these event buses, which then invokes the handlers. The main class for event buses is &amp;lt;code&amp;gt;IEventBus&amp;lt;/code&amp;gt;, and a bus is created using &amp;lt;code&amp;gt;BusBuilder&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Existing Buses ===&lt;br /&gt;
Forge exposes three main families of event buses: the main Forge event bus, the mod-specific event buses, and the network channel event buses.&lt;br /&gt;
&lt;br /&gt;
==== Main Forge Event Bus ====&lt;br /&gt;
The '''main Forge event bus''' is located at &amp;lt;code&amp;gt;MinecraftForge#EVENT_BUS&amp;lt;/code&amp;gt;, and is where most events relating to ingame actions or events are fired on, such as events for ticking, block interactions, and entity interactions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot; style=&amp;quot;border: 2px solid; border-radius: 2px; padding: 5px; margin: 1em; overflow:auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;font-weight:bold; line-height:1.6;&amp;quot;&amp;gt;List of events fired on the main Forge event bus&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
{{:Events/Forge bus}}&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Mod-Specific Event Buses ====&lt;br /&gt;
The '''mod-specific event buses''' are the family of event buses where mod-related initialization and registration events are fired, such as the events for [[Registration|registering objects]] or setup on different physical sides. Only events which implement &amp;lt;code&amp;gt;IModBusEvent&amp;lt;/code&amp;gt; may be fired or listened for on these event buses.&lt;br /&gt;
&lt;br /&gt;
Each loaded mod has their own instance of a mod-specific event bus. The mod-specific event bus for the currently loading mod can be retrieved from &amp;lt;code&amp;gt;FMLModContainer#getEventBus()&amp;lt;/code&amp;gt;, which is also accessible from &amp;lt;code&amp;gt;FMLJavaModLoadingContext#getModEventBus()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Tip|title=Tip|The mod-specific event buses are provided by the &amp;lt;code&amp;gt;javafml&amp;lt;/code&amp;gt; language provider which is builtin to Forge Mod Loader. Custom language providers may provide other ways for mods to receive the different mod-related initialization and registration events; see the documentation of your custom language provider for details.}}&lt;br /&gt;
&lt;br /&gt;
==== Network Channel Event Buses ====&lt;br /&gt;
The '''network channel event buses''' are the family of event buses where different network-related events are fired. Each registered [[Networking|networking channel]] has their own instance of an event-bus in &amp;lt;code&amp;gt;NetworkInstance&amp;lt;/code&amp;gt;, where only events pertinent to that channel are fired on.&lt;br /&gt;
&lt;br /&gt;
The network channel event buses cannot be accessed directly; &amp;lt;code&amp;gt;EventNetworkChannel&amp;lt;/code&amp;gt; provides methods to register events listeners to the event bus.&lt;br /&gt;
&lt;br /&gt;
== Event Listeners ==&lt;br /&gt;
An '''event listener''' (also known as an '''event handler''') is a class, object, or method registered to an event bus to capture for specific events (and their subclasses).&lt;br /&gt;
&lt;br /&gt;
[[File:Guide to Event Handlers.png|thumb|upright 0.9|A visual guide on how event listeners are registered.]]&lt;br /&gt;
&lt;br /&gt;
An event listener may be registered in three ways:&lt;br /&gt;
* The &amp;lt;code&amp;gt;IEventBus#register(Object)&amp;lt;/code&amp;gt; method on a class or instance;&lt;br /&gt;
* The &amp;lt;code&amp;gt;@EventBusSubscriber&amp;lt;/code&amp;gt; annotation on a class; or&lt;br /&gt;
* The &amp;lt;code&amp;gt;IEventBus#addListener&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;IEventBus#addGenericListener&amp;lt;/code&amp;gt; on a method reference or lambda.&lt;br /&gt;
&lt;br /&gt;
=== Priority and Receiving Cancelled Events ===&lt;br /&gt;
An event listener may be registered to a specific '''event priority''' and whether to '''receive cancelled events'''.&lt;br /&gt;
&lt;br /&gt;
The event priority levels allows a listener to react to an event before other event listeners of a lower level, such as to change the values within an event or cancel it outright.&lt;br /&gt;
&lt;br /&gt;
There are five levels of event listeners priority; in descending order from first to receive an event to last: &amp;lt;code&amp;gt;HIGHEST&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;HIGH&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;NORMAL&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LOW&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;LOWEST&amp;lt;/code&amp;gt;. Event listeners are registered by default on a priority of &amp;lt;code&amp;gt;NORMAL&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
An event listener normally never receives a cancelled event, however they may change this by being registered to receive these cancelled events. Non-cancellable events are unaffected by this, and will always be sent to all event listeners (in the order specified by their priority).&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;IEventBus.register&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
The &amp;lt;code&amp;gt;IEventBus#register(Object)&amp;lt;/code&amp;gt; method allows for registering an object instance or a &amp;lt;code&amp;gt;Class&amp;lt;?&amp;gt;&amp;lt;/code&amp;gt; to the event bus. The method exhibits two different behaviors, depending on what is passed into it:&lt;br /&gt;
&lt;br /&gt;
* '''an object instance''' - registers all ''instance or non-&amp;lt;code&amp;gt;static&amp;lt;/code&amp;gt;'' methods annotated with &amp;lt;code&amp;gt;@SubscribeEvent&amp;lt;/code&amp;gt; from the object&lt;br /&gt;
* '''a &amp;lt;code&amp;gt;Class&amp;lt;?&amp;gt;&amp;lt;/code&amp;gt; instance''' - registers all ''class or &amp;lt;code&amp;gt;static&amp;lt;/code&amp;gt;'' methods annotated with &amp;lt;code&amp;gt;@SubscribeEvent&amp;lt;/code&amp;gt; from the class which is represented by the passed in &amp;lt;code&amp;gt;Class&amp;lt;?&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab collapsed name=&amp;quot;Example of how event listeners are registered with the IEventBus.register method&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
class EventHandler {&lt;br /&gt;
	public static void nonAnnotatedStatic(Event event) {}&lt;br /&gt;
&lt;br /&gt;
	@SubscribeEvent&lt;br /&gt;
	public static void annotatedStatic(Event event) {}&lt;br /&gt;
&lt;br /&gt;
	public void nonAnnotatedInstance(Event event) {}&lt;br /&gt;
&lt;br /&gt;
	@SubscribeEvent&lt;br /&gt;
	public void annotatedInstance(Event event) {}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Within the execution of the program&lt;br /&gt;
IEventBus bus = ...;&lt;br /&gt;
&lt;br /&gt;
// This will register the &amp;quot;annotatedStatic&amp;quot; method from the class&lt;br /&gt;
bus.register(EventHandler.class);&lt;br /&gt;
// This would register &amp;quot;annotatedStatic&amp;quot;, but it is already registered&lt;br /&gt;
bus.register(EventHandler.class);&lt;br /&gt;
&lt;br /&gt;
EventHandler instanceA = new EventHandler();&lt;br /&gt;
EventHandler instanceB = new EventHandler();&lt;br /&gt;
&lt;br /&gt;
// This will register the &amp;quot;annotatedInstance&amp;quot; method from the instanceA object, and will not touch the instanceB object&lt;br /&gt;
bus.register(instanceA);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
If an &amp;lt;code&amp;gt;Event&amp;lt;/code&amp;gt; were to be fired on the event bus in the example above, the &amp;lt;code&amp;gt;EventHandler#annotatedStatic&amp;lt;/code&amp;gt; would receive the event, and the &amp;lt;code&amp;gt;annotatedInstance&amp;lt;/code&amp;gt; method from the &amp;lt;code&amp;gt;instanceA&amp;lt;/code&amp;gt; object instance would receive the event.&lt;br /&gt;
&lt;br /&gt;
Neither the unnannotated methods will receive the event, nor will the &amp;lt;code&amp;gt;annotatedInstance&amp;lt;/code&amp;gt; method from the &amp;lt;code&amp;gt;instanceB&amp;lt;/code&amp;gt; object instance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;tt&amp;gt;@SubscribeEvent&amp;lt;/tt&amp;gt; ====&lt;br /&gt;
The &amp;lt;code&amp;gt;@SubscribeEvent&amp;lt;/code&amp;gt; annotation is used to mark a method as an event listener when its containing class or object is registered using &amp;lt;code&amp;gt;IEventBus#register&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
They have two fields: &amp;lt;code&amp;gt;EventPriority priority&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;boolean receiveCancelled&amp;lt;/code&amp;gt;, which sets the event priority for the listener and whether the listener receives cancelled events, respectively.&lt;br /&gt;
&lt;br /&gt;
= WIP =&lt;br /&gt;
TODO: @EventBusSubscriber, addListener, Generic Events? (probably higher up)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Partial previous content of page, to be removed&amp;quot; collapsed&amp;gt;&lt;br /&gt;
== Forge and Mod Buses ==&lt;br /&gt;
There are two event buses of note to a mod: the '''main Forge event bus''', and the '''mod-specific event bus'''.&lt;br /&gt;
&lt;br /&gt;
The Forge event bus, which can be referenced through &amp;lt;code&amp;gt;MinecraftForge.EVENT_BUS&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;EventBusSubscriber.Bus.FORGE&amp;lt;/code&amp;gt; (the latter being an enum that provides handy references to both busses), fires events that depend solely on the game state. This means that:&lt;br /&gt;
* Entity Events&lt;br /&gt;
* Ticking Events&lt;br /&gt;
* Server Events&lt;br /&gt;
and more, are fired on the Forge bus.&lt;br /&gt;
&lt;br /&gt;
The Mod bus, referenced through &amp;lt;code&amp;gt;FMLJavaModLoadingContext.get().getModEventBus()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;EventBusSubscriber.Bus.MOD&amp;lt;/code&amp;gt;, fires events that depend solely on mod state, or which are used to initialise such.&lt;br /&gt;
This means that:&lt;br /&gt;
* Registration Events&lt;br /&gt;
* Mod Lifecycle Events&lt;br /&gt;
* Model Events (bake and register)&lt;br /&gt;
* Config Events&lt;br /&gt;
* Data Provider Events&lt;br /&gt;
and more, are fired on the Mod bus. See [[Stages of Modloading|mod loading events]]. Note that some of these are fired in parallel.&lt;br /&gt;
&lt;br /&gt;
== Sub Events ==&lt;br /&gt;
&lt;br /&gt;
Many events have different variations of themselves, these can be different but all based around one common factor (e.g. &amp;lt;code&amp;gt;PlayerEvent&amp;lt;/code&amp;gt;) or can be an event that has multiple phases (e.g. &amp;lt;code&amp;gt;PotionBrewEvent&amp;lt;/code&amp;gt;). Take note that if you listen to the parent event class, you will receive calls to your method for ''all'' subclasses.&lt;br /&gt;
&lt;br /&gt;
== Event Handlers ==&lt;br /&gt;
Event handlers are methods, which have four main properties. They are communicated to the event bus you want them to listen on, and when the event is posted on that bus, the hander is invoked.&lt;br /&gt;
&lt;br /&gt;
Event handlers' properties are as such:&lt;br /&gt;
- Registered to an event bus&lt;br /&gt;
- May be static or instance&lt;br /&gt;
- Have a single argument, which is used to determine the event that is being listened for&lt;br /&gt;
- The argument given is the instance of the Event being posted.&lt;br /&gt;
&lt;br /&gt;
Note that handlers may take the form of anonymous functions - lambdas.&lt;br /&gt;
&lt;br /&gt;
== Registering Event Handlers ==&lt;br /&gt;
Event handlers are registered typically one of four ways:&lt;br /&gt;
* &amp;lt;code&amp;gt;EventBusSubscriber&amp;lt;/code&amp;gt; (which requires a static, annotated handler method)&lt;br /&gt;
* &amp;lt;code&amp;gt;EventBus#register(T.class)&amp;lt;/code&amp;gt; (which requires a static, annotated handler method)&lt;br /&gt;
* &amp;lt;code&amp;gt;EventBus#register(new X())&amp;lt;/code&amp;gt; (which requires an instance, annotated handler method)&lt;br /&gt;
* &amp;lt;code&amp;gt;EventBus#addListener(Class::function)&amp;lt;/code&amp;gt; (which requires an instance, non-annotated handler method)&lt;br /&gt;
* as an extension of the above: &amp;lt;code&amp;gt;EventBus#&amp;lt;LivingHurtEvent&amp;gt;addListener(event -&amp;gt; { code })&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each of these will be explained in detail as follows.&lt;br /&gt;
&lt;br /&gt;
=== Annotated Event Handlers ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class MyForgeEventHandler {&lt;br /&gt;
    @SubscribeEvent&lt;br /&gt;
    public void pickupItem(EntityItemPickupEvent event) {&lt;br /&gt;
        System.out.println(&amp;quot;Item picked up!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This event handler listens for the &amp;lt;code&amp;gt;EntityItemPickupEvent&amp;lt;/code&amp;gt;, which is, as the name states, posted to the event bus whenever an &amp;lt;code&amp;gt;Entity&amp;lt;/code&amp;gt; picks up an item.&lt;br /&gt;
&lt;br /&gt;
This function would be registered with &amp;lt;code&amp;gt;EventBus#register(new X())&amp;lt;/code&amp;gt; in the above examples.&lt;br /&gt;
&lt;br /&gt;
=== Static Event Handlers ===&lt;br /&gt;
&lt;br /&gt;
An event handler may also be static. The handling method is still annotated with &amp;lt;code&amp;gt;@SubscribeEvent&amp;lt;/code&amp;gt; with the only difference from an instance handler is that it is also marked static. In order to register a static event handler, an instance of the class won’t do, the Class itself has to be passed in. An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class MyStaticForgeEventHandler {&lt;br /&gt;
    @SubscribeEvent&lt;br /&gt;
    public static void arrowNocked(ArrowNockEvent event) {&lt;br /&gt;
        System.out.println(&amp;quot;Arrow nocked!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which must be registered &amp;lt;code&amp;gt;EventBus#register(MyStaticForgeEventHandler.class)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3 id=&amp;quot;eventbussubscriber&amp;quot;&amp;gt;Using &amp;lt;tt style=&amp;quot;font-size: 100%&amp;quot;&amp;gt;@Mod.EventBusSubscriber&amp;lt;/tt&amp;gt;&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A class may be annotated with the &amp;lt;code&amp;gt;@Mod.EventBusSubscriber&amp;lt;/code&amp;gt; annotation. Such a class is automatically registered to the configured bus when the &amp;lt;code&amp;gt;@Mod&amp;lt;/code&amp;gt; class itself is constructed. This is essentially equivalent to adding &amp;lt;code&amp;gt;EventBus#register(AnnotatedClass.class);&amp;lt;/code&amp;gt; at the end of the &amp;lt;code&amp;gt;@Mod&amp;lt;/code&amp;gt; class's constructor.&lt;br /&gt;
&lt;br /&gt;
The mod ID must be specified unless your class is already annotated with an &amp;lt;code&amp;gt;@Mod&amp;lt;/code&amp;gt; annotation. You can pass the bus you want to listen to inside the &amp;lt;code&amp;gt;@Mod.EventBusSubscriber&amp;lt;/code&amp;gt; annotation.&lt;br /&gt;
&lt;br /&gt;
The bus registered with &amp;lt;code&amp;gt;EventBusSubscriber&amp;lt;/code&amp;gt; defaults to the Forge event bus.&lt;br /&gt;
&lt;br /&gt;
You can also specify the &amp;lt;code&amp;gt;Dist&amp;lt;/code&amp;gt;s to load this event subscriber on. This can be used to not load client specific event subscribers on the dedicated server.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example for a static event listener listening to &amp;lt;code&amp;gt;RenderWorldLastEvent&amp;lt;/code&amp;gt; which will only be called on the physical client: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
@Mod.EventBusSubscriber(modid = &amp;quot;examplemod&amp;quot;, dist = Dist.CLIENT)&lt;br /&gt;
public class MyStaticClientOnlyEventHandler {&lt;br /&gt;
    @SubscribeEvent&lt;br /&gt;
    public static void drawLast(RenderWorldLastEvent event) {&lt;br /&gt;
        System.out.println(&amp;quot;Drawing!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Tip/Important|This does not register an instance of the class; it registers the class itself (i.e. the event handling methods must be static).}}&lt;br /&gt;
&lt;br /&gt;
=== Non-Annotated Event Handlers ===&lt;br /&gt;
&lt;br /&gt;
Event handlers do not need to be annotated if they are directly referred to using &amp;lt;code&amp;gt;EventBus#addListener&amp;lt;/code&amp;gt; (or &amp;lt;code&amp;gt;EventBus#addGenericListener&amp;lt;/code&amp;gt; for generic events).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
@Mod(&amp;quot;examplemod&amp;quot;)&lt;br /&gt;
public class MyMainModClass {&lt;br /&gt;
&lt;br /&gt;
  public MyMainModClass() {&lt;br /&gt;
    FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(Entity.class, this::entityCap);&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  private void entityCap(AttachCapabilitiesEvent&amp;lt;Entity&amp;gt; event) {&lt;br /&gt;
    System.out.println(&amp;quot;Capability attached!&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Tip/Important|The generic passed into the event must be referenced directly within the code itself. Otherwise, the event will not be called whatsoever. For example, if you use &amp;lt;code&amp;gt;AttachCapabilitiesEvent&amp;lt;LivingEntity&amp;gt;&amp;lt;/code&amp;gt;, the event will never be called as no call of this event uses &amp;lt;code&amp;gt;LivingEntity&amp;lt;/code&amp;gt;, only &amp;lt;code&amp;gt;Entity&amp;lt;/code&amp;gt;.}}&lt;br /&gt;
&lt;br /&gt;
== Cancelling ==&lt;br /&gt;
&lt;br /&gt;
If an event can be cancelled, it will be marked with the &amp;lt;code&amp;gt;@Cancelable&amp;lt;/code&amp;gt; annotation, and the method &amp;lt;code&amp;gt;Event#isCancelable()&amp;lt;/code&amp;gt; will return &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;. The cancel state of a cancellable event may be modified by calling &amp;lt;code&amp;gt;Event#setCanceled(boolean canceled)&amp;lt;/code&amp;gt;, wherein passing the boolean value &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; is interpreted as cancelling the event, and passing the boolean value &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; is interpreted as “un-cancelling” the event.&lt;br /&gt;
&lt;br /&gt;
{{Tip/Important|Not all events can be cancelled! Attempting to cancel an event that is not cancellable will result in an unchecked &amp;lt;code&amp;gt;UnsupportedOperationException&amp;lt;/code&amp;gt; being thrown, which is expected to result in the game crashing. Always check that an event can be cancelled using &amp;lt;code&amp;gt;Event#isCancelable()&amp;lt;/code&amp;gt; before attempting to cancel it.}}&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
Some events have an &amp;lt;code&amp;gt;Event.Result&amp;lt;/code&amp;gt; as denoted by &amp;lt;code&amp;gt;@HasResult&amp;lt;/code&amp;gt;. A result can be one of three things: &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; which stops the event, &amp;lt;code&amp;gt;DEFAULT&amp;lt;/code&amp;gt; which uses the Vanilla behavior, and &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; which forces the action to take place, regardless of if it would have originally. The result of an event can be set by calling &amp;lt;code&amp;gt;setResult&amp;lt;/code&amp;gt; with an Event.Result on the event.&lt;br /&gt;
&lt;br /&gt;
{{Colored box|title=Information|content=Different events may use results in different ways, refer to the event's JavaDoc before using the result.}}&lt;br /&gt;
&lt;br /&gt;
== Priority ==&lt;br /&gt;
&lt;br /&gt;
Event handler methods have a priority. You can set the &amp;lt;code&amp;gt;priority&amp;lt;/code&amp;gt; of an event handler method by setting the priority value of the annotation or the listener. The priority can be any value of the &amp;lt;code&amp;gt;EventPriority&amp;lt;/code&amp;gt; enum (&amp;lt;code&amp;gt;HIGHEST&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;HIGH&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;NORMAL&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LOW&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;LOWEST&amp;lt;/code&amp;gt;). Event handlers with priority &amp;lt;code&amp;gt;HIGHEST&amp;lt;/code&amp;gt; are executed first and from there in descending order until &amp;lt;code&amp;gt;LOWEST&amp;lt;/code&amp;gt; events which are executed last.&lt;br /&gt;
&lt;br /&gt;
== Mod Event Bus ==&lt;br /&gt;
The mod event bus is primarily used for listening to lifecycle events in which mods should initialize. Many of these events are also ran in parallel so mods can be initialized at the same time. This does mean you cannot directly execute code from other mods in these events. Use the &amp;lt;code&amp;gt;InterModComms&amp;lt;/code&amp;gt; system for that.&lt;br /&gt;
&lt;br /&gt;
It is impossible for an event to be posted on the Mod bus that does not inherit the IModBusEvent interface.&lt;br /&gt;
Thus, this provides a good, easy way to tell which events are fired on this bus.&lt;br /&gt;
&lt;br /&gt;
These are the four most commonly used lifecycle events that are called during mod initialization on the mod event bus: &lt;br /&gt;
* &amp;lt;code&amp;gt;FMLCommonSetupEvent&amp;lt;/code&amp;gt; &lt;br /&gt;
* &amp;lt;code&amp;gt;FMLClientSetupEvent&amp;lt;/code&amp;gt; &amp;amp; &amp;lt;code&amp;gt;FMLDedicatedServerSetupEvent&amp;lt;/code&amp;gt; (''These events are only called on their respective [[Sides#Different_Kinds_of_Sides|physical side]].'')&lt;br /&gt;
* &amp;lt;code&amp;gt;InterModEnqueueEvent&amp;lt;/code&amp;gt; &lt;br /&gt;
* &amp;lt;code&amp;gt;InterModProcessEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These four lifecycle events are all ran in parallel. If you want to run code on the main thread during these events you can use the &amp;lt;code&amp;gt;enqueueWork&amp;lt;/code&amp;gt; methods within the events to do so.&lt;br /&gt;
&lt;br /&gt;
Next to the lifecycle events there are a few miscellaneous events that are fired on the mod event bus where you can register, set up, or initialize various things. Most of these events are not ran in parallel in contrast to the lifecycle events:&lt;br /&gt;
* &amp;lt;code&amp;gt;ColorHandlerEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;ModelBakeEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;TextureStitchEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;RegistryEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GatherDataEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;SoundLoadEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;ParticleFactoryRegisterEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;ModConfigEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A good rule of thumb: events are fired on the mod event bus when they should be handled during initialization of a mod. or where they are used to set state (eg. the config event.)&lt;br /&gt;
&lt;br /&gt;
Detailed information about these events will be found in their respective pages, once they are ready.&lt;br /&gt;
&lt;br /&gt;
== Forge Event Bus ==&lt;br /&gt;
The Forge event bus is where game state events are fired. If anything changes to do with the game, or anything happens that you would need to know about, there's a good chance it's sent here.&lt;br /&gt;
&lt;br /&gt;
A full list of the events fired here is as follows, split into discrete categories:&lt;br /&gt;
&lt;br /&gt;
{{Tree list}}&lt;br /&gt;
* &amp;lt;code&amp;gt;Event&amp;lt;/code&amp;gt; - ''The root event class''&lt;br /&gt;
** '''Rendering events''' ('''client-only''')&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderWorldLastEvent&amp;lt;/code&amp;gt; - Fired after world rendering to allow mods to add custom renders&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderHandEvent&amp;lt;/code&amp;gt; - Fired before and after the hand of the player is rendered in the first person POV&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderLivingEvent&amp;lt;/code&amp;gt; - Fired before and after a &amp;lt;code&amp;gt;LivingRenderer&amp;lt;/code&amp;gt; is executed&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderItemInFrameEvent&amp;lt;/code&amp;gt; - Fired before the item in an &amp;lt;code&amp;gt;ItemFrameEntity&amp;lt;/code&amp;gt; is rendered&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderBlockOverlayEvent&amp;lt;/code&amp;gt; - Fired before the block overlay for the player's screen is rendered&lt;br /&gt;
*** &amp;lt;code&amp;gt;DrawHighlightEvent&amp;lt;/code&amp;gt; - Fired before the block highlight outline is rendered&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderTooltipEvent&amp;lt;/code&amp;gt; - Fired before and during rendering of a text tooltip on a screen&lt;br /&gt;
*** &amp;lt;code&amp;gt;EntityViewRenderEvent&amp;lt;/code&amp;gt; - Superclass for events relating to the player's viewpoint&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderGameOverlayEvent&amp;lt;/code&amp;gt; - Superclass, fired for each element on the player's HUD or game overlay&lt;br /&gt;
*** &amp;lt;code&amp;gt;FOVUpdateEvent&amp;lt;/code&amp;gt; - Fired when the FOV of the player is requested (?)&lt;br /&gt;
** '''GUI/Screen events''' ('''client-only''')&lt;br /&gt;
*** &amp;lt;code&amp;gt;GuiScreenEvent&amp;lt;/code&amp;gt; - Superclass for events relating to &amp;lt;code&amp;gt;Screen&amp;lt;/code&amp;gt;s&lt;br /&gt;
*** &amp;lt;code&amp;gt;GuiContainerEvent&amp;lt;/code&amp;gt; - Superclsas for events relating to &amp;lt;code&amp;gt;ContainerScreen&amp;lt;/code&amp;gt;s&lt;br /&gt;
*** &amp;lt;code&amp;gt;GuiOpenEvent&amp;lt;/code&amp;gt; - Fired before a new screen is opened on the game window&lt;br /&gt;
** '''Superclass events''' - ''These events exist to be superclasses of other events''&lt;br /&gt;
*** &amp;lt;code&amp;gt;GenericEvent&amp;lt;/code&amp;gt; - ''from EventBus'', superclass of events which have a generic type&lt;br /&gt;
*** [[Events/BlockEvent|BlockEvent]] - Superclass for events relating to a block within the world&lt;br /&gt;
*** &amp;lt;code&amp;gt;WorldEvent&amp;lt;/code&amp;gt; - Superclass for events relating to the world&lt;br /&gt;
*** &amp;lt;code&amp;gt;InputEvent&amp;lt;/code&amp;gt; - ('''client-only''') Superclass for events relating to the player's keyboard and mouse inputs&lt;br /&gt;
*** &amp;lt;code&amp;gt;NetworkEvent&amp;lt;/code&amp;gt; - Superclass for events relating to networking&lt;br /&gt;
*** &amp;lt;code&amp;gt;ExplosionEvent&amp;lt;/code&amp;gt; - Fired before an explosion explodes in the world&lt;br /&gt;
*** &amp;lt;code&amp;gt;SoundEvent&amp;lt;/code&amp;gt; - ('''client-only''') Superclass for events related to sounds&lt;br /&gt;
*** &amp;lt;code&amp;gt;EntityEvent&amp;lt;/code&amp;gt; - Superclass for events relating to entities&lt;br /&gt;
*** &amp;lt;code&amp;gt;TickEvent&amp;lt;/code&amp;gt; - Superclass for events fired before and after ticking&lt;br /&gt;
** '''Chat events'''&lt;br /&gt;
*** &amp;lt;code&amp;gt;ServerChatEvent&amp;lt;/code&amp;gt; ('''server-only''') - Fired when the server receives a chat message and before it relays the message&lt;br /&gt;
*** &amp;lt;code&amp;gt;ClientChatEvent&amp;lt;/code&amp;gt; ('''client-only''') - Fired before the client is about to send a chat message&lt;br /&gt;
*** &amp;lt;code&amp;gt;ClientChatReceivedEvent&amp;lt;/code&amp;gt; ('''client-only''') - Fired when the client receives a chat message from the server&lt;br /&gt;
** '''Data loading events'''&lt;br /&gt;
*** &amp;lt;code&amp;gt;RecipesUpdatedEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;BiomeLoadingEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;LootTableLoadEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;StructureSpawnListGatherEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
** '''Startup events'''&lt;br /&gt;
*** &amp;lt;code&amp;gt;AddReloadListenerEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;RegisterCommandsEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ServerLifecycleEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
** '''Gamemode events'''&lt;br /&gt;
*** &amp;lt;code&amp;gt;DifficultyChangeEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ClientPlayerChangeGamemodeEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
**'''Trade events'''&lt;br /&gt;
*** &amp;lt;code&amp;gt;WandererTradesEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;VillagerTradesEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
** '''Other events'''&lt;br /&gt;
*** &amp;lt;code&amp;gt;FurnaceFuelBurnTimeEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;BabyEntitySpawnEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;VillageSiegeEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;TagsUpdatedEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;PotionBrewEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ScreenshotEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;EnchantmentLevelSetEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;CommandEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;AnvilUpdateEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ItemAttributeModifierEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ClientPlayerNetworkEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ChunkWatchEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
{{Tree list/end}}&lt;br /&gt;
&lt;br /&gt;
Like before, each of these events (especially the Super Events, which contain most of the useful events in the game) will have their own article explaining their purpose and usefulness.&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;/div&gt;</summary>
		<author><name>EERussianguy</name></author>
	</entry>
	<entry>
		<id>https://forge.gemwire.uk/index.php?title=Events&amp;diff=2572</id>
		<title>Events</title>
		<link rel="alternate" type="text/html" href="https://forge.gemwire.uk/index.php?title=Events&amp;diff=2572"/>
		<updated>2021-04-20T13:42:52Z</updated>

		<summary type="html">&lt;p&gt;EERussianguy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Under construction}}&lt;br /&gt;
&lt;br /&gt;
An '''event''' is a signal that is fired on an '''event bus''' to inform registered listeners about some type of action or state. This is the primary way by which Forge allows mods to hook into vanilla and game behavior; Forge has an array of different events which are fired when different actions happen within the game, and mods may act upon receiving these events.  &lt;br /&gt;
&lt;br /&gt;
Additionally, mods may create their own events and fire them for other mods to listen for, allowing for higher compatibility. For a class to be considered an event, it must be a subclass of &amp;lt;code&amp;gt;Event&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Generic Events ==&lt;br /&gt;
'''Generic events''' are events which supply additional generic type information, allowing event listeners to filter based on that secondary type. Generic events must implement &amp;lt;code&amp;gt;IGenericEvent&amp;lt;T&amp;gt;&amp;lt;/code&amp;gt;, and return their generic type from the &amp;lt;code&amp;gt;IGenericEvent#getType()&amp;lt;/code&amp;gt; method. As a convenience, events that wish to be generic events may extend the &amp;lt;code&amp;gt;GenericEvent&amp;lt;T&amp;gt;&amp;lt;/code&amp;gt; instead of manually implementing the interface.&lt;br /&gt;
&lt;br /&gt;
For generic events, the generic type must be an exact match with the listener's generic type filter to pass; if an &amp;lt;code&amp;gt;AttachCapabilitiesEvent&amp;lt;ItemStack&amp;gt;&amp;lt;/code&amp;gt; is fired and a listener is listening for &amp;lt;code&amp;gt;AttachCapabilitiesEvent&amp;lt;Object&amp;gt;&amp;lt;/code&amp;gt;, the listener does not receive the event. A event listener may listen to events with any generic type by supplying a wildcard generic (&amp;lt;code&amp;gt;&amp;lt;?&amp;gt;&amp;lt;/code&amp;gt;). Nested generic types are ignored.&lt;br /&gt;
&lt;br /&gt;
== Cancellable Events ==&lt;br /&gt;
An event may be marked as '''cancellable''', which allows event listeners to cancel the event.&lt;br /&gt;
&lt;br /&gt;
A cancellable event may be cancelled by using &amp;lt;code&amp;gt;Event#setCanceled(true)&amp;lt;/code&amp;gt;. Attempting to call this method on a non-cancellable event will result in a &amp;lt;code&amp;gt;UnsupportedOperationException&amp;lt;/code&amp;gt;. A cancelled event behaves similarly to a regular noncancelled event, with one main difference: an event listener will not receive cancelled events unless they are explicitly registered to listen for cancelled events.&lt;br /&gt;
&lt;br /&gt;
To mark an event as cancellable, the event class should be annotated with &amp;lt;code&amp;gt;@Cancelable&amp;lt;/code&amp;gt;. This will automatically make &amp;lt;code&amp;gt;Event#isCancelable()&amp;lt;/code&amp;gt; return &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;. Modders may check if an event has a result through the presence of the annotation or by calling the given method.&lt;br /&gt;
&lt;br /&gt;
== Events with Results ==&lt;br /&gt;
An event may have a '''result''', which is an enum of &amp;lt;code&amp;gt;Event.Result&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Event.Result&amp;lt;/code&amp;gt; enum has three values: &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DEFAULT&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt;. The meaning of these result values is entirely dependent on the event itself.&lt;br /&gt;
 &lt;br /&gt;
An event's current result can be retrieved through &amp;lt;code&amp;gt;Event#getResult()&amp;lt;/code&amp;gt;. The result on an event can be set through &amp;lt;code&amp;gt;Event#setResult(Event.Result)&amp;lt;/code&amp;gt;. You can set the result for an event which is not marked as having a result, however this will cause nothing to happen if the event does not use the result value.&lt;br /&gt;
&lt;br /&gt;
To mark an event as having a result, the event class should be annotated with &amp;lt;code&amp;gt;@Event.HasResult&amp;lt;/code&amp;gt;. This will automatically make &amp;lt;code&amp;gt;Event#hasResult&amp;lt;/code&amp;gt; return &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;. Modders may check if an event has a result through the presence of the annotation or by calling the given method.&lt;br /&gt;
&lt;br /&gt;
== Event Bus ==&lt;br /&gt;
An '''event bus''' is an object which holds a list of event listeners, and the logic for firing the events. Events may be posted on these event buses, which then invokes the handlers. The main class for event buses is &amp;lt;code&amp;gt;IEventBus&amp;lt;/code&amp;gt;, and a bus is created using &amp;lt;code&amp;gt;BusBuilder&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Existing Buses ===&lt;br /&gt;
Forge exposes three main families of event buses: the main Forge event bus, the mod-specific event buses, and the network channel event buses.&lt;br /&gt;
&lt;br /&gt;
==== Main Forge Event Bus ====&lt;br /&gt;
The '''main Forge event bus''' is located at &amp;lt;code&amp;gt;MinecraftForge#EVENT_BUS&amp;lt;/code&amp;gt;, and is where most events relating to ingame actions or events are fired on, such as events for ticking, block interactions, and entity interactions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot; style=&amp;quot;border: 2px solid; border-radius: 2px; padding: 5px; margin: 1em; overflow:auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;font-weight:bold; line-height:1.6;&amp;quot;&amp;gt;List of events fired on the main Forge event bus&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
{{:Events/Forge bus}}&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Mod-Specific Event Buses ====&lt;br /&gt;
The '''mod-specific event buses''' are the family of event buses where mod-related initialization and registration events are fired, such as the events for [[Registration|registering objects]] or setup on different physical sides. Only events which implement &amp;lt;code&amp;gt;IModBusEvent&amp;lt;/code&amp;gt; may be fired or listened for on these event buses.&lt;br /&gt;
&lt;br /&gt;
Each loaded mod has their own instance of a mod-specific event bus. The mod-specific event bus for the currently loading mod can be retrieved from &amp;lt;code&amp;gt;FMLModContainer#getEventBus()&amp;lt;/code&amp;gt;, which is also accessible from &amp;lt;code&amp;gt;FMLJavaModLoadingContext#getModEventBus()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Tip|title=Tip|The mod-specific event buses are provided by the &amp;lt;code&amp;gt;javafml&amp;lt;/code&amp;gt; language provider which is builtin to Forge Mod Loader. Custom language providers may provide other ways for mods to receive the different mod-related initialization and registration events; see the documentation of your custom language provider for details.}}&lt;br /&gt;
&lt;br /&gt;
==== Network Channel Event Buses ====&lt;br /&gt;
The '''network channel event buses''' are the family of event buses where different network-related events are fired. Each registered [[Networking|networking channel]] has their own instance of an event-bus in &amp;lt;code&amp;gt;NetworkInstance&amp;lt;/code&amp;gt;, where only events pertinent to that channel are fired on.&lt;br /&gt;
&lt;br /&gt;
The network channel event buses cannot be accessed directly; &amp;lt;code&amp;gt;EventNetworkChannel&amp;lt;/code&amp;gt; provides methods to register events listeners to the event bus.&lt;br /&gt;
&lt;br /&gt;
== Event Listeners ==&lt;br /&gt;
An '''event listener''' (also known as an '''event handler''') is a class, object, or method registered to an event bus to capture for specific events (and their subclasses).&lt;br /&gt;
&lt;br /&gt;
[[File:Guide to Event Handlers.png|thumb|upright 0.9|A visual guide on how event listeners are registered.]]&lt;br /&gt;
&lt;br /&gt;
An event listener may be registered in three ways:&lt;br /&gt;
* The &amp;lt;code&amp;gt;IEventBus#register(Object)&amp;lt;/code&amp;gt; method on a class or instance;&lt;br /&gt;
* The &amp;lt;code&amp;gt;@EventBusSubscriber&amp;lt;/code&amp;gt; annotation on a class; or&lt;br /&gt;
* The &amp;lt;code&amp;gt;IEventBus#addListener&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;IEventBus#addGenericListener&amp;lt;/code&amp;gt; on a method reference or lambda.&lt;br /&gt;
&lt;br /&gt;
=== Priority and Receiving Cancelled Events ===&lt;br /&gt;
An event listener may be registered to a specific '''event priority''' and whether to '''receive cancelled events'''.&lt;br /&gt;
&lt;br /&gt;
The event priority levels allows a listener to react to an event before other event listeners of a lower level, such as to change the values within an event or cancel it outright.&lt;br /&gt;
&lt;br /&gt;
There are five levels of event listeners priority; in descending order from first to receive an event to last: &amp;lt;code&amp;gt;HIGHEST&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;HIGH&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;NORMAL&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LOW&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;LOWEST&amp;lt;/code&amp;gt;. Event listeners are registered by default on a priority of &amp;lt;code&amp;gt;NORMAL&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
An event listener normally never receives a cancelled event, however they may change this by being registered to receive these cancelled events. Non-cancellable events are unaffected by this, and will always be sent to all event listeners (in the order specified by their priority).&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;IEventBus.register&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
The &amp;lt;code&amp;gt;IEventBus#register(Object)&amp;lt;/code&amp;gt; method allows for registering an object instance or a &amp;lt;code&amp;gt;Class&amp;lt;?&amp;gt;&amp;lt;/code&amp;gt; to the event bus. The method exhibits two different behaviors, depending on what is passed into it:&lt;br /&gt;
&lt;br /&gt;
* '''an object instance''' - registers all ''instance or non-&amp;lt;code&amp;gt;static&amp;lt;/code&amp;gt;'' methods annotated with &amp;lt;code&amp;gt;@SubscribeEvent&amp;lt;/code&amp;gt; from the object&lt;br /&gt;
* '''a &amp;lt;code&amp;gt;Class&amp;lt;?&amp;gt;&amp;lt;/code&amp;gt; instance''' - registers all ''class or &amp;lt;code&amp;gt;static&amp;lt;/code&amp;gt;'' methods annotated with &amp;lt;code&amp;gt;@SubscribeEvent&amp;lt;/code&amp;gt; from the class which is represented by the passed in &amp;lt;code&amp;gt;Class&amp;lt;?&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab collapsed name=&amp;quot;Example of how event listeners are registered with the IEventBus.register method&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
class EventHandler {&lt;br /&gt;
	public static void nonAnnotatedStatic(Event event) {}&lt;br /&gt;
&lt;br /&gt;
	@SubscribeEvent&lt;br /&gt;
	public static void annotatedStatic(Event event) {}&lt;br /&gt;
&lt;br /&gt;
	public void nonAnnotatedInstance(Event event) {}&lt;br /&gt;
&lt;br /&gt;
	@SubscribeEvent&lt;br /&gt;
	public void annotatedInstance(Event event) {}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Within the execution of the program&lt;br /&gt;
IEventBus bus = ...;&lt;br /&gt;
&lt;br /&gt;
// This will register the &amp;quot;annotatedStatic&amp;quot; method from the class&lt;br /&gt;
bus.register(EventHandler.class);&lt;br /&gt;
// This would register &amp;quot;annotatedStatic&amp;quot;, but it is already registered&lt;br /&gt;
bus.register(EventHandler.class);&lt;br /&gt;
&lt;br /&gt;
EventHandler instanceA = new EventHandler();&lt;br /&gt;
EventHandler instanceB = new EventHandler();&lt;br /&gt;
&lt;br /&gt;
// This will register the &amp;quot;annotatedInstance&amp;quot; method from the instanceA object, and will not touch the instanceB object&lt;br /&gt;
bus.register(instanceA);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
If an &amp;lt;code&amp;gt;Event&amp;lt;/code&amp;gt; were to be fired on the event bus in the example above, the &amp;lt;code&amp;gt;EventHandler#annotatedStatic&amp;lt;/code&amp;gt; would receive the event, and the &amp;lt;code&amp;gt;annotatedInstance&amp;lt;/code&amp;gt; method from the &amp;lt;code&amp;gt;instanceA&amp;lt;/code&amp;gt; object instance would receive the event.&lt;br /&gt;
&lt;br /&gt;
Neither the unnannotated methods will receive the event, nor will the &amp;lt;code&amp;gt;annotatedInstance&amp;lt;/code&amp;gt; method from the &amp;lt;code&amp;gt;instanceB&amp;lt;/code&amp;gt; object instance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;tt&amp;gt;@SubscribeEvent&amp;lt;/tt&amp;gt; ====&lt;br /&gt;
The &amp;lt;code&amp;gt;@SubscribeEvent&amp;lt;/code&amp;gt; annotation is used to mark a method as an event listener when its containing class or object is registered using &amp;lt;code&amp;gt;IEventBus#register&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
They have two fields: &amp;lt;code&amp;gt;EventPriority priority&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;boolean receiveCancelled&amp;lt;/code&amp;gt;, which sets the event priority for the listener and whether the listener receives cancelled events, respectively.&lt;br /&gt;
&lt;br /&gt;
= WIP =&lt;br /&gt;
TODO: @EventBusSubscriber, addListener, Generic Events? (probably higher up)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Partial previous content of page, to be removed&amp;quot; collapsed&amp;gt;&lt;br /&gt;
== Forge and Mod Buses ==&lt;br /&gt;
There are two event buses of note to a mod: the '''main Forge event bus''', and the '''mod-specific event bus'''.&lt;br /&gt;
&lt;br /&gt;
The Forge event bus, which can be referenced through &amp;lt;code&amp;gt;MinecraftForge.EVENT_BUS&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;EventBusSubscriber.Bus.FORGE&amp;lt;/code&amp;gt; (the latter being an enum that provides handy references to both busses), fires events that depend solely on the game state. This means that:&lt;br /&gt;
* Entity Events&lt;br /&gt;
* Ticking Events&lt;br /&gt;
* Server Events&lt;br /&gt;
and more, are fired on the Forge bus.&lt;br /&gt;
&lt;br /&gt;
The Mod bus, referenced through &amp;lt;code&amp;gt;FMLJavaModLoadingContext.get().getModEventBus()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;EventBusSubscriber.Bus.MOD&amp;lt;/code&amp;gt;, fires events that depend solely on mod state, or which are used to initialise such.&lt;br /&gt;
This means that:&lt;br /&gt;
* Registration Events&lt;br /&gt;
* Mod Lifecycle Events&lt;br /&gt;
* Model Events (bake and register)&lt;br /&gt;
* Config Events&lt;br /&gt;
* Data Provider Events&lt;br /&gt;
and more, are fired on the Mod bus. See [[Stages of Modloading|mod loading events]]. Note that some of these are fired in parallel.&lt;br /&gt;
&lt;br /&gt;
== Sub Events ==&lt;br /&gt;
&lt;br /&gt;
Many events have different variations of themselves, these can be different but all based around one common factor (e.g. &amp;lt;code&amp;gt;PlayerEvent&amp;lt;/code&amp;gt;) or can be an event that has multiple phases (e.g. &amp;lt;code&amp;gt;PotionBrewEvent&amp;lt;/code&amp;gt;). Take note that if you listen to the parent event class, you will receive calls to your method for ''all'' subclasses.&lt;br /&gt;
&lt;br /&gt;
== Event Handlers ==&lt;br /&gt;
Event handlers are methods, which have four main properties. They are communicated to the event bus you want them to listen on, and when the event is posted on that bus, the hander is invoked.&lt;br /&gt;
&lt;br /&gt;
Event handlers' properties are as such:&lt;br /&gt;
- Registered to an event bus&lt;br /&gt;
- May be static or instance&lt;br /&gt;
- Have a single argument, which is used to determine the event that is being listened for&lt;br /&gt;
- The argument given is the instance of the Event being posted.&lt;br /&gt;
&lt;br /&gt;
Note that handlers may take the form of anonymous functions - lambdas.&lt;br /&gt;
&lt;br /&gt;
== Registering Event Handlers ==&lt;br /&gt;
Event handlers are registered typically one of four ways:&lt;br /&gt;
* &amp;lt;code&amp;gt;EventBusSubscriber&amp;lt;/code&amp;gt; (which requires a static, annotated handler method)&lt;br /&gt;
* &amp;lt;code&amp;gt;EventBus#register(T.class)&amp;lt;/code&amp;gt; (which requires a static, annotated handler method)&lt;br /&gt;
* &amp;lt;code&amp;gt;EventBus#register(new X())&amp;lt;/code&amp;gt; (which requires an instance, annotated handler method)&lt;br /&gt;
* &amp;lt;code&amp;gt;EventBus#addListener(Class::function)&amp;lt;/code&amp;gt; (which requires an instance, non-annotated handler method)&lt;br /&gt;
* as an extension of the above: &amp;lt;code&amp;gt;EventBus#&amp;lt;LivingHurtEvent&amp;gt;addListener(event -&amp;gt; { code })&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each of these will be explained in detail as follows.&lt;br /&gt;
&lt;br /&gt;
=== Annotated Event Handlers ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class MyForgeEventHandler {&lt;br /&gt;
    @SubscribeEvent&lt;br /&gt;
    public void pickupItem(EntityItemPickupEvent event) {&lt;br /&gt;
        System.out.println(&amp;quot;Item picked up!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This event handler listens for the &amp;lt;code&amp;gt;EntityItemPickupEvent&amp;lt;/code&amp;gt;, which is, as the name states, posted to the event bus whenever an &amp;lt;code&amp;gt;Entity&amp;lt;/code&amp;gt; picks up an item.&lt;br /&gt;
&lt;br /&gt;
This function would be registered with &amp;lt;code&amp;gt;EventBus#register(new X())&amp;lt;/code&amp;gt; in the above examples.&lt;br /&gt;
&lt;br /&gt;
=== Static Event Handlers ===&lt;br /&gt;
&lt;br /&gt;
An event handler may also be static. The handling method is still annotated with &amp;lt;code&amp;gt;@SubscribeEvent&amp;lt;/code&amp;gt; with the only difference from an instance handler is that it is also marked static. In order to register a static event handler, an instance of the class won’t do, the Class itself has to be passed in. An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class MyStaticForgeEventHandler {&lt;br /&gt;
    @SubscribeEvent&lt;br /&gt;
    public static void arrowNocked(ArrowNockEvent event) {&lt;br /&gt;
        System.out.println(&amp;quot;Arrow nocked!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which must be registered &amp;lt;code&amp;gt;EventBus#register(MyStaticForgeEventHandler.class)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3 id=&amp;quot;eventbussubscriber&amp;quot;&amp;gt;Using &amp;lt;tt style=&amp;quot;font-size: 100%&amp;quot;&amp;gt;@Mod.EventBusSubscriber&amp;lt;/tt&amp;gt;&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A class may be annotated with the &amp;lt;code&amp;gt;@Mod.EventBusSubscriber&amp;lt;/code&amp;gt; annotation. Such a class is automatically registered to the configured bus when the &amp;lt;code&amp;gt;@Mod&amp;lt;/code&amp;gt; class itself is constructed. This is essentially equivalent to adding &amp;lt;code&amp;gt;EventBus#register(AnnotatedClass.class);&amp;lt;/code&amp;gt; at the end of the &amp;lt;code&amp;gt;@Mod&amp;lt;/code&amp;gt; class's constructor.&lt;br /&gt;
&lt;br /&gt;
The mod ID must be specified unless your class is already annotated with an &amp;lt;code&amp;gt;@Mod&amp;lt;/code&amp;gt; annotation. You can pass the bus you want to listen to inside the &amp;lt;code&amp;gt;@Mod.EventBusSubscriber&amp;lt;/code&amp;gt; annotation.&lt;br /&gt;
&lt;br /&gt;
The bus registered with &amp;lt;code&amp;gt;EventBusSubscriber&amp;lt;/code&amp;gt; defaults to the Forge event bus.&lt;br /&gt;
&lt;br /&gt;
You can also specify the &amp;lt;code&amp;gt;Dist&amp;lt;/code&amp;gt;s to load this event subscriber on. This can be used to not load client specific event subscribers on the dedicated server.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example for a static event listener listening to &amp;lt;code&amp;gt;RenderWorldLastEvent&amp;lt;/code&amp;gt; which will only be called on the physical client: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
@Mod.EventBusSubscriber(modid = &amp;quot;examplemod&amp;quot;, dist = Dist.CLIENT)&lt;br /&gt;
public class MyStaticClientOnlyEventHandler {&lt;br /&gt;
    @SubscribeEvent&lt;br /&gt;
    public static void drawLast(RenderWorldLastEvent event) {&lt;br /&gt;
        System.out.println(&amp;quot;Drawing!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Tip/Important|This does not register an instance of the class; it registers the class itself (i.e. the event handling methods must be static).}}&lt;br /&gt;
&lt;br /&gt;
=== Non-Annotated Event Handlers ===&lt;br /&gt;
&lt;br /&gt;
Event handlers do not need to be annotated if they are directly referred to using &amp;lt;code&amp;gt;EventBus#addListener&amp;lt;/code&amp;gt; (or &amp;lt;code&amp;gt;EventBus#addGenericListener&amp;lt;/code&amp;gt; for generic events).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
@Mod(&amp;quot;examplemod&amp;quot;)&lt;br /&gt;
public class MyMainModClass {&lt;br /&gt;
&lt;br /&gt;
  public MyMainModClass() {&lt;br /&gt;
    FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(Entity.class, this::entityCap);&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  private void entityCap(AttachCapabilitiesEvent&amp;lt;Entity&amp;gt; event) {&lt;br /&gt;
    System.out.println(&amp;quot;Capability attached!&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Tip/Important|The generic passed into the event must be referenced directly within the code itself. Otherwise, the event will not be called whatsoever. For example, if you use &amp;lt;code&amp;gt;AttachCapabilitiesEvent&amp;lt;LivingEntity&amp;gt;&amp;lt;/code&amp;gt;, the event will never be called as no call of this event uses &amp;lt;code&amp;gt;LivingEntity&amp;lt;/code&amp;gt;, only &amp;lt;code&amp;gt;Entity&amp;lt;/code&amp;gt;.}}&lt;br /&gt;
&lt;br /&gt;
== Cancelling ==&lt;br /&gt;
&lt;br /&gt;
If an event can be cancelled, it will be marked with the &amp;lt;code&amp;gt;@Cancelable&amp;lt;/code&amp;gt; annotation, and the method &amp;lt;code&amp;gt;Event#isCancelable()&amp;lt;/code&amp;gt; will return &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;. The cancel state of a cancellable event may be modified by calling &amp;lt;code&amp;gt;Event#setCanceled(boolean canceled)&amp;lt;/code&amp;gt;, wherein passing the boolean value &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; is interpreted as cancelling the event, and passing the boolean value &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; is interpreted as “un-cancelling” the event.&lt;br /&gt;
&lt;br /&gt;
{{Tip/Important|Not all events can be cancelled! Attempting to cancel an event that is not cancellable will result in an unchecked &amp;lt;code&amp;gt;UnsupportedOperationException&amp;lt;/code&amp;gt; being thrown, which is expected to result in the game crashing. Always check that an event can be cancelled using &amp;lt;code&amp;gt;Event#isCancelable()&amp;lt;/code&amp;gt; before attempting to cancel it.}}&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
Some events have an &amp;lt;code&amp;gt;Event.Result&amp;lt;/code&amp;gt; as denoted by &amp;lt;code&amp;gt;@HasResult&amp;lt;/code&amp;gt;. A result can be one of three things: &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; which stops the event, &amp;lt;code&amp;gt;DEFAULT&amp;lt;/code&amp;gt; which uses the Vanilla behavior, and &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; which forces the action to take place, regardless of if it would have originally. The result of an event can be set by calling &amp;lt;code&amp;gt;setResult&amp;lt;/code&amp;gt; with an Event.Result on the event.&lt;br /&gt;
&lt;br /&gt;
{{Colored box|title=Information|content=Different events may use results in different ways, refer to the event's JavaDoc before using the result.}}&lt;br /&gt;
&lt;br /&gt;
== Priority ==&lt;br /&gt;
&lt;br /&gt;
Event handler methods have a priority. You can set the &amp;lt;code&amp;gt;priority&amp;lt;/code&amp;gt; of an event handler method by setting the priority value of the annotation or the listener. The priority can be any value of the &amp;lt;code&amp;gt;EventPriority&amp;lt;/code&amp;gt; enum (&amp;lt;code&amp;gt;HIGHEST&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;HIGH&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;NORMAL&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LOW&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;LOWEST&amp;lt;/code&amp;gt;). Event handlers with priority &amp;lt;code&amp;gt;HIGHEST&amp;lt;/code&amp;gt; are executed first and from there in descending order until &amp;lt;code&amp;gt;LOWEST&amp;lt;/code&amp;gt; events which are executed last.&lt;br /&gt;
&lt;br /&gt;
== Mod Event Bus ==&lt;br /&gt;
The mod event bus is primarily used for listening to lifecycle events in which mods should initialize. Many of these events are also ran in parallel so mods can be initialized at the same time. This does mean you cannot directly execute code from other mods in these events. Use the &amp;lt;code&amp;gt;InterModComms&amp;lt;/code&amp;gt; system for that.&lt;br /&gt;
&lt;br /&gt;
It is impossible for an event to be posted on the Mod bus that does not inherit the IModBusEvent interface.&lt;br /&gt;
Thus, this provides a good, easy way to tell which events are fired on this bus.&lt;br /&gt;
&lt;br /&gt;
These are the four most commonly used lifecycle events that are called during mod initialization on the mod event bus: &lt;br /&gt;
* &amp;lt;code&amp;gt;FMLCommonSetupEvent&amp;lt;/code&amp;gt; &lt;br /&gt;
* &amp;lt;code&amp;gt;FMLClientSetupEvent&amp;lt;/code&amp;gt; &amp;amp; &amp;lt;code&amp;gt;FMLDedicatedServerSetupEvent&amp;lt;/code&amp;gt; (''These events are only called on their respective [[Sides#Different_Kinds_of_Sides|physical side]].'')&lt;br /&gt;
* &amp;lt;code&amp;gt;InterModEnqueueEvent&amp;lt;/code&amp;gt; &lt;br /&gt;
* &amp;lt;code&amp;gt;InterModProcessEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These four lifecycle events are all ran in parallel. If you want to run code on the main thread during these events you can use the &amp;lt;code&amp;gt;enqueueWork&amp;lt;/code&amp;gt; methods within the events to do so.&lt;br /&gt;
&lt;br /&gt;
Next to the lifecycle events there are a few miscellaneous events that are fired on the mod event bus where you can register, set up, or initialize various things. Most of these events are not ran in parallel in contrast to the lifecycle events:&lt;br /&gt;
* &amp;lt;code&amp;gt;ColorHandlerEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;ModelBakeEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;TextureStitchEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;RegistryEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GatherDataEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;SoundLoadEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;ParticleFactoryRegisterEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;ModConfigEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A good rule of thumb: events are fired on the mod event bus when they should be handled during initialization of a mod. or where they are used to set state (eg. the config event.)&lt;br /&gt;
&lt;br /&gt;
Detailed information about these events will be found in their respective pages, once they are ready.&lt;br /&gt;
&lt;br /&gt;
== Forge Event Bus ==&lt;br /&gt;
The Forge event bus is where game state events are fired. If anything changes to do with the game, or anything happens that you would need to know about, there's a good chance it's sent here.&lt;br /&gt;
&lt;br /&gt;
A full list of the events fired here is as follows, split into discrete categories:&lt;br /&gt;
&lt;br /&gt;
{{Tree list}}&lt;br /&gt;
* &amp;lt;code&amp;gt;Event&amp;lt;/code&amp;gt; - ''The root event class''&lt;br /&gt;
** '''Rendering events''' ('''client-only''')&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderWorldLastEvent&amp;lt;/code&amp;gt; - Fired after world rendering to allow mods to add custom renders&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderHandEvent&amp;lt;/code&amp;gt; - Fired before and after the hand of the player is rendered in the first person POV&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderLivingEvent&amp;lt;/code&amp;gt; - Fired before and after a &amp;lt;code&amp;gt;LivingRenderer&amp;lt;/code&amp;gt; is executed&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderItemInFrameEvent&amp;lt;/code&amp;gt; - Fired before the item in an &amp;lt;code&amp;gt;ItemFrameEntity&amp;lt;/code&amp;gt; is rendered&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderBlockOverlayEvent&amp;lt;/code&amp;gt; - Fired before the block overlay for the player's screen is rendered&lt;br /&gt;
*** &amp;lt;code&amp;gt;DrawHighlightEvent&amp;lt;/code&amp;gt; - Fired before the block highlight outline is rendered&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderTooltipEvent&amp;lt;/code&amp;gt; - Fired before and during rendering of a text tooltip on a screen&lt;br /&gt;
*** &amp;lt;code&amp;gt;EntityViewRenderEvent&amp;lt;/code&amp;gt; - Superclass for events relating to the player's viewpoint&lt;br /&gt;
*** &amp;lt;code&amp;gt;RenderGameOverlayEvent&amp;lt;/code&amp;gt; - Superclass, fired for each element on the player's HUD or game overlay&lt;br /&gt;
*** &amp;lt;code&amp;gt;FOVUpdateEvent&amp;lt;/code&amp;gt; - Fired when the FOV of the player is requested (?)&lt;br /&gt;
** '''GUI/Screen events''' ('''client-only''')&lt;br /&gt;
*** &amp;lt;code&amp;gt;GuiScreenEvent&amp;lt;/code&amp;gt; - Superclass for events relating to &amp;lt;code&amp;gt;Screen&amp;lt;/code&amp;gt;s&lt;br /&gt;
*** &amp;lt;code&amp;gt;GuiContainerEvent&amp;lt;/code&amp;gt; - Superclsas for events relating to &amp;lt;code&amp;gt;ContainerScreen&amp;lt;/code&amp;gt;s&lt;br /&gt;
*** &amp;lt;code&amp;gt;GuiOpenEvent&amp;lt;/code&amp;gt; - Fired before a new screen is opened on the game window&lt;br /&gt;
** '''Superclass events''' - ''These events exist to be superclasses of other events''&lt;br /&gt;
*** &amp;lt;code&amp;gt;GenericEvent&amp;lt;/code&amp;gt; - ''from EventBus'', superclass of events which have a generic type&lt;br /&gt;
*** &amp;lt;code&amp;gt;[[Events/BlockEvent|BlockEvent]]&amp;lt;/code&amp;gt; - Superclass for events relating to a block within the world&lt;br /&gt;
*** &amp;lt;code&amp;gt;WorldEvent&amp;lt;/code&amp;gt; - Superclass for events relating to the world&lt;br /&gt;
*** &amp;lt;code&amp;gt;InputEvent&amp;lt;/code&amp;gt; - ('''client-only''') Superclass for events relating to the player's keyboard and mouse inputs&lt;br /&gt;
*** &amp;lt;code&amp;gt;NetworkEvent&amp;lt;/code&amp;gt; - Superclass for events relating to networking&lt;br /&gt;
*** &amp;lt;code&amp;gt;ExplosionEvent&amp;lt;/code&amp;gt; - Fired before an explosion explodes in the world&lt;br /&gt;
*** &amp;lt;code&amp;gt;SoundEvent&amp;lt;/code&amp;gt; - ('''client-only''') Superclass for events related to sounds&lt;br /&gt;
*** &amp;lt;code&amp;gt;EntityEvent&amp;lt;/code&amp;gt; - Superclass for events relating to entities&lt;br /&gt;
*** &amp;lt;code&amp;gt;TickEvent&amp;lt;/code&amp;gt; - Superclass for events fired before and after ticking&lt;br /&gt;
** '''Chat events'''&lt;br /&gt;
*** &amp;lt;code&amp;gt;ServerChatEvent&amp;lt;/code&amp;gt; ('''server-only''') - Fired when the server receives a chat message and before it relays the message&lt;br /&gt;
*** &amp;lt;code&amp;gt;ClientChatEvent&amp;lt;/code&amp;gt; ('''client-only''') - Fired before the client is about to send a chat message&lt;br /&gt;
*** &amp;lt;code&amp;gt;ClientChatReceivedEvent&amp;lt;/code&amp;gt; ('''client-only''') - Fired when the client receives a chat message from the server&lt;br /&gt;
** '''Data loading events'''&lt;br /&gt;
*** &amp;lt;code&amp;gt;RecipesUpdatedEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;BiomeLoadingEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;LootTableLoadEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;StructureSpawnListGatherEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
** '''Startup events'''&lt;br /&gt;
*** &amp;lt;code&amp;gt;AddReloadListenerEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;RegisterCommandsEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ServerLifecycleEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
** '''Gamemode events'''&lt;br /&gt;
*** &amp;lt;code&amp;gt;DifficultyChangeEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ClientPlayerChangeGamemodeEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
**'''Trade events'''&lt;br /&gt;
*** &amp;lt;code&amp;gt;WandererTradesEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;VillagerTradesEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
** '''Other events'''&lt;br /&gt;
*** &amp;lt;code&amp;gt;FurnaceFuelBurnTimeEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;BabyEntitySpawnEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;VillageSiegeEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;TagsUpdatedEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;PotionBrewEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ScreenshotEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;EnchantmentLevelSetEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;CommandEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;AnvilUpdateEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ItemAttributeModifierEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ClientPlayerNetworkEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ChunkWatchEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
{{Tree list/end}}&lt;br /&gt;
&lt;br /&gt;
Like before, each of these events (especially the Super Events, which contain most of the useful events in the game) will have their own article explaining their purpose and usefulness.&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;/div&gt;</summary>
		<author><name>EERussianguy</name></author>
	</entry>
	<entry>
		<id>https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2571</id>
		<title>Events/BlockEvent</title>
		<link rel="alternate" type="text/html" href="https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2571"/>
		<updated>2021-04-20T13:32:04Z</updated>

		<summary type="html">&lt;p&gt;EERussianguy: no tag check&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The variations of &amp;lt;code&amp;gt;BlockEvent&amp;lt;/code&amp;gt; let modders intercept interactions between the player and blocks in the world. All of these events have in common the following: the &amp;lt;code&amp;gt;World&amp;lt;/code&amp;gt; the action was taken in, and the &amp;lt;code&amp;gt;BlockPos&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that's being modified.&lt;br /&gt;
&lt;br /&gt;
== BreakEvent ==&lt;br /&gt;
This event is fired before a block is broken by a player. Predictably, cancelling this event prevents the block from getting broken. Modders have two extra variables to play with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getExpToDrop()&amp;lt;/code&amp;gt;: Returns how much experience ought to drop when the block is broken. Will be zero if the event is currently canceled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setExpToDrop()&amp;lt;/code&amp;gt;: Sets the experience that's going to drop manually.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlayer()&amp;lt;/code&amp;gt;: Gets the player that's doing the action.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onBlockBreak(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getState().is(Blocks.SAND)) // use the base event to get the state and see what it is&lt;br /&gt;
        {&lt;br /&gt;
            event.setExpToDrop(10); // change the amount of experience we'll be dropping&lt;br /&gt;
            PlayerEntity player = event.getPlayer();&lt;br /&gt;
            if (player.getUseItem().getItem().is(Tags.Items.SHEARS)) // check if the player is holding shears&lt;br /&gt;
            {&lt;br /&gt;
                ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(Items.BONE)); // give a bone to the player!&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Stopping players from breaking a block&lt;br /&gt;
* Changing the XP drop of a vanilla block&lt;br /&gt;
* Modify the behavior of a tool&lt;br /&gt;
&lt;br /&gt;
== EntityPlaceEvent ==&lt;br /&gt;
This event is called when a block is placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt;: This is the entity placing the block. Note that this might not be a player! It can be null. This means you should null check the entity. By default, Forge adds this in three places: players placing blocks, endermen placing their held block, as well as ice placed by the Frost Walker enchantment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getBlockSnapshot()&amp;lt;/code&amp;gt;: Gets the snapshot of what's about to be placed. A &amp;lt;code&amp;gt;BlockSnapshot&amp;lt;/code&amp;gt; is just an object containing the dimension, position, NBT, and state of a block, along with some other info. Typically, this isn't necessary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedBlock()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedAgainst()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that was clicked in order to place the block. Imagine planting a flower on some dirt. The dirt would be the state here.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onEntityPlace(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        Entity entity = event.getEntity();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; entity != null) // check if the entity is null&lt;br /&gt;
        {&lt;br /&gt;
            Block block = event.getState().getBlock(); // get the block that was placed&lt;br /&gt;
            if (entity instanceof PlayerEntity &amp;amp;&amp;amp; block.is(Blocks.FROSTED_ICE))&lt;br /&gt;
            {&lt;br /&gt;
                event.setCanceled(true); // cancel the placing&lt;br /&gt;
                event.getWorld().setBlock(event.getPos(), Blocks.COBBLESTONE.defaultBlockState(), 3); // set cobble instead&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* (See above) Changing how frost walker works based on certain conditions&lt;br /&gt;
* Preventing a block from being placed&lt;br /&gt;
* Changing the player's inventory when a block is placed&lt;br /&gt;
* Cause another block to be placed instead of another&lt;br /&gt;
&lt;br /&gt;
== EntityMultiPlaceEvent ==&lt;br /&gt;
This is the same as above except it's fired when a block causes another block to be replaced. A great example is beds, where placing one half of the bed causes another half to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getReplacedBlockSnapshots()&amp;lt;/code&amp;gt;: Everything is the same as before, except we now have a list of snapshots. How sweet.&lt;br /&gt;
&lt;br /&gt;
== NeighborNotifyEvent ==&lt;br /&gt;
This event is fired when a block tells its neighbors to update themselves. This happens all the time, typically with redstone blocks like tripwires or repeaters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNotifiedSides()&amp;lt;/code&amp;gt;: A set of &amp;lt;code&amp;gt;Direction&amp;lt;/code&amp;gt; values that were updated during the event. Sometimes, blocks will choose to exclude a side from being updated, but most often this will be all six directions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getForceRedstoneUpdate()&amp;lt;/code&amp;gt; This is a little funky. There's an option when blocks are set to force a redstone update. If that happened, this will be true. You typically won't need this.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onNeighborNotify(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockPos eventPos = event.getPos();&lt;br /&gt;
        for (Direction direction : event.getNotifiedSides()) // cycle through notified directions&lt;br /&gt;
        {&lt;br /&gt;
            BlockPos pos = eventPos.relative(direction); // move to the direction given&lt;br /&gt;
            double x = pos.getX() + 0.5D; // move to center of the block&lt;br /&gt;
            double y = pos.getY() + 0.5D;&lt;br /&gt;
            double z = pos.getZ() + 0.5D;&lt;br /&gt;
            // add particle&lt;br /&gt;
            event.getWorld().addParticle(ParticleTypes.CLOUD, x, y, z, 0.0D, 0.0D, 0.0D);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Adding blocks that interact with redstone&lt;br /&gt;
* Making a block update detector block&lt;br /&gt;
&lt;br /&gt;
== CreateFluidSourceEvent ==&lt;br /&gt;
This event controls creation of fluid sources. This is different than cancellable events, because it has a &amp;lt;code&amp;gt;Result&amp;lt;/code&amp;gt;. Setting it to &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; causes a source block to created, even if that's not normally what would happen. Setting it to &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; always prevents source creation.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onNeighborNotify(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getPos().getY() &amp;gt; 100)&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent source creation above y = 100&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== FluidPlaceBlockEvent ==&lt;br /&gt;
This event fires when fluids place blocks. Examples of this happening are: basalt, stone, cobblestone, obsidian, and fire (think lava pools). You can cancel this event to prevent placement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getLiquidPos()&amp;lt;/code&amp;gt; This is the liquid's position. For cases like cobble generation, this is the same as the original &amp;lt;code&amp;gt;getPos()&amp;lt;/code&amp;gt;. But for placing fire, this won't be the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNewState()&amp;lt;/code&amp;gt; Gets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setNewState()&amp;lt;/code&amp;gt; Sets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; What the block was before this event.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onBreak(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockState newState = event.getNewState();&lt;br /&gt;
        if (newState.is(Blocks.FIRE))&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // prevent fire placing from lava&lt;br /&gt;
        }&lt;br /&gt;
        else if (newState.is(Blocks.COBBLESTONE) &amp;amp;&amp;amp; event.getWorld().dayTime() &amp;gt; 14000L)&lt;br /&gt;
        {&lt;br /&gt;
            event.setNewState(Blocks.ANDESITE.defaultBlockState()); // change the block if done during nighttime.&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing behavior of cobble generators&lt;br /&gt;
* Preventing cobble generators&lt;br /&gt;
* Adding more aggressive effects during fire spreading from lava&lt;br /&gt;
&lt;br /&gt;
== CropGrowEvent ==&lt;br /&gt;
These events are fired during crop growth. The &amp;lt;code&amp;gt;Pre&amp;lt;/code&amp;gt; event is fired before. It's fired when vanilla blocks try to  'grow' during random ticks (think cacti getting taller). Setting &amp;lt;code&amp;gt;DEFAULT&amp;lt;/code&amp;gt; as the result will cause no change. Setting &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; forces growth. Setting &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; prevents growth.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Post&amp;lt;/code&amp;gt; event is fired after growth.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; Get the state before growth happened.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onCropGrowPre(final BlockEvent.CropGrowEvent.Pre event)&lt;br /&gt;
    {&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockState state = event.getState();&lt;br /&gt;
        if (state.is(Blocks.WHEAT))&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent wheat from growing&lt;br /&gt;
        }&lt;br /&gt;
        else if (state.is(Blocks.BAMBOO))&lt;br /&gt;
        {&lt;br /&gt;
            if (event.getWorld().getRandom().nextFloat() &amp;gt; 0.2F) // take a 4/5 chance&lt;br /&gt;
            {&lt;br /&gt;
                event.setResult(Event.Result.DENY); // make bamboo grow less often&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing growth rate of crops&lt;br /&gt;
* Preventing crop growth under certain conditions&lt;br /&gt;
* Spawning an entity when something grows&lt;br /&gt;
&lt;br /&gt;
== FarmlandTrampleEvent ==&lt;br /&gt;
This event is fired when farmland gets trampled. You can cancel it to prevent trampling.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt; The entity that trampled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFallDistance()&amp;lt;/code&amp;gt; How far that entity fell&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onTrample(final BlockEvent.FarmlandTrampleEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getFallDistance() &amp;lt; 10.0F)&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // change conditions for trampling&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PortalSpawnEvent ==&lt;br /&gt;
This event is fired when a nether portal is created.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPortalSize()&amp;lt;/code&amp;gt; returns a &amp;lt;code&amp;gt;PortalSize&amp;lt;/code&amp;gt; object, basically only useful for determining if the portal is going to be valid or not.&lt;br /&gt;
&lt;br /&gt;
This is mostly used for preventing portal spawning in certain dimensions (even the overworld).&lt;br /&gt;
&lt;br /&gt;
== BlockToolInteractEvent ==&lt;br /&gt;
This event is fired on right click tool events, such as path creation, wood stripping, and farmland tilling. You have access to the player, the &amp;lt;code&amp;gt;ItemStack&amp;lt;/code&amp;gt; they're holding, and the &amp;lt;code&amp;gt;ToolType&amp;lt;/code&amp;gt; they have.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setFinalState()&amp;lt;/code&amp;gt;: Set what you want the result to be.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFinalState()&amp;lt;/code&amp;gt;: Returns what it will be changed to.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onToolInteract(final BlockEvent.BlockToolInteractEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getFinalState().is(Blocks.FARMLAND) &amp;amp;&amp;amp; event.getHeldItemStack().getItem() == Items.NETHERITE_HOE)&lt;br /&gt;
        {&lt;br /&gt;
            event.setFinalState(Blocks.NETHERRACK.defaultBlockState()); // change the final state under certain conditions&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this:&lt;br /&gt;
* Setting your custom farmland block during tilling&lt;br /&gt;
* Adding stripped wood behavior for other blocks&lt;br /&gt;
* Disable path creation&lt;/div&gt;</summary>
		<author><name>EERussianguy</name></author>
	</entry>
	<entry>
		<id>https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2570</id>
		<title>Events/BlockEvent</title>
		<link rel="alternate" type="text/html" href="https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2570"/>
		<updated>2021-04-20T13:31:14Z</updated>

		<summary type="html">&lt;p&gt;EERussianguy: add client checks&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The variations of &amp;lt;code&amp;gt;BlockEvent&amp;lt;/code&amp;gt; let modders intercept interactions between the player and blocks in the world. All of these events have in common the following: the &amp;lt;code&amp;gt;World&amp;lt;/code&amp;gt; the action was taken in, and the &amp;lt;code&amp;gt;BlockPos&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that's being modified.&lt;br /&gt;
&lt;br /&gt;
== BreakEvent ==&lt;br /&gt;
This event is fired before a block is broken by a player. Predictably, cancelling this event prevents the block from getting broken. Modders have two extra variables to play with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getExpToDrop()&amp;lt;/code&amp;gt;: Returns how much experience ought to drop when the block is broken. Will be zero if the event is currently canceled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setExpToDrop()&amp;lt;/code&amp;gt;: Sets the experience that's going to drop manually.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlayer()&amp;lt;/code&amp;gt;: Gets the player that's doing the action.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onBlockBreak(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getState().is(Tags.Blocks.SAND)) // use the base event to get the state and see what it is&lt;br /&gt;
        {&lt;br /&gt;
            event.setExpToDrop(10); // change the amount of experience we'll be dropping&lt;br /&gt;
            PlayerEntity player = event.getPlayer();&lt;br /&gt;
            if (player.getUseItem().getItem().is(Tags.Items.SHEARS)) // check if the player is holding shears&lt;br /&gt;
            {&lt;br /&gt;
                ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(Items.BONE)); // give a bone to the player!&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Stopping players from breaking a block&lt;br /&gt;
* Changing the XP drop of a vanilla block&lt;br /&gt;
* Modify the behavior of a tool&lt;br /&gt;
&lt;br /&gt;
== EntityPlaceEvent ==&lt;br /&gt;
This event is called when a block is placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt;: This is the entity placing the block. Note that this might not be a player! It can be null. This means you should null check the entity. By default, Forge adds this in three places: players placing blocks, endermen placing their held block, as well as ice placed by the Frost Walker enchantment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getBlockSnapshot()&amp;lt;/code&amp;gt;: Gets the snapshot of what's about to be placed. A &amp;lt;code&amp;gt;BlockSnapshot&amp;lt;/code&amp;gt; is just an object containing the dimension, position, NBT, and state of a block, along with some other info. Typically, this isn't necessary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedBlock()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedAgainst()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that was clicked in order to place the block. Imagine planting a flower on some dirt. The dirt would be the state here.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onEntityPlace(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        Entity entity = event.getEntity();&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; entity != null) // check if the entity is null&lt;br /&gt;
        {&lt;br /&gt;
            Block block = event.getState().getBlock(); // get the block that was placed&lt;br /&gt;
            if (entity instanceof PlayerEntity &amp;amp;&amp;amp; block.is(Blocks.FROSTED_ICE))&lt;br /&gt;
            {&lt;br /&gt;
                event.setCanceled(true); // cancel the placing&lt;br /&gt;
                event.getWorld().setBlock(event.getPos(), Blocks.COBBLESTONE.defaultBlockState(), 3); // set cobble instead&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* (See above) Changing how frost walker works based on certain conditions&lt;br /&gt;
* Preventing a block from being placed&lt;br /&gt;
* Changing the player's inventory when a block is placed&lt;br /&gt;
* Cause another block to be placed instead of another&lt;br /&gt;
&lt;br /&gt;
== EntityMultiPlaceEvent ==&lt;br /&gt;
This is the same as above except it's fired when a block causes another block to be replaced. A great example is beds, where placing one half of the bed causes another half to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getReplacedBlockSnapshots()&amp;lt;/code&amp;gt;: Everything is the same as before, except we now have a list of snapshots. How sweet.&lt;br /&gt;
&lt;br /&gt;
== NeighborNotifyEvent ==&lt;br /&gt;
This event is fired when a block tells its neighbors to update themselves. This happens all the time, typically with redstone blocks like tripwires or repeaters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNotifiedSides()&amp;lt;/code&amp;gt;: A set of &amp;lt;code&amp;gt;Direction&amp;lt;/code&amp;gt; values that were updated during the event. Sometimes, blocks will choose to exclude a side from being updated, but most often this will be all six directions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getForceRedstoneUpdate()&amp;lt;/code&amp;gt; This is a little funky. There's an option when blocks are set to force a redstone update. If that happened, this will be true. You typically won't need this.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onNeighborNotify(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockPos eventPos = event.getPos();&lt;br /&gt;
        for (Direction direction : event.getNotifiedSides()) // cycle through notified directions&lt;br /&gt;
        {&lt;br /&gt;
            BlockPos pos = eventPos.relative(direction); // move to the direction given&lt;br /&gt;
            double x = pos.getX() + 0.5D; // move to center of the block&lt;br /&gt;
            double y = pos.getY() + 0.5D;&lt;br /&gt;
            double z = pos.getZ() + 0.5D;&lt;br /&gt;
            // add particle&lt;br /&gt;
            event.getWorld().addParticle(ParticleTypes.CLOUD, x, y, z, 0.0D, 0.0D, 0.0D);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Adding blocks that interact with redstone&lt;br /&gt;
* Making a block update detector block&lt;br /&gt;
&lt;br /&gt;
== CreateFluidSourceEvent ==&lt;br /&gt;
This event controls creation of fluid sources. This is different than cancellable events, because it has a &amp;lt;code&amp;gt;Result&amp;lt;/code&amp;gt;. Setting it to &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; causes a source block to created, even if that's not normally what would happen. Setting it to &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; always prevents source creation.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onNeighborNotify(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getPos().getY() &amp;gt; 100)&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent source creation above y = 100&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== FluidPlaceBlockEvent ==&lt;br /&gt;
This event fires when fluids place blocks. Examples of this happening are: basalt, stone, cobblestone, obsidian, and fire (think lava pools). You can cancel this event to prevent placement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getLiquidPos()&amp;lt;/code&amp;gt; This is the liquid's position. For cases like cobble generation, this is the same as the original &amp;lt;code&amp;gt;getPos()&amp;lt;/code&amp;gt;. But for placing fire, this won't be the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNewState()&amp;lt;/code&amp;gt; Gets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setNewState()&amp;lt;/code&amp;gt; Sets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; What the block was before this event.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onBreak(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockState newState = event.getNewState();&lt;br /&gt;
        if (newState.is(Blocks.FIRE))&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // prevent fire placing from lava&lt;br /&gt;
        }&lt;br /&gt;
        else if (newState.is(Blocks.COBBLESTONE) &amp;amp;&amp;amp; event.getWorld().dayTime() &amp;gt; 14000L)&lt;br /&gt;
        {&lt;br /&gt;
            event.setNewState(Blocks.ANDESITE.defaultBlockState()); // change the block if done during nighttime.&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing behavior of cobble generators&lt;br /&gt;
* Preventing cobble generators&lt;br /&gt;
* Adding more aggressive effects during fire spreading from lava&lt;br /&gt;
&lt;br /&gt;
== CropGrowEvent ==&lt;br /&gt;
These events are fired during crop growth. The &amp;lt;code&amp;gt;Pre&amp;lt;/code&amp;gt; event is fired before. It's fired when vanilla blocks try to  'grow' during random ticks (think cacti getting taller). Setting &amp;lt;code&amp;gt;DEFAULT&amp;lt;/code&amp;gt; as the result will cause no change. Setting &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; forces growth. Setting &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; prevents growth.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Post&amp;lt;/code&amp;gt; event is fired after growth.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; Get the state before growth happened.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onCropGrowPre(final BlockEvent.CropGrowEvent.Pre event)&lt;br /&gt;
    {&lt;br /&gt;
        if (world.isClientSide()) return;&lt;br /&gt;
        BlockState state = event.getState();&lt;br /&gt;
        if (state.is(Blocks.WHEAT))&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent wheat from growing&lt;br /&gt;
        }&lt;br /&gt;
        else if (state.is(Blocks.BAMBOO))&lt;br /&gt;
        {&lt;br /&gt;
            if (event.getWorld().getRandom().nextFloat() &amp;gt; 0.2F) // take a 4/5 chance&lt;br /&gt;
            {&lt;br /&gt;
                event.setResult(Event.Result.DENY); // make bamboo grow less often&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing growth rate of crops&lt;br /&gt;
* Preventing crop growth under certain conditions&lt;br /&gt;
* Spawning an entity when something grows&lt;br /&gt;
&lt;br /&gt;
== FarmlandTrampleEvent ==&lt;br /&gt;
This event is fired when farmland gets trampled. You can cancel it to prevent trampling.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt; The entity that trampled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFallDistance()&amp;lt;/code&amp;gt; How far that entity fell&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onTrample(final BlockEvent.FarmlandTrampleEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getFallDistance() &amp;lt; 10.0F)&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // change conditions for trampling&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PortalSpawnEvent ==&lt;br /&gt;
This event is fired when a nether portal is created.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPortalSize()&amp;lt;/code&amp;gt; returns a &amp;lt;code&amp;gt;PortalSize&amp;lt;/code&amp;gt; object, basically only useful for determining if the portal is going to be valid or not.&lt;br /&gt;
&lt;br /&gt;
This is mostly used for preventing portal spawning in certain dimensions (even the overworld).&lt;br /&gt;
&lt;br /&gt;
== BlockToolInteractEvent ==&lt;br /&gt;
This event is fired on right click tool events, such as path creation, wood stripping, and farmland tilling. You have access to the player, the &amp;lt;code&amp;gt;ItemStack&amp;lt;/code&amp;gt; they're holding, and the &amp;lt;code&amp;gt;ToolType&amp;lt;/code&amp;gt; they have.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setFinalState()&amp;lt;/code&amp;gt;: Set what you want the result to be.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFinalState()&amp;lt;/code&amp;gt;: Returns what it will be changed to.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onToolInteract(final BlockEvent.BlockToolInteractEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (!world.isClientSide() &amp;amp;&amp;amp; event.getFinalState().is(Blocks.FARMLAND) &amp;amp;&amp;amp; event.getHeldItemStack().getItem() == Items.NETHERITE_HOE)&lt;br /&gt;
        {&lt;br /&gt;
            event.setFinalState(Blocks.NETHERRACK.defaultBlockState()); // change the final state under certain conditions&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this:&lt;br /&gt;
* Setting your custom farmland block during tilling&lt;br /&gt;
* Adding stripped wood behavior for other blocks&lt;br /&gt;
* Disable path creation&lt;/div&gt;</summary>
		<author><name>EERussianguy</name></author>
	</entry>
	<entry>
		<id>https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2569</id>
		<title>Events/BlockEvent</title>
		<link rel="alternate" type="text/html" href="https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2569"/>
		<updated>2021-04-20T01:10:53Z</updated>

		<summary type="html">&lt;p&gt;EERussianguy: couple issues&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The variations of &amp;lt;code&amp;gt;BlockEvent&amp;lt;/code&amp;gt; let modders intercept interactions between the player and blocks in the world. All of these events have in common the following: the &amp;lt;code&amp;gt;World&amp;lt;/code&amp;gt; the action was taken in, and the &amp;lt;code&amp;gt;BlockPos&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that's being modified.&lt;br /&gt;
&lt;br /&gt;
== BreakEvent ==&lt;br /&gt;
This event is fired before a block is broken by a player. Predictably, cancelling this event prevents the block from getting broken. Modders have two extra variables to play with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getExpToDrop()&amp;lt;/code&amp;gt;: Returns how much experience ought to drop when the block is broken. Will be zero if the event is currently canceled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setExpToDrop()&amp;lt;/code&amp;gt;: Sets the experience that's going to drop manually.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlayer()&amp;lt;/code&amp;gt;: Gets the player that's doing the action.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onBlockBreak(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (event.getState().is(Tags.Blocks.SAND)) // use the base event to get the state and see what it is&lt;br /&gt;
        {&lt;br /&gt;
            event.setExpToDrop(10); // change the amount of experience we'll be dropping&lt;br /&gt;
            PlayerEntity player = event.getPlayer();&lt;br /&gt;
            if (player.getUseItem().getItem().is(Tags.Items.SHEARS)) // check if the player is holding shears&lt;br /&gt;
            {&lt;br /&gt;
                ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(Items.BONE)); // give a bone to the player!&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Stopping players from breaking a block&lt;br /&gt;
* Changing the XP drop of a vanilla block&lt;br /&gt;
* Modify the behavior of a tool&lt;br /&gt;
&lt;br /&gt;
== EntityPlaceEvent ==&lt;br /&gt;
This event is called when a block is placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt;: This is the entity placing the block. Note that this might not be a player! It can be null. This means you should null check the entity. By default, Forge adds this in three places: players placing blocks, endermen placing their held block, as well as ice placed by the Frost Walker enchantment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getBlockSnapshot()&amp;lt;/code&amp;gt;: Gets the snapshot of what's about to be placed. A &amp;lt;code&amp;gt;BlockSnapshot&amp;lt;/code&amp;gt; is just an object containing the dimension, position, NBT, and state of a block, along with some other info. Typically, this isn't necessary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedBlock()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedAgainst()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that was clicked in order to place the block. Imagine planting a flower on some dirt. The dirt would be the state here.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onEntityPlace(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        Entity entity = event.getEntity();&lt;br /&gt;
        if (entity != null) // check if the entity is null&lt;br /&gt;
        {&lt;br /&gt;
            Block block = event.getState().getBlock(); // get the block that was placed&lt;br /&gt;
            if (entity instanceof PlayerEntity &amp;amp;&amp;amp; block.is(Blocks.FROSTED_ICE))&lt;br /&gt;
            {&lt;br /&gt;
                event.setCanceled(true); // cancel the placing&lt;br /&gt;
                event.getWorld().setBlock(event.getPos(), Blocks.COBBLESTONE.defaultBlockState(), 3); // set cobble instead&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* (See above) Changing how frost walker works based on certain conditions&lt;br /&gt;
* Preventing a block from being placed&lt;br /&gt;
* Changing the player's inventory when a block is placed&lt;br /&gt;
* Cause another block to be placed instead of another&lt;br /&gt;
&lt;br /&gt;
== EntityMultiPlaceEvent ==&lt;br /&gt;
This is the same as above except it's fired when a block causes another block to be replaced. A great example is beds, where placing one half of the bed causes another half to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getReplacedBlockSnapshots()&amp;lt;/code&amp;gt;: Everything is the same as before, except we now have a list of snapshots. How sweet.&lt;br /&gt;
&lt;br /&gt;
== NeighborNotifyEvent ==&lt;br /&gt;
This event is fired when a block tells its neighbors to update themselves. This happens all the time, typically with redstone blocks like tripwires or repeaters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNotifiedSides()&amp;lt;/code&amp;gt;: A set of &amp;lt;code&amp;gt;Direction&amp;lt;/code&amp;gt; values that were updated during the event. Sometimes, blocks will choose to exclude a side from being updated, but most often this will be all six directions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getForceRedstoneUpdate()&amp;lt;/code&amp;gt; This is a little funky. There's an option when blocks are set to force a redstone update. If that happened, this will be true. You typically won't need this.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onNeighborNotify(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        BlockPos eventPos = event.getPos();&lt;br /&gt;
        for (Direction direction : event.getNotifiedSides()) // cycle through notified directions&lt;br /&gt;
        {&lt;br /&gt;
            BlockPos pos = eventPos.relative(direction); // move to the direction given&lt;br /&gt;
            double x = pos.getX() + 0.5D; // move to center of the block&lt;br /&gt;
            double y = pos.getY() + 0.5D;&lt;br /&gt;
            double z = pos.getZ() + 0.5D;&lt;br /&gt;
            // add particle&lt;br /&gt;
            event.getWorld().addParticle(ParticleTypes.CLOUD, x, y, z, 0.0D, 0.0D, 0.0D);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Adding blocks that interact with redstone&lt;br /&gt;
* Making a block update detector block&lt;br /&gt;
&lt;br /&gt;
== CreateFluidSourceEvent ==&lt;br /&gt;
This event controls creation of fluid sources. This is different than cancellable events, because it has a &amp;lt;code&amp;gt;Result&amp;lt;/code&amp;gt;. Setting it to &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; causes a source block to created, even if that's not normally what would happen. Setting it to &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; always prevents source creation.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onNeighborNotify(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (event.getPos().getY() &amp;gt; 100)&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent source creation above y = 100&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== FluidPlaceBlockEvent ==&lt;br /&gt;
This event fires when fluids place blocks. Examples of this happening are: basalt, stone, cobblestone, obsidian, and fire (think lava pools). You can cancel this event to prevent placement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getLiquidPos()&amp;lt;/code&amp;gt; This is the liquid's position. For cases like cobble generation, this is the same as the original &amp;lt;code&amp;gt;getPos()&amp;lt;/code&amp;gt;. But for placing fire, this won't be the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNewState()&amp;lt;/code&amp;gt; Gets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setNewState()&amp;lt;/code&amp;gt; Sets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; What the block was before this event.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onBreak(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        BlockState newState = event.getNewState();&lt;br /&gt;
        if (newState.is(Blocks.FIRE))&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // prevent fire placing from lava&lt;br /&gt;
        }&lt;br /&gt;
        else if (newState.is(Blocks.COBBLESTONE) &amp;amp;&amp;amp; event.getWorld().dayTime() &amp;gt; 14000L)&lt;br /&gt;
        {&lt;br /&gt;
            event.setNewState(Blocks.ANDESITE.defaultBlockState()); // change the block if done during nighttime.&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing behavior of cobble generators&lt;br /&gt;
* Preventing cobble generators&lt;br /&gt;
* Adding more aggressive effects during fire spreading from lava&lt;br /&gt;
&lt;br /&gt;
== CropGrowEvent ==&lt;br /&gt;
These events are fired during crop growth. The &amp;lt;code&amp;gt;Pre&amp;lt;/code&amp;gt; event is fired before. It's fired when vanilla blocks try to  'grow' during random ticks (think cacti getting taller). Setting &amp;lt;code&amp;gt;DEFAULT&amp;lt;/code&amp;gt; as the result will cause no change. Setting &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; forces growth. Setting &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; prevents growth.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Post&amp;lt;/code&amp;gt; event is fired after growth.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; Get the state before growth happened.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onCropGrowPre(final BlockEvent.CropGrowEvent.Pre event)&lt;br /&gt;
    {&lt;br /&gt;
        BlockState state = event.getState();&lt;br /&gt;
        if (state.is(Blocks.WHEAT))&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent wheat from growing&lt;br /&gt;
        }&lt;br /&gt;
        else if (state.is(Blocks.BAMBOO))&lt;br /&gt;
        {&lt;br /&gt;
            if (event.getWorld().getRandom().nextFloat() &amp;gt; 0.2F) // take a 4/5 chance&lt;br /&gt;
            {&lt;br /&gt;
                event.setResult(Event.Result.DENY); // make bamboo grow less often&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing growth rate of crops&lt;br /&gt;
* Preventing crop growth under certain conditions&lt;br /&gt;
* Spawning an entity when something grows&lt;br /&gt;
&lt;br /&gt;
== FarmlandTrampleEvent ==&lt;br /&gt;
This event is fired when farmland gets trampled. You can cancel it to prevent trampling.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt; The entity that trampled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFallDistance()&amp;lt;/code&amp;gt; How far that entity fell&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onTrample(final BlockEvent.FarmlandTrampleEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (event.getFallDistance() &amp;lt; 10.0F)&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // change conditions for trampling&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PortalSpawnEvent ==&lt;br /&gt;
This event is fired when a nether portal is created.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPortalSize()&amp;lt;/code&amp;gt; returns a &amp;lt;code&amp;gt;PortalSize&amp;lt;/code&amp;gt; object, basically only useful for determining if the portal is going to be valid or not.&lt;br /&gt;
&lt;br /&gt;
This is mostly used for preventing portal spawning in certain dimensions (even the overworld).&lt;br /&gt;
&lt;br /&gt;
== BlockToolInteractEvent ==&lt;br /&gt;
This event is fired on right click tool events, such as path creation, wood stripping, and farmland tilling. You have access to the player, the &amp;lt;code&amp;gt;ItemStack&amp;lt;/code&amp;gt; they're holding, and the &amp;lt;code&amp;gt;ToolType&amp;lt;/code&amp;gt; they have.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setFinalState()&amp;lt;/code&amp;gt;: Set what you want the result to be.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFinalState()&amp;lt;/code&amp;gt;: Returns what it will be changed to.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onToolInteract(final BlockEvent.BlockToolInteractEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (event.getFinalState().is(Blocks.FARMLAND) &amp;amp;&amp;amp; event.getHeldItemStack().getItem() == Items.NETHERITE_HOE)&lt;br /&gt;
        {&lt;br /&gt;
            event.setFinalState(Blocks.NETHERRACK.defaultBlockState()); // change the final state under certain conditions&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this:&lt;br /&gt;
* Setting your custom farmland block during tilling&lt;br /&gt;
* Adding stripped wood behavior for other blocks&lt;br /&gt;
* Disable path creation&lt;/div&gt;</summary>
		<author><name>EERussianguy</name></author>
	</entry>
	<entry>
		<id>https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2568</id>
		<title>Events/BlockEvent</title>
		<link rel="alternate" type="text/html" href="https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2568"/>
		<updated>2021-04-20T01:09:23Z</updated>

		<summary type="html">&lt;p&gt;EERussianguy: fix syntax&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The variations of &amp;lt;code&amp;gt;BlockEvent&amp;lt;/code&amp;gt; let modders intercept interactions between the player and blocks in the world. All of these events have in common the following: the &amp;lt;code&amp;gt;World&amp;lt;/code&amp;gt; the action was taken in, and the &amp;lt;code&amp;gt;BlockPos&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that's being modified.&lt;br /&gt;
&lt;br /&gt;
== BreakEvent ==&lt;br /&gt;
This event is fired before a block is broken by a player. Predictably, cancelling this event prevents the block from getting broken. Modders have two extra variables to play with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getExpToDrop()&amp;lt;/code&amp;gt;: Returns how much experience ought to drop when the block is broken. Will be zero if the event is currently canceled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setExpToDrop()&amp;lt;/code&amp;gt;: Sets the experience that's going to drop manually.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlayer()&amp;lt;/code&amp;gt;: Gets the player that's doing the action.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onBlockBreak(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (event.getState().is(Tags.Blocks.SAND)) // use the base event to get the state and see what it is&lt;br /&gt;
        {&lt;br /&gt;
            event.setExpToDrop(10); // change the amount of experience we'll be dropping&lt;br /&gt;
            PlayerEntity player = event.getPlayer();&lt;br /&gt;
            if (player.getUseItem().getItem().is(Tags.Items.SHEARS)) // check if the player is holding shears&lt;br /&gt;
            {&lt;br /&gt;
                ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(Items.BONE)); // give a bone to the player!&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Stopping players from breaking a block&lt;br /&gt;
* Changing the XP drop of a vanilla block&lt;br /&gt;
* Modify the behavior of a tool&lt;br /&gt;
&lt;br /&gt;
== EntityPlaceEvent ==&lt;br /&gt;
This event is called when a block is placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt;: This is the entity placing the block. Note that this might not be a player! It can be null. This means you should null check the entity. By default, Forge adds this in three places: players placing blocks, endermen placing their held block, as well as ice placed by the Frost Walker enchantment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getBlockSnapshot()&amp;lt;/code&amp;gt;: Gets the snapshot of what's about to be placed. A &amp;lt;code&amp;gt;BlockSnapshot&amp;lt;/code&amp;gt; is just an object containing the dimension, position, NBT, and state of a block, along with some other info. Typically, this isn't necessary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedBlock()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPlacedAgainst()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that was clicked in order to place the block. Imagine planting a flower on some dirt. The dirt would be the state here.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onEntityPlace(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        Entity entity = event.getEntity();&lt;br /&gt;
        if (entity != null) // check if the entity is null&lt;br /&gt;
        {&lt;br /&gt;
            Block block = event.getState().getBlock(); // get the block that was placed&lt;br /&gt;
            if (entity instanceof PlayerEntity &amp;amp;&amp;amp; block.is(Blocks.FROSTED_ICE))&lt;br /&gt;
            {&lt;br /&gt;
                event.setCanceled(true); // cancel the placing&lt;br /&gt;
                event.getWorld().setBlock(event.getPos(), Blocks.COBBLESTONE.defaultBlockState(), 3); // set cobble instead&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* (See above) Changing how frost walker works based on certain conditions&lt;br /&gt;
* Preventing a block from being placed&lt;br /&gt;
* Changing the player's inventory when a block is placed&lt;br /&gt;
* Cause another block to be placed instead of another&lt;br /&gt;
&lt;br /&gt;
== EntityMultiPlaceEvent ==&lt;br /&gt;
This is the same as above except it's fired when a block causes another block to be replaced. A great example is beds, where placing one half of the bed causes another half to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getReplacedBlockSnapshots()&amp;lt;/code&amp;gt;: Everything is the same as before, except we now have a list of snapshots. How sweet.&lt;br /&gt;
&lt;br /&gt;
== NeighborNotifyEvent ==&lt;br /&gt;
This event is fired when a block tells its neighbors to update themselves. This happens all the time, typically with redstone blocks like tripwires or repeaters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNotifiedSides()&amp;lt;/code&amp;gt;: A set of &amp;lt;code&amp;gt;Direction&amp;lt;/code&amp;gt; values that were updated during the event. Sometimes, blocks will choose to exclude a side from being updated, but most often this will be all six directions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getForceRedstoneUpdate()&amp;lt;/code&amp;gt; This is a little funky. There's an option when blocks are set to force a redstone update. If that happened, this will be true. You typically won't need this.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onNeighborNotify(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        BlockPos eventPos = event.getPos();&lt;br /&gt;
        for (Direction direction : event.getNotifiedSides()) // cycle through notified directions&lt;br /&gt;
        {&lt;br /&gt;
            BlockPos pos = eventPos.relative(direction); // move to the direction given&lt;br /&gt;
            double x = pos.getX() + 0.5D; // move to center of the block&lt;br /&gt;
            double y = pos.getY() + 0.5D;&lt;br /&gt;
            double z = pos.getZ() + 0.5D;&lt;br /&gt;
            // add particle&lt;br /&gt;
            event.getWorld().addParticle(ParticleTypes.CLOUD, x, y, z, 0.0D, 0.0D, 0.0D);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Adding blocks that interact with redstone&lt;br /&gt;
* Making a block update detector block&lt;br /&gt;
&lt;br /&gt;
== CreateFluidSourceEvent ==&lt;br /&gt;
This event controls creation of fluid sources. This is different than cancellable events, because it has a &amp;lt;code&amp;gt;Result&amp;lt;/code&amp;gt;. Setting it to &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; causes a source block to created, even if that's not normally what would happen. Setting it to &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; always prevents source creation.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onNeighborNotify(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (event.getPos().getY() &amp;gt; 100)&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent source creation above y = 100&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== FluidPlaceBlockEvent ==&lt;br /&gt;
This event fires when fluids place blocks. Examples of this happening are: basalt, stone, cobblestone, obsidian, and fire (think lava pools). You can cancel this event to prevent placement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getLiquidPos()&amp;lt;/code&amp;gt; This is the liquid's position. For cases like cobble generation, this is the same as the original &amp;lt;code&amp;gt;getPos()&amp;lt;/code&amp;gt;. But for placing fire, this won't be the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getNewState()&amp;lt;/code&amp;gt; Gets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setNewState()&amp;lt;/code&amp;gt; Sets the state to be placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; What the block was before this event.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onBreak(final BlockEvent.BreakEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        BlockState newState = event.getNewState();&lt;br /&gt;
        if (newState.is(Blocks.FIRE))&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // prevent fire placing from lava&lt;br /&gt;
        }&lt;br /&gt;
        else if (newState.is(Blocks.COBBLESTONE) &amp;amp;&amp;amp; event.getWorld().dayTime() &amp;gt; 14000L)&lt;br /&gt;
        {&lt;br /&gt;
            event.setNewState(Blocks.ANDESITE.defaultBlockState()); // change the block if done during nighttime.&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing behavior of cobble generators&lt;br /&gt;
* Preventing cobble generators&lt;br /&gt;
* Adding more aggressive effects during fire spreading from lava&lt;br /&gt;
&lt;br /&gt;
== CropGrowEvent ==&lt;br /&gt;
These events are fired during crop growth. The &amp;lt;code&amp;gt;Pre&amp;lt;/code&amp;gt; event is fired before. It's fired when vanilla blocks try to  'grow' during random ticks (think cacti getting taller). Setting &amp;lt;code&amp;gt;DEFAULT&amp;lt;/code&amp;gt; as the result will cause no change. Setting &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; forces growth. Setting &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; prevents growth.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Post&amp;lt;/code&amp;gt; event is fired after growth.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getOriginalState&amp;lt;/code&amp;gt; Get the state before growth happened.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onCropGrowPre(final BlockEvent.CropGrowEvent.Pre event)&lt;br /&gt;
    {&lt;br /&gt;
        BlockState state = event.getState();&lt;br /&gt;
        if (state.is(Blocks.WHEAT))&lt;br /&gt;
        {&lt;br /&gt;
            event.setResult(Event.Result.DENY); // prevent wheat from growing&lt;br /&gt;
        }&lt;br /&gt;
        else if (state.is(Blocks.BAMBOO))&lt;br /&gt;
        {&lt;br /&gt;
            if (event.getWorld().getRandom().nextFloat() &amp;gt; 0.2F) // take a 4/5 chance&lt;br /&gt;
            {&lt;br /&gt;
                event.setResult(Event.Result.DENY); // make bamboo grow less often&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this event:&lt;br /&gt;
* Changing growth rate of crops&lt;br /&gt;
* Preventing crop growth under certain conditions&lt;br /&gt;
* Spawning an entity when something grows&lt;br /&gt;
&lt;br /&gt;
== FarmlandTrampleEvent ==&lt;br /&gt;
This event is fired when farmland gets trampled. You can cancel it to prevent trampling.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt; The entity that trampled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFallDistance()&amp;lt;/code&amp;gt; How far that entity fell&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void onTrample(final BlockEvent.FarmlandTrampleEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (event.getFallDistance() &amp;lt; 10.0F)&lt;br /&gt;
        {&lt;br /&gt;
            event.setCanceled(true); // change conditions for trampling&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PortalSpawnEvent ==&lt;br /&gt;
This event is fired when a nether portal is created.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getPortalSize()&amp;lt;/code&amp;gt; returns a &amp;lt;code&amp;gt;PortalSize&amp;lt;/code&amp;gt; object, basically only useful for determining if the portal is going to be valid or not.&lt;br /&gt;
&lt;br /&gt;
This is mostly used for preventing portal spawning in certain dimensions (even the overworld).&lt;br /&gt;
&lt;br /&gt;
== BlockToolInteractEvent ==&lt;br /&gt;
This event is fired on right click tool events, such as path creation, wood stripping, and farmland tilling. You have access to the player, the &amp;lt;code&amp;gt;ItemStack&amp;lt;/code&amp;gt; they're holding, and the &amp;lt;code&amp;gt;ToolType&amp;lt;/code&amp;gt; they have.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;setFinalState()&amp;lt;/code&amp;gt;: Set what you want the result to be.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;getFinalState()&amp;lt;/code&amp;gt;: Returns what it will be changed to.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public void event(final BlockEvent.BlockToolInteractEvent event)&lt;br /&gt;
    {&lt;br /&gt;
        if (event.getFinalState().is(Blocks.FARMLAND) &amp;amp;&amp;amp; event.getHeldItemStack().getItem() == Items.NETHERITE_HOE)&lt;br /&gt;
        {&lt;br /&gt;
            event.setFinalState(Blocks.NETHERRACK.defaultBlockState()); // change the final state under certain conditions&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some ideas for using this:&lt;br /&gt;
* Setting your custom farmland block during tilling&lt;br /&gt;
* Adding stripped wood behavior for other blocks&lt;br /&gt;
* Disable path creation&lt;/div&gt;</summary>
		<author><name>EERussianguy</name></author>
	</entry>
	<entry>
		<id>https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2567</id>
		<title>Events/BlockEvent</title>
		<link rel="alternate" type="text/html" href="https://forge.gemwire.uk/index.php?title=Events/BlockEvent&amp;diff=2567"/>
		<updated>2021-04-20T01:09:01Z</updated>

		<summary type="html">&lt;p&gt;EERussianguy: create page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The variations of &amp;lt;code&amp;gt;BlockEvent&amp;lt;/code&amp;gt; let modders intercept interactions between the player and blocks in the world. All of these events have in common the following: the &amp;lt;code&amp;gt;World&amp;lt;/code&amp;gt; the action was taken in, and the &amp;lt;code&amp;gt;BlockPos&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that's being modified.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;== BreakEvent ==&amp;lt;br /&amp;gt;This event is fired before a block is broken by a player. Predictably, cancelling this event prevents the block from getting broken. Modders have two extra variables to play with:&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;getExpToDrop()&amp;lt;/code&amp;gt;: Returns how much experience ought to drop when the block is broken. Will be zero if the event is currently canceled.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;setExpToDrop()&amp;lt;/code&amp;gt;: Sets the experience that's going to drop manually.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;getPlayer()&amp;lt;/code&amp;gt;: Gets the player that's doing the action.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Example usage:&amp;lt;br /&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&amp;lt;br /&amp;gt;public void onBlockBreak(final BlockEvent.BreakEvent event)&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; if (event.getState().is(Tags.Blocks.SAND)) // use the base event to get the state and see what it is&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; event.setExpToDrop(10); // change the amount of experience we'll be dropping&amp;lt;br /&amp;gt; PlayerEntity player = event.getPlayer();&amp;lt;br /&amp;gt; if (player.getUseItem().getItem().is(Tags.Items.SHEARS)) // check if the player is holding shears&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(Items.BONE)); // give a bone to the player!&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Some ideas for using this event:&amp;lt;br /&amp;gt;* Stopping players from breaking a block&amp;lt;br /&amp;gt;* Changing the XP drop of a vanilla block&amp;lt;br /&amp;gt;* Modify the behavior of a tool&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;== EntityPlaceEvent ==&amp;lt;br /&amp;gt;This event is called when a block is placed.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt;: This is the entity placing the block. Note that this might not be a player! It can be null. This means you should null check the entity. By default, Forge adds this in three places: players placing blocks, endermen placing their held block, as well as ice placed by the Frost Walker enchantment.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;getBlockSnapshot()&amp;lt;/code&amp;gt;: Gets the snapshot of what's about to be placed. A &amp;lt;code&amp;gt;BlockSnapshot&amp;lt;/code&amp;gt; is just an object containing the dimension, position, NBT, and state of a block, along with some other info. Typically, this isn't necessary.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;getPlacedBlock()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; to be placed.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;getPlacedAgainst()&amp;lt;/code&amp;gt; The &amp;lt;code&amp;gt;BlockState&amp;lt;/code&amp;gt; that was clicked in order to place the block. Imagine planting a flower on some dirt. The dirt would be the state here.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Example usage:&amp;lt;br /&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&amp;lt;br /&amp;gt;public void onEntityPlace(final BlockEvent.BreakEvent event)&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; Entity entity = event.getEntity();&amp;lt;br /&amp;gt; if (entity != null) // check if the entity is null&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; Block block = event.getState().getBlock(); // get the block that was placed&amp;lt;br /&amp;gt; if (entity instanceof PlayerEntity &amp;amp;&amp;amp; block.is(Blocks.FROSTED_ICE))&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; event.setCanceled(true); // cancel the placing&amp;lt;br /&amp;gt; event.getWorld().setBlock(event.getPos(), Blocks.COBBLESTONE.defaultBlockState(), 3); // set cobble instead&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Some ideas for using this event:&amp;lt;br /&amp;gt;* (See above) Changing how frost walker works based on certain conditions&amp;lt;br /&amp;gt;* Preventing a block from being placed&amp;lt;br /&amp;gt;* Changing the player's inventory when a block is placed&amp;lt;br /&amp;gt;* Cause another block to be placed instead of another&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;== EntityMultiPlaceEvent ==&amp;lt;br /&amp;gt;This is the same as above except it's fired when a block causes another block to be replaced. A great example is beds, where placing one half of the bed causes another half to be placed.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;getReplacedBlockSnapshots()&amp;lt;/code&amp;gt;: Everything is the same as before, except we now have a list of snapshots. How sweet.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;== NeighborNotifyEvent ==&amp;lt;br /&amp;gt;This event is fired when a block tells its neighbors to update themselves. This happens all the time, typically with redstone blocks like tripwires or repeaters.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;getNotifiedSides()&amp;lt;/code&amp;gt;: A set of &amp;lt;code&amp;gt;Direction&amp;lt;/code&amp;gt; values that were updated during the event. Sometimes, blocks will choose to exclude a side from being updated, but most often this will be all six directions.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;getForceRedstoneUpdate()&amp;lt;/code&amp;gt; This is a little funky. There's an option when blocks are set to force a redstone update. If that happened, this will be true. You typically won't need this.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Example usage:&amp;lt;br /&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&amp;lt;br /&amp;gt;public void onNeighborNotify(final BlockEvent.BreakEvent event)&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; BlockPos eventPos = event.getPos();&amp;lt;br /&amp;gt; for (Direction direction : event.getNotifiedSides()) // cycle through notified directions&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; BlockPos pos = eventPos.relative(direction); // move to the direction given&amp;lt;br /&amp;gt; double x = pos.getX() + 0.5D; // move to center of the block&amp;lt;br /&amp;gt; double y = pos.getY() + 0.5D;&amp;lt;br /&amp;gt; double z = pos.getZ() + 0.5D;&amp;lt;br /&amp;gt; // add particle&amp;lt;br /&amp;gt; event.getWorld().addParticle(ParticleTypes.CLOUD, x, y, z, 0.0D, 0.0D, 0.0D);&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Some ideas for using this event:&amp;lt;br /&amp;gt;* Adding blocks that interact with redstone&amp;lt;br /&amp;gt;* Making a block update detector block&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;== CreateFluidSourceEvent ==&amp;lt;br /&amp;gt;This event controls creation of fluid sources. This is different than cancellable events, because it has a &amp;lt;code&amp;gt;Result&amp;lt;/code&amp;gt;. Setting it to &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; causes a source block to created, even if that's not normally what would happen. Setting it to &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; always prevents source creation.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Example usage:&amp;lt;br /&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&amp;lt;br /&amp;gt;public void onNeighborNotify(final BlockEvent.BreakEvent event)&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; if (event.getPos().getY() &amp;gt; 100)&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; event.setResult(Event.Result.DENY); // prevent source creation above y = 100&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;== FluidPlaceBlockEvent ==&amp;lt;br /&amp;gt;This event fires when fluids place blocks. Examples of this happening are: basalt, stone, cobblestone, obsidian, and fire (think lava pools). You can cancel this event to prevent placement.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;getLiquidPos()&amp;lt;/code&amp;gt; This is the liquid's position. For cases like cobble generation, this is the same as the original &amp;lt;code&amp;gt;getPos()&amp;lt;/code&amp;gt;. But for placing fire, this won't be the same.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;getNewState()&amp;lt;/code&amp;gt; Gets the state to be placed.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;setNewState()&amp;lt;/code&amp;gt; Sets the state to be placed.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;getOriginalState()&amp;lt;/code&amp;gt; What the block was before this event.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Example usage:&amp;lt;br /&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&amp;lt;br /&amp;gt;public void onBreak(final BlockEvent.BreakEvent event)&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; BlockState newState = event.getNewState();&amp;lt;br /&amp;gt; if (newState.is(Blocks.FIRE))&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; event.setCanceled(true); // prevent fire placing from lava&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt; else if (newState.is(Blocks.COBBLESTONE) &amp;amp;&amp;amp; event.getWorld().dayTime() &amp;gt; 14000L)&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; event.setNewState(Blocks.ANDESITE.defaultBlockState()); // change the block if done during nighttime.&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Some ideas for using this event:&amp;lt;br /&amp;gt;* Changing behavior of cobble generators&amp;lt;br /&amp;gt;* Preventing cobble generators&amp;lt;br /&amp;gt;* Adding more aggressive effects during fire spreading from lava&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;== CropGrowEvent ==&amp;lt;br /&amp;gt;These events are fired during crop growth. The &amp;lt;code&amp;gt;Pre&amp;lt;/code&amp;gt; event is fired before. It's fired when vanilla blocks try to 'grow' during random ticks (think cacti getting taller). Setting &amp;lt;code&amp;gt;DEFAULT&amp;lt;/code&amp;gt; as the result will cause no change. Setting &amp;lt;code&amp;gt;ALLOW&amp;lt;/code&amp;gt; forces growth. Setting &amp;lt;code&amp;gt;DENY&amp;lt;/code&amp;gt; prevents growth.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;The &amp;lt;code&amp;gt;Post&amp;lt;/code&amp;gt; event is fired after growth.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;getOriginalState&amp;lt;/code&amp;gt; Get the state before growth happened.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Example usage:&amp;lt;br /&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&amp;lt;br /&amp;gt;public void onCropGrowPre(final BlockEvent.CropGrowEvent.Pre event)&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; BlockState state = event.getState();&amp;lt;br /&amp;gt; if (state.is(Blocks.WHEAT))&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; event.setResult(Event.Result.DENY); // prevent wheat from growing&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt; else if (state.is(Blocks.BAMBOO))&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; if (event.getWorld().getRandom().nextFloat() &amp;gt; 0.2F) // take a 4/5 chance&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; event.setResult(Event.Result.DENY); // make bamboo grow less often&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Some ideas for using this event:&amp;lt;br /&amp;gt;* Changing growth rate of crops&amp;lt;br /&amp;gt;* Preventing crop growth under certain conditions&amp;lt;br /&amp;gt;* Spawning an entity when something grows&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;== FarmlandTrampleEvent ==&amp;lt;br /&amp;gt;This event is fired when farmland gets trampled. You can cancel it to prevent trampling.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;getEntity()&amp;lt;/code&amp;gt; The entity that trampled&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;getFallDistance()&amp;lt;/code&amp;gt; How far that entity fell&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Example usage:&amp;lt;br /&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&amp;lt;br /&amp;gt;public void onTrample(final BlockEvent.FarmlandTrampleEvent event)&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; if (event.getFallDistance() &amp;lt; 10.0F)&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; event.setCanceled(true); // change conditions for trampling&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;== PortalSpawnEvent ==&amp;lt;br /&amp;gt;This event is fired when a nether portal is created.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;getPortalSize()&amp;lt;/code&amp;gt; returns a &amp;lt;code&amp;gt;PortalSize&amp;lt;/code&amp;gt; object, basically only useful for determining if the portal is going to be valid or not.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;This is mostly used for preventing portal spawning in certain dimensions (even the overworld).&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;== BlockToolInteractEvent ==&amp;lt;br /&amp;gt;This event is fired on right click tool events, such as path creation, wood stripping, and farmland tilling. You have access to the player, the &amp;lt;code&amp;gt;ItemStack&amp;lt;/code&amp;gt; they're holding, and the &amp;lt;code&amp;gt;ToolType&amp;lt;/code&amp;gt; they have.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;setFinalState()&amp;lt;/code&amp;gt;: Set what you want the result to be.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;code&amp;gt;getFinalState()&amp;lt;/code&amp;gt;: Returns what it will be changed to.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Example usage:&amp;lt;br /&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&amp;lt;br /&amp;gt;public void event(final BlockEvent.BlockToolInteractEvent event)&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; if (event.getFinalState().is(Blocks.FARMLAND) &amp;amp;&amp;amp; event.getHeldItemStack().getItem() == Items.NETHERITE_HOE)&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; event.setFinalState(Blocks.NETHERRACK.defaultBlockState()); // change the final state under certain conditions&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Some ideas for using this:&amp;lt;br /&amp;gt;* Setting your custom farmland block during tilling&amp;lt;br /&amp;gt;* Adding stripped wood behavior for other blocks&amp;lt;br /&amp;gt;* Disable path creation&lt;/div&gt;</summary>
		<author><name>EERussianguy</name></author>
	</entry>
</feed>