    001package net.minecraftforge.event;
    002
    003import java.util.List;
    004
    005import net.minecraft.block.Block;
    006import net.minecraft.entity.EntityLiving;
    007import net.minecraft.entity.EnumCreatureType;
    008import net.minecraft.entity.player.EntityPlayer;
    009import net.minecraft.item.ItemStack;
    010import net.minecraft.world.World;
    011import net.minecraft.world.WorldServer;
    012import net.minecraftforge.common.MinecraftForge;
    013import net.minecraftforge.event.Event.Result;
    014import net.minecraftforge.event.entity.living.LivingPackSizeEvent;
    015import net.minecraftforge.event.entity.living.LivingSpawnEvent;
    016import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
    017import net.minecraftforge.event.entity.player.PlayerEvent;
    018import net.minecraftforge.event.entity.player.PlayerInteractEvent;
    019import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
    020import net.minecraftforge.event.world.WorldEvent;
    021
    022@SuppressWarnings("deprecation")
    023public class ForgeEventFactory
    024{
    025    public static boolean doPlayerHarvestCheck(EntityPlayer player, Block block, boolean success)
    026    {
    027        PlayerEvent.HarvestCheck event = new PlayerEvent.HarvestCheck(player, block, success);
    028        MinecraftForge.EVENT_BUS.post(event);
    029        return event.success;
    030    }
    031
    032    public static float getBreakSpeed(EntityPlayer player, Block block, int metadata, float original)
    033    {
    034        PlayerEvent.BreakSpeed event = new PlayerEvent.BreakSpeed(player, block, metadata, original);
    035        return (MinecraftForge.EVENT_BUS.post(event) ? -1 : event.newSpeed);
    036    }
    037
    038    public static PlayerInteractEvent onPlayerInteract(EntityPlayer player, Action action, int x, int y, int z, int face)
    039    {
    040        PlayerInteractEvent event = new PlayerInteractEvent(player, action, x, y, z, face);
    041        MinecraftForge.EVENT_BUS.post(event);
    042        return event;
    043    }
    044
    045    public static void onPlayerDestroyItem(EntityPlayer player, ItemStack stack)
    046    {
    047        MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, stack));
    048    }
    049
    050    public static Result canEntitySpawn(EntityLiving entity, World world, float x, float y, float z)
    051    {
    052        LivingSpawnEvent.CheckSpawn event = new LivingSpawnEvent.CheckSpawn(entity, world, x, y, z);
    053        MinecraftForge.EVENT_BUS.post(event);
    054        return event.getResult();
    055    }
    056
    057    public static boolean doSpecialSpawn(EntityLiving entity, World world, float x, float y, float z)
    058    {
    059        return MinecraftForge.EVENT_BUS.post(new LivingSpawnEvent.SpecialSpawn(entity, world, x, y, z));
    060    }
    061
    062    public static List getPotentialSpawns(WorldServer world, EnumCreatureType type, int x, int y, int z, List oldList)
    063    {
    064        WorldEvent.PotentialSpawns event = new WorldEvent.PotentialSpawns(world, type, x, y, z, oldList);
    065        if (MinecraftForge.EVENT_BUS.post(event))
    066        {
    067            return null;
    068        }
    069        return event.list;
    070    }
    071
    072    public static int getMaxSpawnPackSize(EntityLiving entity)
    073    {
    074        LivingPackSizeEvent maxCanSpawnEvent = new LivingPackSizeEvent(entity);
    075        MinecraftForge.EVENT_BUS.post(maxCanSpawnEvent);
    076        return maxCanSpawnEvent.getResult() == Result.ALLOW ? maxCanSpawnEvent.maxPackSize : entity.getMaxSpawnedInChunk();
    077    }
    078}