|
18 | 18 | package com.lambda.mixin.render; |
19 | 19 |
|
20 | 20 | import com.lambda.module.modules.render.ContainerPreview; |
| 21 | +import com.lambda.module.modules.render.MapPreview; |
| 22 | +import net.minecraft.client.MinecraftClient; |
21 | 23 | import net.minecraft.client.font.TextRenderer; |
22 | 24 | 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.client.render.MapRenderState; |
| 26 | +import net.minecraft.component.DataComponentTypes; |
| 27 | +import net.minecraft.item.FilledMapItem; |
25 | 28 | import net.minecraft.item.ItemStack; |
| 29 | +import net.minecraft.item.Items; |
26 | 30 | import net.minecraft.item.tooltip.TooltipData; |
27 | 31 | import net.minecraft.text.Text; |
28 | 32 | import net.minecraft.util.Identifier; |
29 | 33 | import org.jetbrains.annotations.Nullable; |
| 34 | +import org.joml.Matrix3x2fStack; |
| 35 | +import org.spongepowered.asm.mixin.Final; |
30 | 36 | import org.spongepowered.asm.mixin.Mixin; |
| 37 | +import org.spongepowered.asm.mixin.Shadow; |
| 38 | +import org.spongepowered.asm.mixin.Unique; |
31 | 39 | import org.spongepowered.asm.mixin.injection.At; |
32 | 40 | import org.spongepowered.asm.mixin.injection.Inject; |
33 | 41 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
34 | 42 |
|
35 | 43 | import java.util.List; |
36 | 44 | import java.util.Optional; |
37 | 45 |
|
| 46 | +/* |
| 47 | +Map slot rendering code |
| 48 | +Original source: https://github.com/Crec0/map-in-slot |
| 49 | +Copyright (c) 2022 Crec0 |
| 50 | +Licensed under MIT License |
| 51 | + */ |
38 | 52 | @Mixin(DrawContext.class) |
39 | | -public class DrawContextMixin { |
| 53 | +public abstract class DrawContextMixin { |
| 54 | + @Shadow |
| 55 | + @Final |
| 56 | + MinecraftClient client; |
| 57 | + |
| 58 | + @Unique |
| 59 | + private final MapRenderState mapRenderState = new MapRenderState(); |
| 60 | + |
| 61 | + @Shadow |
| 62 | + public abstract Matrix3x2fStack getMatrices(); |
| 63 | + |
| 64 | + @Shadow |
| 65 | + public abstract void drawMap(MapRenderState mapRenderState); |
| 66 | + |
| 67 | + @Inject(method = "drawStackOverlay(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", at = @At(value = "TAIL")) |
| 68 | + private void injectDrawMap(TextRenderer textRenderer, ItemStack stack, int i, int j, String string, CallbackInfo ci) { |
| 69 | + if (MapPreview.INSTANCE.isDisabled() || !MapPreview.getShowInSlot()) return; |
| 70 | + |
| 71 | + if (!stack.isOf(Items.FILLED_MAP)) return; |
| 72 | + |
| 73 | + var mapId = stack.get(DataComponentTypes.MAP_ID); |
| 74 | + var savedData = FilledMapItem.getMapState(mapId, client.world); |
| 75 | + |
| 76 | + if (savedData == null) return; |
| 77 | + |
| 78 | + this.getMatrices().pushMatrix(); |
| 79 | + this.getMatrices().translate(i, j); |
| 80 | + this.getMatrices().scale(0.125F, 0.125F); |
| 81 | + |
| 82 | + client.getMapRenderer().update(mapId, savedData, this.mapRenderState); |
| 83 | + this.drawMap(this.mapRenderState); |
| 84 | + |
| 85 | + this.getMatrices().popMatrix(); |
| 86 | + } |
| 87 | + |
40 | 88 | @Inject(method = "drawTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;Ljava/util/Optional;IILnet/minecraft/util/Identifier;)V", at = @At("HEAD"), cancellable = true) |
41 | 89 | private void onDrawTooltip(TextRenderer textRenderer, List<Text> text, Optional<TooltipData> data, int x, int y, @Nullable Identifier texture, CallbackInfo ci) { |
42 | 90 | if (!ContainerPreview.INSTANCE.isEnabled()) return; |
|
0 commit comments