Skip to content

Commit

Permalink
injectedd method into Enchantment
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Nov 25, 2023
1 parent 3e7b1e6 commit 590ff57
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 21 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package net.feltmc.feltapi.api.enchanting;

import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;

public interface EnchantmentExtension {
default boolean canApplyAtEnchantingTable(ItemStack stack) {
return stack.getItem().canApplyAtEnchantingTable(stack, (Enchantment) this);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.feltmc.feltapi.mixin.enchanting;

import net.feltmc.feltapi.api.enchanting.BookEnchantableItem;
import net.feltmc.feltapi.api.enchanting.EnchantingItem;
import net.minecraft.world.inventory.AnvilMenu;
import net.minecraft.world.item.EnchantedBookItem;
import net.minecraft.world.item.ItemStack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import net.feltmc.feltapi.api.enchanting.EnchantingItem;
import net.feltmc.feltapi.api.enchanting.EnchantmentExtension;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -10,9 +11,9 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Enchantment.class)
public class EnchantmentMixin {
public class EnchantmentMixin implements EnchantmentExtension {
@Inject(method = "canEnchant", at = @At("HEAD"), cancellable = true)
public void injectEnchantmentCheck(ItemStack stack, CallbackInfoReturnable<Boolean> callback){
callback.setReturnValue(stack.getItem().canApplyAtEnchantingTable(stack, (Enchantment) (Object)this));
callback.setReturnValue(this.canApplyAtEnchantingTable(stack));
}
}
3 changes: 3 additions & 0 deletions felt-enchanting-api/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"loom:injected_interfaces": {
"net/minecraft/class_1792": [
"net/feltmc/feltapi/api/enchanting/EnchantingItem"
],
"net/minecraft/class_1887": [
"net/feltmc/feltapi/api/enchanting/EnchantmentExtension"
]
}
}
Expand Down

0 comments on commit 590ff57

Please sign in to comment.