Fix ContainerRepair patch to prevent NPE (#3553)

This commit is contained in:
Ben Staddon 2017-01-12 00:14:38 +00:00 committed by LexManos
parent d72888b6ab
commit a718077a2e
2 changed files with 67 additions and 7 deletions

View file

@ -32,12 +32,11 @@
if (itemstack1.func_77984_f() && itemstack1.func_77973_b().func_82789_a(itemstack, itemstack2))
{
@@ -312,6 +316,8 @@
}
@@ -327,6 +331,7 @@
i += k;
itemstack1.func_151001_c(this.field_82857_m);
}
+ if (flag && !itemstack1.func_77973_b().isBookEnchantable(itemstack1, itemstack2)) itemstack1 = ItemStack.field_190927_a;
this.field_82854_e = j + i;
+ if (flag && !itemstack1.func_77973_b().isBookEnchantable(itemstack1, itemstack2)) itemstack1 = null;
+
if (StringUtils.isBlank(this.field_82857_m))
{
if (itemstack.func_82837_s())

View file

@ -0,0 +1,61 @@
package net.minecraftforge.test;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@Mod(modid = IsBookEnchantableTest.MOD_ID, name = "Test for isBookEnchantable", version = "1.0")
@Mod.EventBusSubscriber
public class IsBookEnchantableTest
{
static final String MOD_ID = "is_book_enchantable_test";
private static final Item TEST_ITEM = new TestItem();
@SubscribeEvent
public static void registerItem(RegistryEvent.Register<Item> event)
{
event.getRegistry().register(TEST_ITEM);
}
private static class TestItem extends Item
{
private static final String NAME = "test_item";
private TestItem()
{
maxStackSize = 1;
setUnlocalizedName(MOD_ID + "." + NAME);
setRegistryName(NAME);
setCreativeTab(CreativeTabs.MISC);
}
@Override
public boolean isEnchantable(ItemStack stack)
{
return true;
}
@Override
public int getItemEnchantability()
{
return 15;
}
@Override
public boolean isBookEnchantable(ItemStack stack, ItemStack book)
{
return false;
}
@Override
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment)
{
return true;
}
}
}