package net.minecraftforge.common;

import java.util.UUID;

import net.minecraft.src.*;
import net.minecraftforge.event.*;
import net.minecraftforge.event.entity.*;
import net.minecraftforge.event.world.WorldEvent;

public class ForgeInternalHandler
{
    @ForgeSubscribe(priority = EventPriority.HIGHEST)
    public void onEntityJoinWorld(EntityJoinWorldEvent event)
    {
        if (!event.world.isRemote)
        {
            if (event.entity.getPersistentID() == null)
            {
                event.entity.generatePersistentID();
            }
            else
            {
                ForgeChunkManager.loadEntity(event.entity);
            }
        }
        Entity entity = event.entity;
        if (entity.getClass().equals(EntityItem.class))
        {
            ItemStack item = ((EntityItem)entity).item;
            if (item != null && item.getItem().hasCustomEntity(item))
            {
                Entity newEntity = item.getItem().createEntity(event.world, entity, item);
                if (newEntity != null)
                {
                    entity.setDead();
                    event.setCanceled(true);
                    event.world.spawnEntityInWorld(newEntity);
                }
            }
        }
    }

    @ForgeSubscribe(priority = EventPriority.HIGHEST)
    public void onDimensionLoad(WorldEvent.Load event)
    {
        ForgeChunkManager.loadWorld(event.world);
    }

    @ForgeSubscribe(priority = EventPriority.HIGHEST)
    public void onDimensionSave(WorldEvent.Save event)
    {
    	ForgeChunkManager.saveWorld(event.world);
    }
}

@@ -53,16 +53,52 @@
 .UUID;%0A%0A
+import cpw.mods.fml.common.FMLLog;%0A%0A
 import n
@@ -692,32 +692,33 @@
     %7D%0A        %7D%0A
+%0A
         Entity e
@@ -827,20 +827,21 @@
 emStack 
-item
+stack
  = ((Ent
@@ -862,16 +862,17 @@
 ).item;%0A
+%0A
         
@@ -883,38 +883,688 @@
 if (
-item != null && item.getItem()
+stack == null)%0A            %7B%0A                entity.setDead();%0A                event.setCanceled(true);%0A                return;%0A            %7D%0A%0A            Item item = stack.getItem();%0A            if (item == null)%0A            %7B%0A                FMLLog.warning(%22Attempted to add a EntityItem to the world with a invalid item: ID %25d at %22 + %0A                    %22(%25d,  %25d, %25d), this is most likely a config issue between you and the server. Please double check your configs%22,%0A                    stack.itemID, entity.posX, entity.posY, entity.posZ);%0A                entity.setDead();%0A                event.setCanceled(true);%0A                return;%0A            %7D%0A%0A            if (item
 .has
@@ -1576,20 +1576,21 @@
 mEntity(
-item
+stack
 ))%0A     
@@ -1642,18 +1642,8 @@
 tem.
-getItem().
 crea
@@ -1672,20 +1672,21 @@
 entity, 
-item
+stack
 );%0A     

Fix potential NPE in EntityJoin handler and print warning.