Skip to content

Commit 278a280

Browse files
committed
Cherry-pick 6526138
1 parent 6cab785 commit 278a280

File tree

5 files changed

+93
-71
lines changed

5 files changed

+93
-71
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.MapPreview;
21+
import net.minecraft.client.item.TooltipData;
22+
import net.minecraft.item.FilledMapItem;
23+
import net.minecraft.item.Item;
24+
import net.minecraft.item.ItemStack;
25+
import org.spongepowered.asm.mixin.Mixin;
26+
27+
import java.util.Optional;
28+
29+
@Mixin(FilledMapItem.class)
30+
public class FilledMapItemMixin extends Item {
31+
public FilledMapItemMixin(Item.Settings settings) {
32+
super(settings);
33+
}
34+
35+
@Override
36+
public Optional<TooltipData> getTooltipData(ItemStack stack) {
37+
return Optional.of(new MapPreview.MapComponent(stack));
38+
}
39+
}

common/src/main/java/com/lambda/mixin/render/DrawContextMixin.java

Lines changed: 0 additions & 64 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.MapPreview;
21+
import net.minecraft.client.gui.tooltip.BundleTooltipComponent;
22+
import net.minecraft.client.gui.tooltip.TooltipComponent;
23+
import net.minecraft.client.item.BundleTooltipData;
24+
import net.minecraft.client.item.TooltipData;
25+
import org.spongepowered.asm.mixin.Mixin;
26+
import org.spongepowered.asm.mixin.injection.At;
27+
import org.spongepowered.asm.mixin.injection.Inject;
28+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
29+
30+
@Mixin(TooltipComponent.class)
31+
public interface TooltipComponentMixin {
32+
@Inject(method = "of(Lnet/minecraft/client/item/TooltipData;)Lnet/minecraft/client/gui/tooltip/TooltipComponent;", at = @At("HEAD"), cancellable = true)
33+
private static void of(TooltipData data, CallbackInfoReturnable<TooltipComponent> cir) {
34+
if (data instanceof BundleTooltipData) {
35+
cir.setReturnValue(new BundleTooltipComponent((BundleTooltipData)data));
36+
return;
37+
}
38+
39+
if (data instanceof MapPreview.MapComponent) {
40+
cir.setReturnValue((TooltipComponent) data);
41+
return;
42+
}
43+
44+
throw new IllegalArgumentException("Unknown TooltipComponent");
45+
}
46+
}

common/src/main/kotlin/com/lambda/module/modules/render/MapPreview.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.mojang.blaze3d.systems.RenderSystem
2424
import net.minecraft.client.font.TextRenderer
2525
import net.minecraft.client.gui.DrawContext
2626
import net.minecraft.client.gui.tooltip.TooltipComponent
27+
import net.minecraft.client.item.TooltipData
2728
import net.minecraft.item.FilledMapItem
2829
import net.minecraft.item.ItemStack
2930
import net.minecraft.item.map.MapState
@@ -37,18 +38,15 @@ object MapPreview : Module(
3738
) {
3839
private val background = Identifier("textures/map/map_background.png")
3940

40-
// The map component is added via the draw context mixin, thanks mojang
41-
class MapComponent(val stack: ItemStack) : TooltipComponent {
41+
class MapComponent(val stack: ItemStack) : TooltipData, TooltipComponent {
4242
val state: MapState?
4343
get() = FilledMapItem.getMapState(stack, mc.world)
4444

4545
val mapId: Int?
4646
get() = FilledMapItem.getMapId(stack)
4747

48-
override fun drawItems(fontRenderer: TextRenderer, x: Int, y: Int, context: DrawContext) {
48+
override fun drawItems(textRenderer: TextRenderer, x: Int, y: Int, context: DrawContext) {
4949
mapId?.let { id ->
50-
// Values taken from net.minecraft.client.render.item.HeldItemRenderer.renderFirstPersonMap
51-
5250
val matrices = context.matrices
5351

5452
matrices.push()
@@ -59,7 +57,9 @@ object MapPreview : Module(
5957
context.drawTexture(background, -7, -7, 0f, 0f, 142, 142, 142, 142)
6058

6159
matrices.translate(0.0, 0.0, 1.0)
60+
6261
mc.gameRenderer.mapRenderer.draw(matrices, context.vertexConsumers, id, state, true, 240)
62+
matrices.pop()
6363
}
6464
}
6565

common/src/main/resources/lambda.mixins.common.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"input.KeyboardMixin",
2020
"input.MouseMixin",
2121
"items.BarrierBlockMixin",
22+
"items.FilledMapItemMixin",
2223
"items.TridentMixin",
2324
"network.ClientConnectionMixin",
2425
"network.ClientLoginNetworkMixin",
@@ -29,12 +30,11 @@
2930
"render.BackgroundRendererMixin",
3031
"render.BlockRenderManagerMixin",
3132
"render.CameraMixin",
32-
"render.ChatHudMixin",
3333
"render.CapeFeatureRendererMixin",
34+
"render.ChatHudMixin",
3435
"render.ChatInputSuggestorMixin",
3536
"render.ChatScreenMixin",
3637
"render.DebugHudMixin",
37-
"render.DrawContextMixin",
3838
"render.ElytraFeatureRendererMixin",
3939
"render.GameRendererMixin",
4040
"render.GlStateManagerMixin",
@@ -49,6 +49,7 @@
4949
"render.ScreenHandlerMixin",
5050
"render.SplashOverlayMixin",
5151
"render.SplashOverlayMixin$LogoTextureMixin",
52+
"render.TooltipComponentMixin",
5253
"render.VertexBufferMixin",
5354
"render.WorldRendererMixin",
5455
"world.BlockCollisionSpliteratorMixin",

0 commit comments

Comments
 (0)