2012-09-27 00:54:15 +00:00
|
|
|
package net.minecraftforge.event;
|
2012-12-13 07:27:57 +00:00
|
|
|
|
2013-09-07 04:10:08 +00:00
|
|
|
import java.util.ArrayList;
|
2013-03-05 04:29:05 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
2012-12-13 07:27:57 +00:00
|
|
|
import net.minecraft.block.Block;
|
2013-01-02 06:20:30 +00:00
|
|
|
import net.minecraft.entity.EntityLiving;
|
2013-10-13 16:21:57 +00:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2013-03-05 04:29:05 +00:00
|
|
|
import net.minecraft.entity.EnumCreatureType;
|
2013-10-13 16:21:57 +00:00
|
|
|
import net.minecraft.entity.monster.EntityZombie;
|
2012-12-13 07:27:57 +00:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2013-01-02 06:20:30 +00:00
|
|
|
import net.minecraft.world.World;
|
2013-03-05 04:29:05 +00:00
|
|
|
import net.minecraft.world.WorldServer;
|
2012-09-27 00:54:15 +00:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2013-01-02 06:20:30 +00:00
|
|
|
import net.minecraftforge.event.Event.Result;
|
2013-03-20 02:59:28 +00:00
|
|
|
import net.minecraftforge.event.entity.living.LivingPackSizeEvent;
|
2013-01-02 06:20:30 +00:00
|
|
|
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
|
2013-09-06 17:19:51 +00:00
|
|
|
import net.minecraftforge.event.entity.living.LivingSpawnEvent.AllowDespawn;
|
2013-10-13 16:21:57 +00:00
|
|
|
import net.minecraftforge.event.entity.living.ZombieEvent.SummonAidEvent;
|
2013-09-23 08:50:59 +00:00
|
|
|
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
2013-03-05 04:29:05 +00:00
|
|
|
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
|
|
|
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
|
|
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
2012-09-27 04:18:18 +00:00
|
|
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
2013-09-07 04:10:08 +00:00
|
|
|
import net.minecraftforge.event.world.BlockEvent;
|
2013-03-05 04:29:05 +00:00
|
|
|
import net.minecraftforge.event.world.WorldEvent;
|
2012-09-27 00:54:15 +00:00
|
|
|
|
2013-01-02 06:20:30 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2012-09-27 00:54:15 +00:00
|
|
|
public class ForgeEventFactory
|
|
|
|
{
|
|
|
|
public static boolean doPlayerHarvestCheck(EntityPlayer player, Block block, boolean success)
|
|
|
|
{
|
|
|
|
PlayerEvent.HarvestCheck event = new PlayerEvent.HarvestCheck(player, block, success);
|
|
|
|
MinecraftForge.EVENT_BUS.post(event);
|
|
|
|
return event.success;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static float getBreakSpeed(EntityPlayer player, Block block, int metadata, float original)
|
|
|
|
{
|
|
|
|
PlayerEvent.BreakSpeed event = new PlayerEvent.BreakSpeed(player, block, metadata, original);
|
|
|
|
return (MinecraftForge.EVENT_BUS.post(event) ? -1 : event.newSpeed);
|
|
|
|
}
|
2012-09-27 04:18:18 +00:00
|
|
|
|
|
|
|
public static PlayerInteractEvent onPlayerInteract(EntityPlayer player, Action action, int x, int y, int z, int face)
|
|
|
|
{
|
|
|
|
PlayerInteractEvent event = new PlayerInteractEvent(player, action, x, y, z, face);
|
|
|
|
MinecraftForge.EVENT_BUS.post(event);
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void onPlayerDestroyItem(EntityPlayer player, ItemStack stack)
|
|
|
|
{
|
|
|
|
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, stack));
|
|
|
|
}
|
2013-01-02 06:20:30 +00:00
|
|
|
|
|
|
|
public static Result canEntitySpawn(EntityLiving entity, World world, float x, float y, float z)
|
|
|
|
{
|
|
|
|
LivingSpawnEvent.CheckSpawn event = new LivingSpawnEvent.CheckSpawn(entity, world, x, y, z);
|
|
|
|
MinecraftForge.EVENT_BUS.post(event);
|
|
|
|
return event.getResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean doSpecialSpawn(EntityLiving entity, World world, float x, float y, float z)
|
|
|
|
{
|
2013-03-05 04:29:05 +00:00
|
|
|
return MinecraftForge.EVENT_BUS.post(new LivingSpawnEvent.SpecialSpawn(entity, world, x, y, z));
|
|
|
|
}
|
2013-01-02 06:20:30 +00:00
|
|
|
|
2013-09-06 20:05:29 +00:00
|
|
|
public static Result canEntityDespawn(EntityLiving entity)
|
2013-09-06 17:19:51 +00:00
|
|
|
{
|
2013-09-06 20:05:29 +00:00
|
|
|
AllowDespawn event = new AllowDespawn(entity);
|
|
|
|
MinecraftForge.EVENT_BUS.post(event);
|
|
|
|
return event.getResult();
|
2013-09-06 17:19:51 +00:00
|
|
|
}
|
|
|
|
|
2013-03-05 04:29:05 +00:00
|
|
|
public static List getPotentialSpawns(WorldServer world, EnumCreatureType type, int x, int y, int z, List oldList)
|
|
|
|
{
|
|
|
|
WorldEvent.PotentialSpawns event = new WorldEvent.PotentialSpawns(world, type, x, y, z, oldList);
|
|
|
|
if (MinecraftForge.EVENT_BUS.post(event))
|
|
|
|
{
|
|
|
|
return null;
|
2013-01-02 06:20:30 +00:00
|
|
|
}
|
2013-03-05 04:29:05 +00:00
|
|
|
return event.list;
|
2013-01-02 06:20:30 +00:00
|
|
|
}
|
2013-03-20 00:43:37 +00:00
|
|
|
|
2013-03-20 02:59:28 +00:00
|
|
|
public static int getMaxSpawnPackSize(EntityLiving entity)
|
2013-03-20 00:43:37 +00:00
|
|
|
{
|
2013-03-20 02:59:28 +00:00
|
|
|
LivingPackSizeEvent maxCanSpawnEvent = new LivingPackSizeEvent(entity);
|
2013-03-20 00:43:37 +00:00
|
|
|
MinecraftForge.EVENT_BUS.post(maxCanSpawnEvent);
|
2013-03-20 02:59:28 +00:00
|
|
|
return maxCanSpawnEvent.getResult() == Result.ALLOW ? maxCanSpawnEvent.maxPackSize : entity.getMaxSpawnedInChunk();
|
2013-03-20 00:43:37 +00:00
|
|
|
}
|
2013-09-03 20:55:11 +00:00
|
|
|
|
|
|
|
public static String getPlayerDisplayName(EntityPlayer player, String username)
|
|
|
|
{
|
|
|
|
PlayerEvent.NameFormat event = new PlayerEvent.NameFormat(player, username);
|
|
|
|
MinecraftForge.EVENT_BUS.post(event);
|
|
|
|
return event.displayname;
|
|
|
|
}
|
2013-09-07 04:10:08 +00:00
|
|
|
|
|
|
|
public static float fireBlockHarvesting(ArrayList<ItemStack> drops, World world, Block block, int x, int y, int z, int meta, int fortune, float dropChance, boolean silkTouch, EntityPlayer player)
|
|
|
|
{
|
|
|
|
BlockEvent.HarvestDropsEvent event = new BlockEvent.HarvestDropsEvent(x, y, z, world, block, meta, fortune, dropChance, drops, player, silkTouch);
|
|
|
|
MinecraftForge.EVENT_BUS.post(event);
|
|
|
|
return event.dropChance;
|
|
|
|
}
|
2013-09-23 08:50:59 +00:00
|
|
|
|
|
|
|
public static ItemTooltipEvent onItemTooltip(ItemStack itemStack, EntityPlayer entityPlayer, List<String> toolTip, boolean showAdvancedItemTooltips)
|
|
|
|
{
|
|
|
|
ItemTooltipEvent event = new ItemTooltipEvent(itemStack, entityPlayer, toolTip, showAdvancedItemTooltips);
|
|
|
|
MinecraftForge.EVENT_BUS.post(event);
|
|
|
|
return event;
|
|
|
|
}
|
2013-10-13 16:21:57 +00:00
|
|
|
|
|
|
|
public static SummonAidEvent fireZombieSummonAid(EntityZombie zombie, World world, int x, int y, int z, EntityLivingBase attacker, double summonChance)
|
|
|
|
{
|
|
|
|
SummonAidEvent summonEvent = new SummonAidEvent(zombie, world, x, y, z, attacker, summonChance);
|
|
|
|
MinecraftForge.EVENT_BUS.post(summonEvent);
|
|
|
|
return summonEvent;
|
|
|
|
}
|
2012-09-27 00:54:15 +00:00
|
|
|
}
|