From 37cebc102e4b8538e40b5d034fa11faf1db0cd2e Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Fri, 12 Jan 2024 13:04:49 +0000 Subject: [PATCH] Back to redirects --- .../fabric/mixin/item/BlockItemMixin.java | 7 ++--- .../fabric/mixin/item/CatEntityMixin.java | 11 ++++--- .../item/CookingRecipeJsonBuilderMixin.java | 7 ++--- .../fabricmc/fabric/mixin/item/ItemMixin.java | 23 +++++++-------- .../fabric/mixin/item/LivingEntityMixin.java | 15 +++++----- .../fabric/mixin/item/WolfEntityMixin.java | 29 ++++++++----------- 6 files changed, 41 insertions(+), 51 deletions(-) diff --git a/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/BlockItemMixin.java b/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/BlockItemMixin.java index 9a939aaafa..bef3b5e09a 100644 --- a/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/BlockItemMixin.java +++ b/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/BlockItemMixin.java @@ -16,18 +16,17 @@ package net.fabricmc.fabric.mixin.item; -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemUsageContext; @Mixin(BlockItem.class) class BlockItemMixin { - @WrapOperation(method = "useOnBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/BlockItem;isFood()Z")) - private boolean isStackAwareFood(BlockItem instance, Operation original, ItemUsageContext context) { + @Redirect(method = "useOnBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/BlockItem;isFood()Z")) + private boolean isStackAwareFood(BlockItem instance, ItemUsageContext context) { return context.getStack().isFood(); } } diff --git a/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/CatEntityMixin.java b/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/CatEntityMixin.java index 2ce028686d..45040e85a9 100644 --- a/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/CatEntityMixin.java +++ b/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/CatEntityMixin.java @@ -16,11 +16,10 @@ package net.fabricmc.fabric.mixin.item; -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; import net.minecraft.entity.passive.CatEntity; import net.minecraft.entity.player.PlayerEntity; @@ -30,13 +29,13 @@ @Mixin(CatEntity.class) class CatEntityMixin { - @WrapOperation(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getFoodComponent()Lnet/minecraft/item/FoodComponent;")) - private @Nullable FoodComponent getStackAwareFoodComponent(Item instance, Operation original, PlayerEntity player, Hand hand) { + @Redirect(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getFoodComponent()Lnet/minecraft/item/FoodComponent;")) + private @Nullable FoodComponent getStackAwareFoodComponent(Item instance, PlayerEntity player, Hand hand) { return player.getStackInHand(hand).getFoodComponent(); } - @WrapOperation(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;isFood()Z")) - private boolean isStackAwareFood(Item instance, Operation original, PlayerEntity player, Hand hand) { + @Redirect(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;isFood()Z")) + private boolean isStackAwareFood(Item instance, PlayerEntity player, Hand hand) { return player.getStackInHand(hand).isFood(); } } diff --git a/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/CookingRecipeJsonBuilderMixin.java b/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/CookingRecipeJsonBuilderMixin.java index 903cf66e11..ebb69882ed 100644 --- a/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/CookingRecipeJsonBuilderMixin.java +++ b/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/CookingRecipeJsonBuilderMixin.java @@ -16,18 +16,17 @@ package net.fabricmc.fabric.mixin.item; -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; import net.minecraft.data.server.recipe.CookingRecipeJsonBuilder; import net.minecraft.item.Item; @Mixin(CookingRecipeJsonBuilder.class) class CookingRecipeJsonBuilderMixin { - @WrapOperation(method = "getSmeltingRecipeCategory", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;isFood()Z")) - private static boolean isStackAwareFood(Item instance, Operation original) { + @Redirect(method = "getSmeltingRecipeCategory", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;isFood()Z")) + private static boolean isStackAwareFood(Item instance) { return instance.getDefaultStack().isFood(); } } diff --git a/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/ItemMixin.java b/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/ItemMixin.java index c6c5e3b29b..8d18b0b434 100644 --- a/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/ItemMixin.java +++ b/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/ItemMixin.java @@ -16,13 +16,12 @@ package net.fabricmc.fabric.mixin.item; -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.minecraft.entity.LivingEntity; @@ -76,28 +75,28 @@ public void fabric_setCustomDamageHandler(@Nullable CustomDamageHandler handler) this.customDamageHandler = handler; } - @WrapOperation(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getFoodComponent()Lnet/minecraft/item/FoodComponent;")) - private @Nullable FoodComponent getStackAwareFoodComponent(Item instance, Operation original, World world, PlayerEntity user, Hand hand) { + @Redirect(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getFoodComponent()Lnet/minecraft/item/FoodComponent;")) + private @Nullable FoodComponent getStackAwareFoodComponent(Item instance, World world, PlayerEntity user, Hand hand) { return user.getStackInHand(hand).getFoodComponent(); } - @WrapOperation(method = "getMaxUseTime", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getFoodComponent()Lnet/minecraft/item/FoodComponent;")) - private @Nullable FoodComponent getStackAwareFoodComponent(Item instance, Operation original, ItemStack stack) { + @Redirect(method = "getMaxUseTime", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getFoodComponent()Lnet/minecraft/item/FoodComponent;")) + private @Nullable FoodComponent getStackAwareFoodComponent(Item instance, ItemStack stack) { return stack.getFoodComponent(); } - @WrapOperation(method = {"getMaxUseTime", "getUseAction"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;isFood()Z")) - private boolean isStackAwareFood(Item instance, Operation original, ItemStack stack) { + @Redirect(method = {"getMaxUseTime", "getUseAction"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;isFood()Z")) + private boolean isStackAwareFood(Item instance, ItemStack stack) { return stack.isFood(); } - @WrapOperation(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;isFood()Z")) - private boolean isStackAwareFood(Item instance, Operation original, World world, PlayerEntity user, Hand hand) { + @Redirect(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;isFood()Z")) + private boolean isStackAwareFood(Item instance, World world, PlayerEntity user, Hand hand) { return user.getStackInHand(hand).isFood(); } - @WrapOperation(method = "finishUsing", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;isFood()Z")) - private boolean isStackAwareFood(Item instance, Operation original, ItemStack stack, World world, LivingEntity user) { + @Redirect(method = "finishUsing", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;isFood()Z")) + private boolean isStackAwareFood(Item instance, ItemStack stack, World world, LivingEntity user) { return stack.isFood(); } } diff --git a/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/LivingEntityMixin.java b/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/LivingEntityMixin.java index 5d8a410bc7..920468203a 100644 --- a/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/LivingEntityMixin.java +++ b/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/LivingEntityMixin.java @@ -16,13 +16,12 @@ package net.fabricmc.fabric.mixin.item; -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import net.minecraft.entity.EquipmentSlot; @@ -49,18 +48,18 @@ private static void onGetPreferredEquipmentSlot(ItemStack stack, CallbackInfoRet } } - @WrapOperation(method = "shouldSpawnConsumptionEffects", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getFoodComponent()Lnet/minecraft/item/FoodComponent;")) - private @Nullable FoodComponent getStackAwareFoodComponent(Item instance, Operation original) { + @Redirect(method = "shouldSpawnConsumptionEffects", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getFoodComponent()Lnet/minecraft/item/FoodComponent;")) + private @Nullable FoodComponent getStackAwareFoodComponent(Item instance) { return this.activeItemStack.getFoodComponent(); } - @WrapOperation(method = "applyFoodEffects", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getFoodComponent()Lnet/minecraft/item/FoodComponent;")) - private @Nullable FoodComponent getStackAwareFoodComponent(Item instance, Operation original, ItemStack stack, World world, LivingEntity targetEntity) { + @Redirect(method = "applyFoodEffects", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getFoodComponent()Lnet/minecraft/item/FoodComponent;")) + private @Nullable FoodComponent getStackAwareFoodComponent(Item instance, ItemStack stack, World world, LivingEntity targetEntity) { return stack.getFoodComponent(); } - @WrapOperation(method = "applyFoodEffects", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;isFood()Z")) - private boolean isStackAwareFood(Item instance, Operation original, ItemStack stack, World world, LivingEntity targetEntity) { + @Redirect(method = "applyFoodEffects", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;isFood()Z")) + private boolean isStackAwareFood(Item instance, ItemStack stack, World world, LivingEntity targetEntity) { return stack.isFood(); } } diff --git a/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/WolfEntityMixin.java b/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/WolfEntityMixin.java index 3b81ceab3a..ff75a048e9 100644 --- a/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/WolfEntityMixin.java +++ b/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/WolfEntityMixin.java @@ -16,13 +16,13 @@ package net.fabricmc.fabric.mixin.item; -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Share; +import com.llamalad7.mixinextras.sugar.ref.LocalRef; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import net.minecraft.entity.passive.WolfEntity; @@ -35,28 +35,23 @@ @Mixin(WolfEntity.class) class WolfEntityMixin { - @Unique - private static final ThreadLocal INTERACTION_STACK = new ThreadLocal<>(); - @Inject(method = "interactMob", at = @At("HEAD")) - private void storeCopy(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - INTERACTION_STACK.set(player.getStackInHand(hand).copy()); + private void storeCopy(PlayerEntity player, Hand hand, CallbackInfoReturnable cir, @Share("interaction_stack") LocalRef stackRef) { + stackRef.set(player.getStackInHand(hand).copy()); } - @WrapOperation(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getFoodComponent()Lnet/minecraft/item/FoodComponent;")) - private @Nullable FoodComponent getStackAwareFoodComponent(Item instance, Operation original, PlayerEntity player, Hand hand) { - FoodComponent fc = INTERACTION_STACK.get().getFoodComponent(); - INTERACTION_STACK.remove(); - return fc; + @Redirect(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getFoodComponent()Lnet/minecraft/item/FoodComponent;")) + private @Nullable FoodComponent getStackAwareFoodComponent(Item instance, PlayerEntity player, Hand hand, @Share("interaction_stack") LocalRef stackRef) { + return stackRef.get().getFoodComponent(); } - @WrapOperation(method = "isBreedingItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getFoodComponent()Lnet/minecraft/item/FoodComponent;")) - private @Nullable FoodComponent getStackAwareFoodComponent(Item instance, Operation original, ItemStack stack) { + @Redirect(method = "isBreedingItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getFoodComponent()Lnet/minecraft/item/FoodComponent;")) + private @Nullable FoodComponent getStackAwareFoodComponent(Item instance, ItemStack stack) { return stack.getFoodComponent(); } - @WrapOperation(method = "isBreedingItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;isFood()Z", ordinal = 0)) - private boolean isStackAwareFood(Item instance, Operation original, ItemStack stack) { + @Redirect(method = "isBreedingItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;isFood()Z", ordinal = 0)) + private boolean isStackAwareFood(Item instance, ItemStack stack) { return stack.isFood(); } }