Skip to content

Commit

Permalink
Reimplement Z offset forBaseOwoHandledScreen to fix issues with hover…
Browse files Browse the repository at this point in the history
… and item rendering
  • Loading branch information
Dragon-Seeker committed Dec 11, 2024
1 parent 76c26ed commit 5787c96
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
14 changes: 0 additions & 14 deletions src/main/java/io/wispforest/owo/mixin/ui/HandledScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,6 @@ private void clearSlotScissors(DrawContext context, Slot slot, CallbackInfo ci)
GlStateManager._disableScissorTest();
}

// TODO: [1.21.2-Porting] Figure out f such is still needed and how to handle such
// @Inject(method = "drawSlotHighlight", at = @At(value = "HEAD"))
// private static void enableSlotDepth(DrawContext context, int x, int y, int z, CallbackInfo ci) {
// if (!owo$inOwoScreen) return;
// RenderSystem.enableDepthTest();
// context.getMatrices().translate(0, 0, 300);
// }
//
// @Inject(method = "drawSlotHighlight", at = @At("TAIL"))
// private static void clearSlotDepth(DrawContext context, int x, int y, int z, CallbackInfo ci) {
// if (!owo$inOwoScreen) return;
// context.getMatrices().translate(0, 0, -300);
// }

@ModifyVariable(method = "mouseClicked", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/SimpleOption;getValue()Ljava/lang/Object;", ordinal = 0), ordinal = 3)
private int doNoThrow(int slotId, @Local() Slot slot) {
return (((Object) this instanceof BaseOwoHandledScreen<?, ?>) && slot != null) ? slot.id : slotId;
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/io/wispforest/owo/ui/base/BaseOwoHandledScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.slot.Slot;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -330,4 +331,44 @@ public void updateY(int y) {
((SlotAccessor) this.slot).owo$setY(y - BaseOwoHandledScreen.this.y);
}
}

@Override
protected void drawSlotHighlightBack(DrawContext context) {
context.translate(0, 0, getOffsetAmount(true));

super.drawSlotHighlightBack(context);
}

@Override
protected void drawSlotHighlightFront(DrawContext context) {
super.drawSlotHighlightFront(context);

context.translate(0, 0, -getOffsetAmount(true));
}

@Override
protected void drawItem(DrawContext context, ItemStack stack, int x, int y, @Nullable String amountText) {
var offset = getOffsetAmount(false);

context.translate(0, 0, offset);

super.drawItem(context, stack, x, y, amountText);

context.translate(0, 0, -offset);
}

@Override
protected void drawMouseoverTooltip(DrawContext context, int x, int y) {
var offset = getOffsetAmount(false);

context.translate(0, 0, offset);

super.drawMouseoverTooltip(context, x, y);

context.translate(0, 0, offset);
}

protected int getOffsetAmount(boolean slotRendering) {
return 300;
}
}
6 changes: 5 additions & 1 deletion src/main/resources/owo.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ transitive-accessible class net/minecraft/item/ItemGroup$EntriesImpl
transitive-accessible class net/minecraft/client/gui/DrawContext$ScissorStack
transitive-extendable method net/minecraft/client/gui/widget/CheckboxWidget <init> (IIILnet/minecraft/text/Text;Lnet/minecraft/client/font/TextRenderer;ZLnet/minecraft/client/gui/widget/CheckboxWidget$Callback;)V

accessible class net/minecraft/registry/RegistryOps$CachedRegistryInfoGetter
accessible class net/minecraft/registry/RegistryOps$CachedRegistryInfoGetter

extendable method net/minecraft/client/gui/screen/ingame/HandledScreen drawSlotHighlightBack (Lnet/minecraft/client/gui/DrawContext;)V
extendable method net/minecraft/client/gui/screen/ingame/HandledScreen drawSlotHighlightFront (Lnet/minecraft/client/gui/DrawContext;)V
extendable method net/minecraft/client/gui/screen/ingame/HandledScreen drawItem (Lnet/minecraft/client/gui/DrawContext;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V

0 comments on commit 5787c96

Please sign in to comment.