001 package net.minecraftforge.common; 002 003 import java.util.UUID; 004 005 import cpw.mods.fml.common.FMLLog; 006 007 import net.minecraft.src.*; 008 import net.minecraftforge.event.*; 009 import net.minecraftforge.event.entity.*; 010 import net.minecraftforge.event.world.WorldEvent; 011 012 public class ForgeInternalHandler 013 { 014 @ForgeSubscribe(priority = EventPriority.HIGHEST) 015 public void onEntityJoinWorld(EntityJoinWorldEvent event) 016 { 017 if (!event.world.isRemote) 018 { 019 if (event.entity.getPersistentID() == null) 020 { 021 event.entity.generatePersistentID(); 022 } 023 else 024 { 025 ForgeChunkManager.loadEntity(event.entity); 026 } 027 } 028 029 Entity entity = event.entity; 030 if (entity.getClass().equals(EntityItem.class)) 031 { 032 ItemStack stack = ((EntityItem)entity).item; 033 034 if (stack == null) 035 { 036 entity.setDead(); 037 event.setCanceled(true); 038 return; 039 } 040 041 Item item = stack.getItem(); 042 if (item == null) 043 { 044 FMLLog.warning("Attempted to add a EntityItem to the world with a invalid item: ID %d at " + 045 "(%2.2f, %2.2f, %2.2f), this is most likely a config issue between you and the server. Please double check your configs", 046 stack.itemID, entity.posX, entity.posY, entity.posZ); 047 entity.setDead(); 048 event.setCanceled(true); 049 return; 050 } 051 052 if (item.hasCustomEntity(stack)) 053 { 054 Entity newEntity = item.createEntity(event.world, entity, stack); 055 if (newEntity != null) 056 { 057 entity.setDead(); 058 event.setCanceled(true); 059 event.world.spawnEntityInWorld(newEntity); 060 } 061 } 062 } 063 } 064 065 @ForgeSubscribe(priority = EventPriority.HIGHEST) 066 public void onDimensionLoad(WorldEvent.Load event) 067 { 068 ForgeChunkManager.loadWorld(event.world); 069 } 070 071 @ForgeSubscribe(priority = EventPriority.HIGHEST) 072 public void onDimensionSave(WorldEvent.Save event) 073 { 074 ForgeChunkManager.saveWorld(event.world); 075 } 076 077 @ForgeSubscribe(priority = EventPriority.HIGHEST) 078 public void onDimensionUnload(WorldEvent.Unload event) 079 { 080 ForgeChunkManager.unloadWorld(event.world); 081 } 082 }