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