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.LivingSpawnEvent; 015import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; 016import net.minecraftforge.event.entity.player.PlayerEvent; 017import net.minecraftforge.event.entity.player.PlayerInteractEvent; 018import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; 019import net.minecraftforge.event.world.WorldEvent; 020 021@SuppressWarnings("deprecation") 022public class ForgeEventFactory 023{ 024 public static boolean doPlayerHarvestCheck(EntityPlayer player, Block block, boolean success) 025 { 026 PlayerEvent.HarvestCheck event = new PlayerEvent.HarvestCheck(player, block, success); 027 MinecraftForge.EVENT_BUS.post(event); 028 return event.success; 029 } 030 031 public static float getBreakSpeed(EntityPlayer player, Block block, int metadata, float original) 032 { 033 PlayerEvent.BreakSpeed event = new PlayerEvent.BreakSpeed(player, block, metadata, original); 034 return (MinecraftForge.EVENT_BUS.post(event) ? -1 : event.newSpeed); 035 } 036 037 public static PlayerInteractEvent onPlayerInteract(EntityPlayer player, Action action, int x, int y, int z, int face) 038 { 039 PlayerInteractEvent event = new PlayerInteractEvent(player, action, x, y, z, face); 040 MinecraftForge.EVENT_BUS.post(event); 041 return event; 042 } 043 044 public static void onPlayerDestroyItem(EntityPlayer player, ItemStack stack) 045 { 046 MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, stack)); 047 } 048 049 public static Result canEntitySpawn(EntityLiving entity, World world, float x, float y, float z) 050 { 051 LivingSpawnEvent.CheckSpawn event = new LivingSpawnEvent.CheckSpawn(entity, world, x, y, z); 052 MinecraftForge.EVENT_BUS.post(event); 053 return event.getResult(); 054 } 055 056 public static boolean doSpecialSpawn(EntityLiving entity, World world, float x, float y, float z) 057 { 058 return MinecraftForge.EVENT_BUS.post(new LivingSpawnEvent.SpecialSpawn(entity, world, x, y, z)); 059 } 060 061 public static List getPotentialSpawns(WorldServer world, EnumCreatureType type, int x, int y, int z, List oldList) 062 { 063 WorldEvent.PotentialSpawns event = new WorldEvent.PotentialSpawns(world, type, x, y, z, oldList); 064 if (MinecraftForge.EVENT_BUS.post(event)) 065 { 066 return null; 067 } 068 return event.list; 069 } 070}