mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 19:59:42 +00:00
Add ability for Items to create custom Entities for themselves when added to the world, PR: #151
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user