    001package net.minecraftforge.event;
    002
    003import net.minecraft.block.Block;
    004import net.minecraft.entity.EntityLiving;
    005import net.minecraft.entity.player.EntityPlayer;
    006import net.minecraft.item.ItemStack;
    007import net.minecraft.world.World;
    008import net.minecraftforge.common.MinecraftForge;
    009import net.minecraftforge.event.Event.Result;
    010import net.minecraftforge.event.entity.living.LivingSpawnEvent;
    011import net.minecraftforge.event.entity.living.LivingSpecialSpawnEvent;
    012import net.minecraftforge.event.entity.player.*;
    013import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
    014
    015@SuppressWarnings("deprecation")
    016public class ForgeEventFactory
    017{
    018    public static boolean doPlayerHarvestCheck(EntityPlayer player, Block block, boolean success)
    019    {
    020        PlayerEvent.HarvestCheck event = new PlayerEvent.HarvestCheck(player, block, success);
    021        MinecraftForge.EVENT_BUS.post(event);
    022        return event.success;
    023    }
    024
    025    public static float getBreakSpeed(EntityPlayer player, Block block, int metadata, float original)
    026    {
    027        PlayerEvent.BreakSpeed event = new PlayerEvent.BreakSpeed(player, block, metadata, original);
    028        return (MinecraftForge.EVENT_BUS.post(event) ? -1 : event.newSpeed);
    029    }
    030
    031    public static PlayerInteractEvent onPlayerInteract(EntityPlayer player, Action action, int x, int y, int z, int face)
    032    {
    033        PlayerInteractEvent event = new PlayerInteractEvent(player, action, x, y, z, face);
    034        MinecraftForge.EVENT_BUS.post(event);
    035        return event;
    036    }
    037
    038    public static void onPlayerDestroyItem(EntityPlayer player, ItemStack stack)
    039    {
    040        MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, stack));
    041    }
    042
    043    public static Result canEntitySpawn(EntityLiving entity, World world, float x, float y, float z)
    044    {
    045        LivingSpawnEvent.CheckSpawn event = new LivingSpawnEvent.CheckSpawn(entity, world, x, y, z);
    046        MinecraftForge.EVENT_BUS.post(event);
    047        return event.getResult();
    048    }
    049
    050    public static boolean doSpecialSpawn(EntityLiving entity, World world, float x, float y, float z)
    051    {
    052        boolean result = MinecraftForge.EVENT_BUS.post(new LivingSpecialSpawnEvent(entity, world, x, y, z));
    053        LivingSpawnEvent.SpecialSpawn nEvent = new LivingSpawnEvent.SpecialSpawn(entity, world, x, y, z);
    054
    055        if (result) //For the time being, copy the canceled state from the old legacy event
    056        {           // Remove when we remove LivingSpecialSpawnEvent.
    057            nEvent.setCanceled(true);
    058        }
    059
    060        return MinecraftForge.EVENT_BUS.post(nEvent);
    061    }
    062}