aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/dulkirfabric/mixin/ItemStackMixin.java27
-rw-r--r--src/main/java/com/dulkirfabric/mixin/render/DrawContextMixin.java19
2 files changed, 46 insertions, 0 deletions
diff --git a/src/main/java/com/dulkirfabric/mixin/ItemStackMixin.java b/src/main/java/com/dulkirfabric/mixin/ItemStackMixin.java
new file mode 100644
index 0000000..5fdd7f5
--- /dev/null
+++ b/src/main/java/com/dulkirfabric/mixin/ItemStackMixin.java
@@ -0,0 +1,27 @@
+package com.dulkirfabric.mixin;
+
+import com.dulkirfabric.util.ItemChangeHandler;
+import net.minecraft.client.item.TooltipContext;
+import net.minecraft.entity.player.PlayerEntity;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.text.Text;
+import org.jetbrains.annotations.Nullable;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
+
+import java.util.List;
+
+@Mixin(ItemStack.class)
+public abstract class ItemStackMixin {
+ @Shadow public abstract Item getItem();
+
+ @Inject(method = "getTooltip", at = @At("HEAD"))
+ private void onGetTooltip(@Nullable PlayerEntity player, TooltipContext context, CallbackInfoReturnable<List<Text>> cir) {
+ ItemChangeHandler.INSTANCE.handle(this.getItem().getName().getString());
+ }
+}
diff --git a/src/main/java/com/dulkirfabric/mixin/render/DrawContextMixin.java b/src/main/java/com/dulkirfabric/mixin/render/DrawContextMixin.java
index 9b6cac3..1bef0f5 100644
--- a/src/main/java/com/dulkirfabric/mixin/render/DrawContextMixin.java
+++ b/src/main/java/com/dulkirfabric/mixin/render/DrawContextMixin.java
@@ -1,16 +1,29 @@
package com.dulkirfabric.mixin.render;
+import com.dulkirfabric.events.TooltipRenderChangeEvent;
import com.dulkirfabric.features.TooltipImpl;
+import com.dulkirfabric.util.ItemChangeHandler;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
+import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
+import net.minecraft.client.gui.tooltip.TooltipComponent;
import net.minecraft.client.gui.tooltip.TooltipPositioner;
+import net.minecraft.client.util.math.MatrixStack;
import org.joml.Vector2ic;
+import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import java.util.List;
@Mixin(DrawContext.class)
public class DrawContextMixin {
+ @Shadow @Final private MatrixStack matrices;
+ List<TooltipComponent> prevComponents;
@WrapOperation(method = "drawTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;IILnet/minecraft/client/gui/tooltip/TooltipPositioner;)V",
at = @At(target = "Lnet/minecraft/client/gui/tooltip/TooltipPositioner;getPosition(IIIIII)Lorg/joml/Vector2ic;", value = "INVOKE"))
@@ -18,4 +31,10 @@ public class DrawContextMixin {
Vector2ic v = operation.call(positionerInstance, sw, sh, mx, my, tw, th);
return TooltipImpl.INSTANCE.calculatePos(v);
}
+
+ @Inject(method = "drawTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;IILnet/minecraft/client/gui/tooltip/TooltipPositioner;)V",
+ at = @At(target = "Lnet/minecraft/client/util/math/MatrixStack;push()V", value = "INVOKE"))
+ public void onPush(TextRenderer textRenderer, List<TooltipComponent> components, int x, int y, TooltipPositioner positioner, CallbackInfo ci) {
+ TooltipImpl.INSTANCE.applyScale(matrices);
+ }
}