Add ability for Items to create custom Entities for themselves when added to the world, PR: #151

This commit is contained in:
LexManos committed 2012-09-11 17:35:53 -07:00
1 parent 96be8c4f19
commit aeebb6e9f9
3 files changed
+65 -1

No files matched your search

@@ -0,0 +1,28 @@
package net.minecraftforge.common;
import net.minecraft.src.*;
import net.minecraftforge.event.*;
import net.minecraftforge.event.entity.*;
public class ForgeInternalHandler
{
@ForgeSubscribe(priority = EventPriority.HIGHEST)
public void onEntityJoinWorld(EntityJoinWorldEvent event)
{
Entity entity = event.entity;
if (entity instanceof EntityItem)
{
ItemStack item = ((EntityItem)entity).item;
if (item.getItem().hasCustomEntity(item))
{
Entity newEntity = item.getItem().createEntity(event.world, entity, item);
if (newEntity != null)
{
entity.setDead();
event.setCanceled(true);
event.world.spawnEntityInWorld(entity);
}
}
}
}
}