From 4a748beb696230ec50bfe1ef03288998683510c2 Mon Sep 17 00:00:00 2001 From: LexManos Date: Tue, 27 Nov 2012 16:12:54 -0800 Subject: [PATCH] Fix potential NPE in EntityJoin handler and print warning. --- .../common/ForgeInternalHandler.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/common/net/minecraftforge/common/ForgeInternalHandler.java b/common/net/minecraftforge/common/ForgeInternalHandler.java index 7d9e400656..658d41d16a 100644 --- a/common/net/minecraftforge/common/ForgeInternalHandler.java +++ b/common/net/minecraftforge/common/ForgeInternalHandler.java @@ -2,6 +2,8 @@ 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.*; @@ -23,13 +25,33 @@ public class ForgeInternalHandler 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)) + ItemStack stack = ((EntityItem)entity).item; + + if (stack == null) { - Entity newEntity = item.getItem().createEntity(event.world, entity, item); + 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 " + + "(%d, %d, %d), 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();