aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java
blob: da12fc353dbebeb6145e2fd31c21f162da20c059 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.anthonyhilyard.iceberg.mixin;

import java.lang.reflect.Field;
import java.util.List;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import com.anthonyhilyard.iceberg.Loader;

import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.world.item.ItemStack;
import net.minecraft.network.chat.Component;

@Mixin(Screen.class)
public class ScreenMixin
{
	@Inject(method = "getTooltipFromItem", at = @At(value = "HEAD"))
	private static List<Component> getTooltipFromItem(Minecraft minecraft, ItemStack itemStack, CallbackInfoReturnable<List<Component>> info)
	{
		if (FabricLoader.getInstance().isModLoaded("andromeda"))
		{
			try
			{
				Field tooltipStackField = GuiGraphics.class.getDeclaredField("icebergTooltipStack");
				tooltipStackField.setAccessible(true);
				tooltipStackField.set(null, itemStack);
			}
			catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e)
			{
				Loader.LOGGER.error(ExceptionUtils.getStackTrace(e));
			}
		}
		return info.getReturnValue();
	}
}