mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-21 12:42:26 +00:00
83 lines
2.4 KiB
Java
83 lines
2.4 KiB
Java
package net.minecraftforge.common;
|
|
|
|
import java.util.UUID;
|
|
|
|
import cpw.mods.fml.common.FMLLog;
|
|
|
|
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 stack = ((EntityItem)entity).item;
|
|
|
|
if (stack == null)
|
|
{
|
|
entity.setDead();
|
|
event.setCanceled(true);
|
|
return;
|
|
}
|
|
|
|
Item item = stack.getItem();
|
|
if (item == null)
|
|
{
|
|
FMLLog.warning("Attempted to add a EntityItem to the world with a invalid item: ID %d at " +
|
|
"(%2.2f, %2.2f, %2.2f), this is most likely a config issue between you and the server. Please double check your configs",
|
|
stack.itemID, entity.posX, entity.posY, entity.posZ);
|
|
entity.setDead();
|
|
event.setCanceled(true);
|
|
return;
|
|
}
|
|
|
|
if (item.hasCustomEntity(stack))
|
|
{
|
|
Entity newEntity = item.createEntity(event.world, entity, stack);
|
|
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);
|
|
}
|
|
|
|
@ForgeSubscribe(priority = EventPriority.HIGHEST)
|
|
public void onDimensionUnload(WorldEvent.Unload event)
|
|
{
|
|
ForgeChunkManager.unloadWorld(event.world);
|
|
}
|
|
}
|