Skip to content

Commit d2d41ee

Browse files
committed
Added Container Preview
1 parent 5c7a1c7 commit d2d41ee

File tree

6 files changed

+443
-0
lines changed

6 files changed

+443
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.items;
19+
20+
import com.lambda.module.modules.render.ContainerPreview;
21+
import net.minecraft.item.BlockItem;
22+
import net.minecraft.item.Item;
23+
import net.minecraft.item.ItemStack;
24+
import net.minecraft.item.tooltip.TooltipData;
25+
import org.spongepowered.asm.mixin.Mixin;
26+
27+
import java.util.Optional;
28+
29+
@Mixin(BlockItem.class)
30+
public class BlockItemMixin extends Item {
31+
public BlockItemMixin(Settings settings) {
32+
super(settings);
33+
}
34+
35+
@Override
36+
public Optional<TooltipData> getTooltipData(ItemStack stack) {
37+
if (ContainerPreview.INSTANCE.isEnabled() && ContainerPreview.isShulkerBox(stack)) {
38+
return Optional.of(new ContainerPreview.ShulkerComponent(stack));
39+
}
40+
return super.getTooltipData(stack);
41+
}
42+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
}

src/main/java/com/lambda/mixin/render/ScreenMixin.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
package com.lambda.mixin.render;
1919

2020
import com.lambda.gui.components.QuickSearch;
21+
import com.lambda.module.modules.render.ContainerPreview;
2122
import com.lambda.module.modules.render.NoRender;
23+
import net.minecraft.client.MinecraftClient;
2224
import net.minecraft.client.gui.DrawContext;
2325
import net.minecraft.client.gui.screen.Screen;
2426
import org.lwjgl.glfw.GLFW;
@@ -42,4 +44,12 @@ private void onKeyPressed(int keyCode, int scanCode, int modifiers, CallbackInfo
4244
private void injectRenderInGameBackground(DrawContext context, CallbackInfo ci) {
4345
if (NoRender.INSTANCE.isEnabled() && NoRender.getNoGuiShadow()) ci.cancel();
4446
}
47+
48+
@Inject(method = "renderWithTooltip", at = @At("TAIL"))
49+
private void onRenderWithTooltip(DrawContext context, int mouseX, int mouseY, float deltaTicks, CallbackInfo ci) {
50+
// Render locked container preview tooltip at the end of screen rendering
51+
if (ContainerPreview.INSTANCE.isEnabled() && ContainerPreview.isLocked()) {
52+
ContainerPreview.renderLockedTooltip(context, MinecraftClient.getInstance().textRenderer);
53+
}
54+
}
4555
}

src/main/java/com/lambda/mixin/render/TooltipComponentMixin.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.lambda.mixin.render;
1919

20+
import com.lambda.module.modules.render.ContainerPreview;
2021
import com.lambda.module.modules.render.MapPreview;
2122
import net.minecraft.client.gui.tooltip.BundleTooltipComponent;
2223
import net.minecraft.client.gui.tooltip.ProfilesTooltipComponent;
@@ -32,6 +33,13 @@
3233
public interface TooltipComponentMixin {
3334
@Inject(method = "of(Lnet/minecraft/item/tooltip/TooltipData;)Lnet/minecraft/client/gui/tooltip/TooltipComponent;", at = @At("HEAD"), cancellable = true)
3435
private static void of(TooltipData tooltipData, CallbackInfoReturnable<TooltipComponent> cir) {
36+
// Handle ContainerPreview shulker box tooltip
37+
if (ContainerPreview.INSTANCE.isEnabled() && tooltipData instanceof ContainerPreview.ShulkerComponent shulkerComponent) {
38+
cir.setReturnValue(shulkerComponent);
39+
return;
40+
}
41+
42+
// Handle MapPreview map tooltip
3543
if (MapPreview.INSTANCE.isEnabled()) cir.setReturnValue((switch (tooltipData) {
3644
case MapPreview.MapComponent mapComponent -> mapComponent;
3745
case BundleTooltipData bundleTooltipData -> new BundleTooltipComponent(bundleTooltipData.contents());

0 commit comments

Comments
 (0)