Jump to content

[SOLVED] Modifying canApply doesn't affect enchantment table


Recommended Posts

Posted (edited)

I'm using Mixins to modify some enchants and where it can be applied to. To do this, I'm changing the canApply field, which works, just not for the enchantment table even tho it says it does.

I've also tried modifying canEnchantAtEnchantingTable, but that didn't seem to work (almost exactly the same code as the code beneath)

Here is the code:

@Mixin(Enchantment.class)
public class EnchantmentMixin {

    @Inject(at = @At("HEAD"), method = "canEnchant", cancellable = true)
    private void Power(ItemStack itemToEnchant, CallbackInfoReturnable<Boolean> info) {
        if (itemToEnchant.getItem() instanceof CrossbowItem) {
            Enchantment e = (Enchantment) ((Object)this);
            if (e instanceof ArrowDamageEnchantment) {
                info.setReturnValue(true);
            }
        }
    }

Does anyone have a good explanation for this or a way to fix it?

Edited by tobywig
Posted

Override boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) in your item class.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)

I don't think you understand what I'm trying to do here. I would like to make the Power enchantment show up in the enchanting table for the crossbow, but to my disappointment, canEnchant does not affect this, but only the anvil, commands (/enchant) etc. I am not making a new item so I would not be able to override canEnchantAtEnchantingTable. I'm using Mixins to attempt to change this.

 

edit: Fixed it. Due to canEnchantAtEnchantingTable being a method added by forge with no mapping, it needed remap=false.

Edited by tobywig
  • tobywig changed the title to [SOLVED] Modifying canApply doesn't affect enchantment table

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.

Announcements



×
×
  • Create New...

Important Information

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