Skip to content

Commit

Permalink
Fix review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Jan 5, 2024
1 parent cd8b264 commit 80bb77f
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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;
Expand All @@ -33,18 +34,18 @@

@Mixin(WolfEntity.class)
class WolfEntityMixin {
@SuppressWarnings("MissingUnique")
private static final ThreadLocal<ItemStack> fabric_interactMob_itemStack = new ThreadLocal<>();
@Unique
private static final ThreadLocal<ItemStack> INTERACTION_STACK = new ThreadLocal<>();

@Inject(method = "interactMob", at = @At("HEAD"))
private void storeCopy(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
fabric_interactMob_itemStack.set(player.getStackInHand(hand).copy());
INTERACTION_STACK.set(player.getStackInHand(hand).copy());
}

@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) {
FoodComponent fc = fabric_interactMob_itemStack.get().getFoodComponent();
fabric_interactMob_itemStack.remove();
FoodComponent fc = INTERACTION_STACK.get().getFoodComponent();
INTERACTION_STACK.remove();
return fc;
}

Expand Down

0 comments on commit 80bb77f

Please sign in to comment.