Skip to content

Commit 5f123ea

Browse files
authored
fix: Init chat screen on init, not ctor, also fix the render order (#36)
* fix: Add the dialog container to chat screen on init, not ctor * Inject at head, not tail * Always render chat screen on top of dialog container * Finish my sentence
1 parent 2e8f85d commit 5f123ea

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

api/src/main/java/com/noxcrew/sheeplib/mixin/ChatScreenMixin.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ protected ChatScreenMixin(Component component) {
3535
* Adds the dialog container screen as a child of this screen.
3636
*/
3737
@Inject(
38-
method = "<init>",
39-
at = @At("TAIL")
38+
method = "init",
39+
at = @At("HEAD")
4040
)
41-
public void init(String string, boolean bl, CallbackInfo ci) {
42-
this.addWidget(DialogContainer.INSTANCE);
41+
public void init(CallbackInfo ci) {
42+
this.addRenderableWidget(DialogContainer.INSTANCE);
4343
}
4444

4545
/**

api/src/main/java/com/noxcrew/sheeplib/mixin/GuiMixin.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,36 @@
22

33
import com.noxcrew.sheeplib.DialogContainer;
44
import net.minecraft.client.DeltaTracker;
5+
import net.minecraft.client.Minecraft;
56
import net.minecraft.client.gui.Gui;
67
import net.minecraft.client.gui.GuiGraphics;
8+
import net.minecraft.client.gui.screens.ChatScreen;
9+
import org.spongepowered.asm.mixin.Final;
710
import org.spongepowered.asm.mixin.Mixin;
11+
import org.spongepowered.asm.mixin.Shadow;
812
import org.spongepowered.asm.mixin.injection.At;
913
import org.spongepowered.asm.mixin.injection.Inject;
1014
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1115

1216
/**
13-
* Adds the {@link DialogContainer} as a render layer.
17+
* Renders the {@link DialogContainer}.
1418
*/
1519
@Mixin(Gui.class)
1620
public class GuiMixin {
21+
@Shadow
22+
@Final
23+
private Minecraft minecraft;
24+
1725
@Inject(
1826
method = "render",
1927
at = @At(
2028
value = "INVOKE",
2129
target = "Lnet/minecraft/client/gui/Gui;renderTabList(Lnet/minecraft/client/gui/GuiGraphics;Lnet/minecraft/client/DeltaTracker;)V"
2230
))
2331
public void render(GuiGraphics graphics, DeltaTracker deltaTracker, CallbackInfo ci) {
24-
DialogContainer.INSTANCE.render(graphics, deltaTracker);
32+
// Only render when not in a chat screen, otherwise chat is rendered over the top of dialogs.
33+
if (!(this.minecraft.screen instanceof ChatScreen)) {
34+
DialogContainer.INSTANCE.render(graphics, 0, 0, deltaTracker.getGameTimeDeltaTicks());
35+
}
2536
}
2637
}

api/src/main/kotlin/com/noxcrew/sheeplib/DialogContainer.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import kotlin.reflect.jvm.jvmName
2121
/**
2222
* The container for all open dialogs.
2323
*/
24-
public object DialogContainer : ContainerEventHandler, NarratableEntry {
24+
public object DialogContainer : ContainerEventHandler, NarratableEntry, Renderable {
2525

2626
private val minecraft = Minecraft.getInstance()
2727
private val logger = LoggerFactory.getLogger("SheepLib")
@@ -36,13 +36,13 @@ public object DialogContainer : ContainerEventHandler, NarratableEntry {
3636
private var isDragging: Boolean = false
3737

3838
/** Renders all opened dialogs. */
39-
public fun render(guiGraphics: GuiGraphics, deltaTracker: DeltaTracker) {
39+
public override fun render(guiGraphics: GuiGraphics, i: Int, j: Int, f: Float) {
4040
val cursorIsActive = minecraft?.screen is ChatScreen
4141

4242
val childX = if (cursorIsActive) minecraft.mouseHandler.getScaledXPos(minecraft.window) else -1
4343
val childY = if (cursorIsActive) minecraft.mouseHandler.getScaledYPos(minecraft.window) else -1
4444
children.value.forEach {
45-
(it as Renderable).render(guiGraphics, childX.toInt(), childY.toInt(), deltaTracker.gameTimeDeltaTicks)
45+
(it as Renderable).render(guiGraphics, childX.toInt(), childY.toInt(), f)
4646
}
4747
}
4848

0 commit comments

Comments
 (0)