Jump to content

[SOLVED] Enchantment applies to everything in the game?


GVmG

Recommended Posts

I have made a custom enchantment (of which all behavior is handled separately). I want this item to only apply to my own custom item.

I have tried to use different methods, including overriding the "canEnchant" and "canApplyAtEnchantingTable" methods and such, but somehow that ends up not letting me enchant anything

When I fall back to trying to use the custom EnchantmentCategory, that's when it lets me enchant the custom item... and everything else in the game.

My enchantment code:
 

public class SpaciousEnchantment extends Enchantment {
    public static final EnchantmentCategory ENCH_BACKPACK=EnchantmentCategory.create("backpack_enchants", (i) -> i==BackpackMod.ITEM_BACKPACK.get());

    public SpaciousEnchantment() {
        super(Rarity.VERY_RARE, ENCH_BACKPACK, new EquipmentSlot[]{});
    }

    public static int rowsPerLevel(int level) {
        if (level==1) return 2;
        if (level==2) return 4;
        if (level==3) return 6;
        return 1;
    }

    //we override isCurse and the getFullName methods so we can make this un-removable but have a custom color.
    @Override
    public boolean isCurse() {return true;}

    @Override
    public Component getFullname(int pLevel) {
        MutableComponent mutablecomponent = Component.translatable(this.getDescriptionId());
        mutablecomponent.withStyle(ChatFormatting.GREEN);
        //mutablecomponent.withStyle(ChatFormatting.GRAY);

        if (pLevel != 1 || this.getMaxLevel() != 1) {
            mutablecomponent.append(" ").append(Component.translatable("enchantment.level." + pLevel));
        }

        return mutablecomponent;
    }

    @Override
    public boolean isTreasureOnly() {return true;}
    @Override
    public boolean isTradeable() {return false;}
    @Override
    public boolean isDiscoverable() {return false;}

    @Override
    public int getMaxLevel() {return 3;}
}

I suspected the issue was the EquipmentSlot stuff, but I tried making it {EquipmentSlot.MAINHAND, EquipmentSlot.OFFHAND} and that changed absolutely nothing either, allowing every item in the game to be enchanted.

EDIT: I even tried the "canApplyAtEnchantingTable" method in the item class itself and again, nothing changed (since that only affects the item itself, not every other item). i have no idea why it wont work.

Edited by GVmG
solved
Link to comment
Share on other sites

I did though, and it doesn't seem to be working. It's right at the top of my code.

 

EDIT: cleaned up my IDE's cache, that fixed it. guess it was something behind the scenes with compilation.

Edited by GVmG
solved
Link to comment
Share on other sites

  • GVmG changed the title to [SOLVED] Enchantment applies to everything in the game?

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.

Guest
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.



×
×
  • Create New...

Important Information

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