Jump to content

[1.8] Apply Vanilla Enchanted Book to Custom Shears in Anvil


Recommended Posts

I have created custom shears extending ItemShears (maybe that was a mistake). I want them to be enchantable in all cases that vanilla (iron) shears are enchantable. Sadly, my custom shears run afoul of a line in vanilla enchantment code where item == Items.shears (not instanceof). I wish the test could be changed to instanceof.


The whole chain of "canApply..." methods are written into class Enchantment and the children for specific enchantments. I haven't found any call-backs to item objects where my custom shears could override something to assert their enchantability, even in an anvil. I've made some headway on the enchanting table, but the anvil is thus far resisting my efforts.


My test case (on anvil in survival mode): custom shears as input1, and an enchanted book with eff V as input2. The output slot is empty, and there's an ugly red X before it. I want the X to go away, and I want enchanted (Eff V) custom shears in the output slot.


If there's a Forge event somewhere in the call chain, I'm not seeing it. I tried overriding isBookEnchantable, but no joy. Maybe I'm almost there but blind to something obvious?


For what it's worth, my shears class:


public class classRubyShears extends ItemShears {


  protected static final Item.ToolMaterial toolMaterial = classNetherGemMod.toolRuby;

  protected static final float efficiencyOnProperMaterial = toolMaterial.getEfficiencyOnProperMaterial ();


  public classRubyShears(String name) {

    super ();

    this.setUnlocalizedName (name);

    this.setMaxDamage (toolMaterial.getMaxUses ());

    classNetherGemMod.regItem (this); // set texture & maybe tab, then register




  * Return true if anvil can repair damage on item in stack1 using material item in stack2.

  * This does not enable book application. On the contrary, returning true precludes magic processing,

  * so NEVER return true for enchanted books in stack2



  public boolean getIsRepairable(ItemStack tool, ItemStack gem) {

    return gem.getItem () == classNetherGemMod.itemRuby;




  public int getItemEnchantability() {

    return this.toolMaterial.getEnchantability ();      // Enchantable on a crafting table




  * Allow or forbid the specific book/item combination as an anvil enchant


  * @param stack The item

  * @param book The book

  * @return if the enchantment is allowed


  public boolean isBookEnchantable(ItemStack stack, ItemStack book) {

    NBTTagList enchants = Items.enchanted_book.getEnchantments (book);


    if (enchants != null) {

      for (int i = 0; i < enchants.tagCount (); i++ ) {

        short enchId = enchants.getCompoundTagAt (i).getShort ("id");

        switch (enchId) {

          case 32:

          case 33:

          case 34:

          case 35:

          case 70:

            return true;


        if (enchId == classNetherGemMod.smartHarvest.effectId) return true; // Not constant enough to use inside switch



    return false;





EDIT: I've found something called ForgeHooks.onAnvilChange that might fill the bill. I'll give it a go this week.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • file:///C:/Users/Danie/Downloads/Capture.JPG I keep experiencing this error, does anyone know how to fix it here is the report: file:///C:/Users/Danie/AppData/Roaming/.minecraft/crash-reports/Bug_report1.txt
    • Hi, i am unable to join a multiplayer server my friend and i created. We started it with some mods then decided to add some others and this is when the error appeared. We are using Curseforge, the server is in 1.20.1 . The full error message is "Internal Exception: io.netty.handler.codec.DecoderException: java.lang.ArrayIndexOutOfBoundsException: Index 17196645 out of bounds for length 13" I am the only one with that issue, my friends can log in and out no problem. I have tried switching minecraft account but that doesn't help so i guess the bug is on my side. We use the same mod profile so i know the error doesn't come from there. Here is the latest.log file https://pastebin.com/X6J9Fnnf. If you need more informations to try and investigate, please let me know. Big thanks to anyone that will try to help
    • [00:02:07] [main/ERROR]: Missing or unsupported mandatory dependencies:     Mod ID: 'kotlinforforge', Requested by: 'flightlib', Expected range: '[4.3.0,)', Actual version: '[MISSING]'     Mod ID: 'terrablender', Requested by: 'biomesoplenty', Expected range: '[,)', Actual version: '[MISSING]'     Mod ID: 'geckolib', Requested by: 'cakescosmetics', Expected range: '[4.4,)', Actual version: '[MISSING]'     Mod ID: 'balm', Requested by: 'waystones', Expected range: '[7.2.0,)', Actual version: '[MISSING]'     Mod ID: 'oculus', Requested by: 'irisflw', Expected range: '[1.6.15,)', Actual version: '[MISSING]'     Mod ID: 'cupboard', Requested by: 'betterfpsdist', Expected range: '[1.20.1-1.5,)', Actual version: '[MISSING]' [00:02:53] [main/WARN]: Mod file C:\Users\ezkid\AppData\Roaming\.minecraft\libraries\net\minecraftforge\fmlcore\1.20.1-47.2.32\fmlcore-1.20.1-47.2.32.jar is missing mods.toml file [00:02:54] [main/WARN]: Mod file C:\Users\ezkid\AppData\Roaming\.minecraft\libraries\net\minecraftforge\javafmllanguage\1.20.1-47.2.32\javafmllanguage-1.20.1-47.2.32.jar is missing mods.toml file [00:02:54] [main/WARN]: Mod file C:\Users\ezkid\AppData\Roaming\.minecraft\libraries\net\minecraftforge\lowcodelanguage\1.20.1-47.2.32\lowcodelanguage-1.20.1-47.2.32.jar is missing mods.toml file [00:02:54] [main/WARN]: Mod file C:\Users\ezkid\AppData\Roaming\.minecraft\libraries\net\minecraftforge\mclanguage\1.20.1-47.2.32\mclanguage-1.20.1-47.2.32.jar is missing mods.toml file [00:02:65] [main/ERROR]: Skipping early mod setup due to previous error
    • Guns and more cool stuff
    • nvm i did it, turn out i just needed to install a drive or smth
  • Topics

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.