Skip to content

Commit

Permalink
update EnchantmentHelper mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
UpcraftLP committed Feb 2, 2024
1 parent bf6535b commit 95d04ca
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package dev.cammiescorner.camsbackpacks.mixin;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import dev.cammiescorner.camsbackpacks.item.BackpackItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(EnchantmentHelper.class)
public abstract class EnchantmentHelperMixin {

@Inject(method = "getItemEnchantmentLevel", at = @At("HEAD"), cancellable = true)
private static void getItemEnchantmentLevelMixin(Enchantment enchantment, ItemStack stack, CallbackInfoReturnable<Integer> cir) {
if (enchantment == Enchantments.BINDING_CURSE && stack.getItem() instanceof BackpackItem) {
cir.setReturnValue(1);
@ModifyReturnValue(method = "getItemEnchantmentLevel", at = @At("RETURN"))
private static int getItemEnchantmentLevelMixin(int original, Enchantment enchantment, ItemStack stack) {
if (original == 0 && enchantment == Enchantments.BINDING_CURSE && stack.getItem() instanceof BackpackItem) {
return 1;
}

return original;
}
}

0 comments on commit 95d04ca

Please sign in to comment.