Fixed NPE with incorrectly initialized disks, fixes #200
This commit is contained in:
@@ -238,6 +238,10 @@ public abstract class NBTStorage implements IStorage {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static boolean isValid(ItemStack stack) {
|
||||
return stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_ITEMS) && stack.getTagCompound().hasKey(NBT_STORED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stack The {@link ItemStack} to populate with the NBT tags from {@link NBTStorage#createNBT()}
|
||||
* @return The provided {@link ItemStack} with NBT tags from {@link NBTStorage#createNBT()}
|
||||
|
||||
@@ -93,19 +93,21 @@ public class ItemStorageDisk extends ItemBase {
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack disk, EntityPlayer player, List list, boolean b) {
|
||||
int capacity = EnumStorageType.getById(disk.getItemDamage()).getCapacity();
|
||||
if (NBTStorage.isValid(disk)) {
|
||||
int capacity = EnumStorageType.getById(disk.getItemDamage()).getCapacity();
|
||||
|
||||
if (capacity == -1) {
|
||||
list.add(I18n.format("misc.refinedstorage:storage.stored", NBTStorage.getStoredFromNBT(disk.getTagCompound())));
|
||||
} else {
|
||||
list.add(I18n.format("misc.refinedstorage:storage.stored_capacity", NBTStorage.getStoredFromNBT(disk.getTagCompound()), capacity));
|
||||
if (capacity == -1) {
|
||||
list.add(I18n.format("misc.refinedstorage:storage.stored", NBTStorage.getStoredFromNBT(disk.getTagCompound())));
|
||||
} else {
|
||||
list.add(I18n.format("misc.refinedstorage:storage.stored_capacity", NBTStorage.getStoredFromNBT(disk.getTagCompound()), capacity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
|
||||
if (!world.isRemote && player.isSneaking() && NBTStorage.getStoredFromNBT(stack.getTagCompound()) == 0 && stack.getMetadata() != TYPE_CREATIVE) {
|
||||
ItemStack storagePart = new ItemStack(RefinedStorageItems.STORAGE_PART, 1, stack.getMetadata());
|
||||
public ActionResult<ItemStack> onItemRightClick(ItemStack disk, World world, EntityPlayer player, EnumHand hand) {
|
||||
if (!world.isRemote && player.isSneaking() && NBTStorage.isValid(disk) && NBTStorage.getStoredFromNBT(disk.getTagCompound()) == 0 && disk.getMetadata() != TYPE_CREATIVE) {
|
||||
ItemStack storagePart = new ItemStack(RefinedStorageItems.STORAGE_PART, 1, disk.getMetadata());
|
||||
|
||||
if (!player.inventory.addItemStackToInventory(storagePart.copy())) {
|
||||
InventoryHelper.spawnItemStack(world, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), storagePart);
|
||||
@@ -114,7 +116,7 @@ public class ItemStorageDisk extends ItemBase {
|
||||
return new ActionResult(EnumActionResult.SUCCESS, new ItemStack(RefinedStorageItems.STORAGE_HOUSING));
|
||||
}
|
||||
|
||||
return new ActionResult(EnumActionResult.PASS, stack);
|
||||
return new ActionResult(EnumActionResult.PASS, disk);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -53,7 +53,12 @@ public class TileDiskDrive extends TileNode implements IStorageProvider, IStorag
|
||||
private static final String NBT_MODE = "Mode";
|
||||
private static final String NBT_STORED = "Stored";
|
||||
|
||||
private BasicItemHandler disks = new BasicItemHandler(8, this, new BasicItemValidator(RefinedStorageItems.STORAGE_DISK)) {
|
||||
private BasicItemHandler disks = new BasicItemHandler(8, this, new BasicItemValidator(RefinedStorageItems.STORAGE_DISK) {
|
||||
@Override
|
||||
public boolean isValid(ItemStack disk) {
|
||||
return super.isValid(disk) && NBTStorage.isValid(disk);
|
||||
}
|
||||
}) {
|
||||
@Override
|
||||
protected void onContentsChanged(int slot) {
|
||||
super.onContentsChanged(slot);
|
||||
|
||||
Reference in New Issue
Block a user