| 1 | /*
|
| 2 | * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
|
| 3 | * Copyright (c) Meteor Development.
|
| 4 | */
|
| 5 |
|
| 6 | package meteordevelopment.meteorclient.mixin;
|
| 7 |
|
| 8 | import com.llamalad7.mixinextras.injector.ModifyReturnValue;
|
| 9 | import meteordevelopment.meteorclient.MeteorClient;
|
| 10 | import meteordevelopment.meteorclient.events.entity.player.FinishUsingItemEvent;
|
| 11 | import meteordevelopment.meteorclient.events.entity.player.StoppedUsingItemEvent;
|
| 12 | import meteordevelopment.meteorclient.events.game.ItemStackTooltipEvent;
|
| 13 | import meteordevelopment.meteorclient.utils.Utils;
|
| 14 | import net.minecraft.network.chat.Component;
|
| 15 | import net.minecraft.world.entity.LivingEntity;
|
| 16 | import net.minecraft.world.item.ItemStack;
|
| 17 | import net.minecraft.world.level.Level;
|
| 18 | import org.spongepowered.asm.mixin.Mixin;
|
| 19 | import org.spongepowered.asm.mixin.injection.At;
|
| 20 | import org.spongepowered.asm.mixin.injection.Inject;
|
| 21 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
| 22 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
| 23 |
|
| 24 | import java.util.List;
|
| 25 |
|
| 26 | import static meteordevelopment.meteorclient.MeteorClient.mc;
|
| 27 |
|
| 28 | @Mixin(ItemStack.class)
|
| 29 | public abstract class ItemStackMixin {
|
| 30 | @ModifyReturnValue(method = "getTooltipLines", at = @At("RETURN"))
|
| 31 | private List<Component> onGetTooltipLines(List<Component> original) {
|
| 32 | if (Utils.canUpdate()) {
|
| 33 | ItemStackTooltipEvent event = MeteorClient.EVENT_BUS.post(new ItemStackTooltipEvent((ItemStack) (Object) this, original));
|
| 34 | return event.list();
|
| 35 | }
|
| 36 |
|
| 37 | return original;
|
| 38 | }
|
| 39 |
|
| 40 | @Inject(method = "finishUsingItem", at = @At("HEAD"))
|
| 41 | private void onFinishUsingItem(Level level, LivingEntity livingEntity, CallbackInfoReturnable<ItemStack> cir) {
|
| 42 | if (livingEntity == mc.player) {
|
| 43 | MeteorClient.EVENT_BUS.post(FinishUsingItemEvent.get((ItemStack) (Object) this));
|
| 44 | }
|
| 45 | }
|
| 46 |
|
| 47 | @Inject(method = "releaseUsing", at = @At("HEAD"))
|
| 48 | private void onReleaseUsing(Level level, LivingEntity entity, int remainingTime, CallbackInfo ci) {
|
| 49 | if (entity == mc.player) {
|
| 50 | MeteorClient.EVENT_BUS.post(StoppedUsingItemEvent.get((ItemStack) (Object) this));
|
| 51 | }
|
| 52 | }
|
| 53 | }
|
| 54 |
|