Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion api/src/main/java/com/noxcrew/sheeplib/mixin/GuiMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

import com.mojang.blaze3d.platform.Window;
import com.noxcrew.sheeplib.DialogContainer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ComponentPath;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.util.CommonColors;
import net.minecraft.world.scores.Scoreboard;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -15,7 +21,24 @@
* Renders the [DialogContainerScreen].
*/
@Mixin(Gui.class)
public class GuiMixin {
public abstract class GuiMixin {

@Shadow public abstract Font getFont();

@Unique
private int drawContainerFocus(ComponentPath componentPath, GuiGraphics guiGraphics, int y) {
final var font = Minecraft.getInstance().font;
int i = y;
for (
var el = componentPath;
el != null;
el = (el instanceof ComponentPath.Path path) ? path.childPath() : null, i += font.lineHeight
) {
guiGraphics.drawString(font, el.component().toString(), 5, i, CommonColors.WHITE);
}
return i;
}

@SuppressWarnings("InvalidInjectorMethodSignature")
@Inject(
method = "render",
Expand All @@ -26,5 +49,15 @@ public class GuiMixin {
locals = LocalCapture.CAPTURE_FAILHARD)
public void render(GuiGraphics guiGraphics, float f, CallbackInfo ci, Window window, Scoreboard scoreboard, int o, int q) {
DialogContainer.INSTANCE.render(guiGraphics, o, q, 0);

int y = 5;

// Debug - draw focus path on screen
final var screen = Minecraft.getInstance().screen;
if (screen != null) {
y = drawContainerFocus(screen.getCurrentFocusPath(), guiGraphics, y);
}

drawContainerFocus(DialogContainer.INSTANCE.getCurrentFocusPath(), guiGraphics, y + getFont().lineHeight);
}
}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
allprojects {
group = "com.noxcrew.sheeplib"
version = "1.1.0"
version = "1.1.1-SNAPSHOT"
}