Skip to content

Commit 5a1d6c1

Browse files
committed
feat: map preview
1 parent 752bb58 commit 5a1d6c1

File tree

6 files changed

+111
-0
lines changed

6 files changed

+111
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.DrawContext;
22+
import net.minecraft.client.gui.screen.ingame.HandledScreen;
23+
import net.minecraft.item.Items;
24+
import net.minecraft.screen.slot.Slot;
25+
import org.spongepowered.asm.mixin.Mixin;
26+
import org.spongepowered.asm.mixin.Shadow;
27+
import org.spongepowered.asm.mixin.injection.At;
28+
import org.spongepowered.asm.mixin.injection.Inject;
29+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
30+
31+
import javax.annotation.Nullable;
32+
33+
@Mixin(HandledScreen.class)
34+
public abstract class HandledScreenMixin {
35+
@Shadow @Nullable public Slot focusedSlot;
36+
37+
@Inject(method = "drawMouseoverTooltip", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;Ljava/util/Optional;II)V"), cancellable = true)
38+
void injectTooltip(DrawContext context, int x, int y, CallbackInfo ci) {
39+
if (focusedSlot == null) return;
40+
41+
var stack = focusedSlot.getStack();
42+
if (stack.isOf(Items.FILLED_MAP) && MapPreview.INSTANCE.isEnabled()) {
43+
ci.cancel(); // fck off lmao
44+
MapPreview.drawMap(stack, x, y);
45+
}
46+
}
47+
}

common/src/main/kotlin/com/lambda/graphics/renderer/gui/TextureRenderer.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ object TextureRenderer {
3838
shader.use()
3939

4040
drawInternal(rect)
41+
texture.unbind()
4142
}
4243

4344
fun drawTextureShaded(texture: Texture, rect: Rect) {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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.module.modules.render
19+
20+
import com.lambda.graphics.buffer.pixel.PixelBuffer
21+
import com.lambda.graphics.texture.Texture
22+
import com.lambda.module.Module
23+
import com.lambda.module.tag.ModuleTag
24+
import com.lambda.threading.runSafe
25+
import com.lambda.util.math.Vec2d
26+
import net.minecraft.item.FilledMapItem
27+
import net.minecraft.item.ItemStack
28+
import org.lwjgl.BufferUtils
29+
import org.lwjgl.opengl.GL11.GL_RGB
30+
import org.lwjgl.opengl.GL11.GL_RGBA
31+
import org.lwjgl.opengl.GL45C.GL_TEXTURE_2D
32+
import org.lwjgl.opengl.GL45C.glBindTexture
33+
34+
object MapPreview : Module(
35+
name = "MapPreview",
36+
description = "Preview maps in your inventory",
37+
defaultTags = setOf(ModuleTag.RENDER)
38+
) {
39+
private val scale by setting("Scale", 0.7, 0.1..1.0, 0.05)
40+
41+
private val buffer = BufferUtils.createByteBuffer(128*128)
42+
private val texture = Texture(buffer, 128, 128, format = GL_RGB, levels = 1)
43+
private val pbo = PixelBuffer(texture)
44+
45+
@JvmStatic
46+
fun drawMap(stack: ItemStack, x: Int, y: Int) = runSafe {
47+
val state = FilledMapItem.getMapState(stack, world) ?: return@runSafe
48+
buffer.put(state.colors)
49+
buffer.flip()
50+
51+
val base = Vec2d(x, y)
52+
53+
texture.bind()
54+
texture.update(buffer, 128, 128)
55+
56+
texture.draw(base, scale)
57+
}
58+
}

common/src/main/kotlin/com/lambda/util/math/Rect.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ data class Rect(private val pos1: Vec2d, private val pos2: Vec2d) {
6565
fun basedOn(base: Vec2d, width: Double, height: Double) =
6666
Rect(base, base + Vec2d(width, height))
6767

68+
fun basedOn(base: Vec2d, width: Int, height: Int) =
69+
Rect(base, base + Vec2d(width, height))
70+
6871
fun basedOn(base: Vec2d, size: Vec2d) =
6972
Rect(base, base + size)
7073

common/src/main/resources/lambda.accesswidener

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ accessible field net/minecraft/network/packet/c2s/login/LoginKeyC2SPacket nonce
6666
accessible field net/minecraft/world/explosion/Explosion behavior Lnet/minecraft/world/explosion/ExplosionBehavior;
6767
accessible field net/minecraft/structure/StructureTemplate blockInfoLists Ljava/util/List;
6868
accessible method net/minecraft/item/BlockItem getPlacementState (Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/block/BlockState;
69+
accessible field net/minecraft/client/gui/screen/ingame/HandledScreen focusedSlot Lnet/minecraft/screen/slot/Slot;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"render.DebugHudMixin",
3333
"render.GameRendererMixin",
3434
"render.GlStateManagerMixin",
35+
"render.HandledScreenMixin",
3536
"render.InGameHudMixin",
3637
"render.InGameOverlayRendererMixin",
3738
"render.LightmapTextureManagerMixin",

0 commit comments

Comments
 (0)