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