Merge pull request #1721 from me4502/update-event

Added NeighborNotifyEvent fired on server side only, allows for monitoring and disabling world 'physics' updates.
This commit is contained in:
LexManos committed 2015-02-28 22:54:48 -08:00
commit 7355bdf600
6 files changed
+172 -49

No files matched your search

@@ -2,6 +2,7 @@ package net.minecraftforge.event;
import java.io.File;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -62,6 +63,7 @@ import net.minecraftforge.event.entity.player.PlayerUseItemEvent;
import net.minecraftforge.event.entity.player.PlayerWakeUpEvent;
import net.minecraftforge.event.entity.player.UseHoeEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent;
import net.minecraftforge.event.world.BlockEvent.MultiPlaceEvent;
import net.minecraftforge.event.world.BlockEvent.PlaceEvent;
import net.minecraftforge.event.world.ExplosionEvent;
@@ -89,6 +91,13 @@ public class ForgeEventFactory
MinecraftForge.EVENT_BUS.post(event);
return event;
}
public static NeighborNotifyEvent onNeighborNotify(World world, BlockPos pos, IBlockState state, EnumSet<EnumFacing> notifiedSides)
{
NeighborNotifyEvent event = new NeighborNotifyEvent(world, pos, state, notifiedSides);
MinecraftForge.EVENT_BUS.post(event);
return event;
}
public static boolean doPlayerHarvestCheck(EntityPlayer player, Block block, boolean success)
{
@@ -1,6 +1,7 @@
package net.minecraftforge.event.world;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.block.Block;
@@ -9,6 +10,7 @@ import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.util.BlockSnapshot;
@@ -177,4 +179,31 @@ public class BlockEvent extends Event
return blockSnapshots;
}
}
/**
* Fired when a physics update occurs on a block. This event acts as
* a way for mods to detect physics updates, in the same way a BUD switch
* does. This event is only called on the server.
*/
@Cancelable
public static class NeighborNotifyEvent extends BlockEvent
{
private final EnumSet<EnumFacing> notifiedSides;
public NeighborNotifyEvent(World world, BlockPos pos, IBlockState state, EnumSet<EnumFacing> notifiedSides)
{
super(world, pos, state);
this.notifiedSides = notifiedSides;
}
/**
* Gets a list of directions from the base block that updates will occur upon.
*
* @return list of notified directions
*/
public EnumSet<EnumFacing> getNotifiedSides()
{
return notifiedSides;
}
}
}