
FabricShieldEnchantments can be enchanted on any item
dsfhdshdjtsb opened this issue ยท 13 comments
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)
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.
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.
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
Harvest Sythes has a solution to this.
https://github.com/LordDeatHunter/HarvestScythes/blob/master/src/main/java/wraith/harvest_scythes/enchantment/CustomEnchantmentTargets.java
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"