|
| 1 | +/* |
| 2 | + * Copyright 2025 Lambda |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +package com.lambda.mixin.render; |
| 19 | + |
| 20 | +import com.lambda.module.modules.render.ContainerPreview; |
| 21 | +import net.minecraft.client.font.TextRenderer; |
| 22 | +import net.minecraft.client.gui.DrawContext; |
| 23 | +import net.minecraft.client.gui.tooltip.TooltipComponent; |
| 24 | +import net.minecraft.client.gui.tooltip.TooltipPositioner; |
| 25 | +import net.minecraft.item.ItemStack; |
| 26 | +import net.minecraft.item.tooltip.TooltipData; |
| 27 | +import net.minecraft.text.Text; |
| 28 | +import net.minecraft.util.Identifier; |
| 29 | +import org.spongepowered.asm.mixin.Mixin; |
| 30 | +import org.spongepowered.asm.mixin.injection.At; |
| 31 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 32 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 33 | + |
| 34 | +import java.util.List; |
| 35 | +import java.util.Optional; |
| 36 | + |
| 37 | +@Mixin(DrawContext.class) |
| 38 | +public class DrawContextMixin { |
| 39 | + @Inject(method = "drawTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;Ljava/util/Optional;IILnet/minecraft/util/Identifier;)V", at = @At("HEAD"), cancellable = true) |
| 40 | + private void onDrawTooltip(TextRenderer textRenderer, List<Text> text, Optional<TooltipData> data, int x, int y, Identifier texture, CallbackInfo ci) { |
| 41 | + if (!ContainerPreview.INSTANCE.isEnabled()) return; |
| 42 | + |
| 43 | + // Don't intercept if we're rendering a sub-tooltip (prevents infinite recursion) |
| 44 | + if (ContainerPreview.isRenderingSubTooltip()) return; |
| 45 | + |
| 46 | + // If we're locked, always render our locked tooltip and cancel any other tooltip |
| 47 | + if (ContainerPreview.isLocked()) { |
| 48 | + ci.cancel(); |
| 49 | + ContainerPreview.renderLockedTooltip((DrawContext)(Object)this, textRenderer); |
| 50 | + return; |
| 51 | + } |
| 52 | + |
| 53 | + // Check if this is a shulker box tooltip with ContainerPreview |
| 54 | + if (data.isPresent() && data.get() instanceof ContainerPreview.ShulkerComponent component) { |
| 55 | + // Cancel the default tooltip and render our custom one |
| 56 | + ci.cancel(); |
| 57 | + ContainerPreview.renderShulkerTooltip((DrawContext)(Object)this, textRenderer, component, x, y); |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments