Add some null checks to packets

Might close #169
This commit is contained in:
Ellpeck 2016-07-24 12:48:35 +02:00
parent 90c1f2c25f
commit 5e63208098
2 changed files with 18 additions and 12 deletions

View file

@ -20,6 +20,7 @@ import de.ellpeck.actuallyadditions.mod.tile.TileEntityBookletStand;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -67,7 +68,10 @@ public final class PacketHandler{
if(tile instanceof IButtonReactor){ if(tile instanceof IButtonReactor){
IButtonReactor reactor = (IButtonReactor)tile; IButtonReactor reactor = (IButtonReactor)tile;
reactor.onButtonPressed(compound.getInteger("ButtonID"), (EntityPlayer)world.getEntityByID(compound.getInteger("PlayerID"))); Entity entity = world.getEntityByID(compound.getInteger("PlayerID"));
if(entity != null && entity instanceof EntityPlayer){
reactor.onButtonPressed(compound.getInteger("ButtonID"), (EntityPlayer)entity);
}
} }
} }
}; };

View file

@ -45,6 +45,7 @@ public class TileEntityGiantChest extends TileEntityInventoryBase implements IBu
@Override @Override
public void onButtonPressed(int buttonID, EntityPlayer player){ public void onButtonPressed(int buttonID, EntityPlayer player){
if(player != null && this.pos != null){
GuiHandler.GuiTypes type; GuiHandler.GuiTypes type;
if(buttonID == 0){ if(buttonID == 0){
@ -60,3 +61,4 @@ public class TileEntityGiantChest extends TileEntityInventoryBase implements IBu
player.openGui(ActuallyAdditions.instance, type.ordinal(), this.worldObj, this.pos.getX(), this.pos.getY(), this.pos.getZ()); player.openGui(ActuallyAdditions.instance, type.ordinal(), this.worldObj, this.pos.getX(), this.pos.getY(), this.pos.getZ());
} }
} }
}