Inventories now don't NPE when broken

This commit is contained in:
Nick 2015-11-03 09:11:39 -08:00
parent 6a5f5356ce
commit ddcc1237e8
3 changed files with 8 additions and 10 deletions

View file

@ -44,7 +44,7 @@ public class BloodAltar {
}
}
return true;
return false;
}
public static AltarUpgrade getUpgrades(World world, BlockPos pos, EnumAltarTier altarTier)

View file

@ -3,7 +3,6 @@ package WayofTime.bloodmagic.block;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.iface.IAltarReader;
import WayofTime.bloodmagic.tile.TileAltar;
import WayofTime.bloodmagic.tile.TileInventory;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
@ -88,10 +87,11 @@ public class BlockAltar extends BlockContainer {
}
@Override
public void breakBlock(World world, BlockPos blockPos, IBlockState blockState)
{
TileInventory tileInventory = (TileInventory) world.getTileEntity(blockPos);
if (tileInventory != null) tileInventory.dropItems();
public void breakBlock(World world, BlockPos blockPos, IBlockState blockState) {
TileAltar tileAltar = (TileAltar) world.getTileEntity(blockPos);
if (tileAltar != null)
tileAltar.dropItems();
super.breakBlock(world, blockPos, blockState);
}

View file

@ -3,6 +3,7 @@ package WayofTime.bloodmagic.tile;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
@ -57,10 +58,7 @@ public class TileInventory extends TileEntity implements IInventory {
}
public void dropItems() {
if (inventory != null) {
for (ItemStack stack : inventory)
getWorld().spawnEntityInWorld(new EntityItem(getWorld(), getPos().getX(), pos.getY(), pos.getZ(), stack));
}
InventoryHelper.dropInventoryItems(getWorld(), getPos(), this);
}
// IInventory