Fabric Shield Lib

Fabric Shield Lib

3M Downloads

FabricShieldEnchantments can be enchanted on any item

dsfhdshdjtsb opened this issue ยท 13 comments

commented

The enchantments that are supposed to only show up on shields can show up on any item in the enchantment table(including the reflection enchantment from the dev environment)

commented

Can confirm, but I cannot figure out why. There is a check for this sort of thing.

    @Override
    public boolean isAcceptableItem(ItemStack stack) {
        return stack.getItem() instanceof FabricShield || stack.getItem() instanceof ShieldItem;
    }

We have this code but something is wrong. Needs more investigation.

commented

Here's our problem which someone else is experiencing

commented

Capture+_2021-12-26-17-10-41

commented

What version of minecraft was this in?

commented

This seems to be a problem with how isAcceptableItem works in general

commented

I figured out the problem, but not the solution :)

The Enchantment Table generates valid enchantments for the item by going through every single enchantment and testing if it is valid for the current item(this is in a method in the enchantmentHelper class, forgot name). However, it calls the isAcceptableItem method off of each enchantment's Target(ex: WEAPON, HELMET, BREAKABLE, etc.) not the enchantment itself. That means the isAcceptableItem from the FabricShieldEnchantment is not called, rather the one from its target, BREAKABLE, is called, which makes the enchantment applicable to every breakable item.

I've tried to fix this by using @reDIrect when the method isAcceptableItem is called, but since it is called off of the enchantment target and not the enchantment, I was still unable to access the overwritten isAcceptableItem. I think heavier mixins could fix this, but it may be a lot of work.

commented

Capture+_2021-12-26-17-10-41

Oh hey thats my post lmao :)

commented

I figured out the problem, but not the solution :)

The Enchantment Table generates valid enchantments for the item by going through every single enchantment and testing if it is valid for the current item(this is in a method in the enchantmentHelper class, forgot name). However, it calls the isAcceptableItem method off of each enchantment's Target(ex: WEAPON, HELMET, BREAKABLE, etc.) not the enchantment itself. That means the isAcceptableItem from the FabricShieldEnchantment is not called, rather the one from its target, BREAKABLE, is called, which makes the enchantment applicable to every breakable item.

I've tried to fix this by using @reDIrect when the method isAcceptableItem is called, but since it is called off of the enchantment target and not the enchantment, I was still unable to access the overwritten isAcceptableItem. I think heavier mixins could fix this, but it may be a lot of work.

hmm yeah heavy mixins will be needed

commented

Capture+_2021-12-26-17-10-41

Oh hey thats my post lmao :)

What a coincidence lol

commented

They seem to be using this to be able to edit the enums

modImplementation("com.github.Chocohead:Fabric-ASM:v2.3") {
exclude (group: "net.fabricmc.fabric-api")
}
include "com.github.Chocohead:Fabric-ASM:v2.3"

commented

Adding Fabric-ASM seems to break everything else

commented

Never mind I was doing it wrong last time. This has been fixed in the latest commit