[1.11] Add canApplyAtEnchantmentTable to Item (#3463)

Allowing increased control of which enchantments can be put on an item over Vanilla's hard-coded item type checks.
Render enchantment buttons disabled when the item is enchantable but the enchantability requirement is not met on lower levels.
This commit is contained in:
BlayTheNinth authored and LexManos committed 2016-12-03 10:43:29 -08:00
1 parent e09e6c0f24
commit 2009b3ec5e
5 files changed
+90 -5

No files matched your search

@@ -0,0 +1,44 @@
package net.minecraftforge.test;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.init.Enchantments;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
@Mod(modid="canapplyatenchantingtabletest", name="CanApplyAtEnchantingTableTest", version="0.0.0")
public class CanApplyAtEnchantingTableTest
{
public static final boolean ENABLE = true;
public static final Item testItem = new Item()
{
public boolean isItemTool(ItemStack stack)
{
return true;
}
@Override
public int getItemEnchantability()
{
return 30;
}
@Override
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment)
{
return super.canApplyAtEnchantingTable(stack, enchantment) || enchantment == Enchantments.FORTUNE;
}
};
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event)
{
if(ENABLE)
{
GameRegistry.register(testItem.setRegistryName("test_item").setUnlocalizedName("FortuneEnchantableOnly").setMaxStackSize(1));
}
}
}