Skip to content

Commit b94e4ed

Browse files
committed
fix: Init chat screen on init, not ctor, also fix the render order (backport of #36)
(cherry picked from commit 5f123ea)
1 parent b36a84c commit b94e4ed

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
@@ -32,11 +32,11 @@ protected ChatScreenMixin(Component component) {
3232
* Adds the dialog container screen as a child of this screen.
3333
*/
3434
@Inject(
35-
method = "<init>",
36-
at = @At("TAIL")
35+
method = "init",
36+
at = @At("HEAD")
3737
)
38-
public void init(String string, CallbackInfo ci) {
39-
this.addWidget(DialogContainer.INSTANCE);
38+
public void init(CallbackInfo ci) {
39+
this.addRenderableWidget(DialogContainer.INSTANCE);
4040
}
4141

4242
/**

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
@@ -20,7 +20,7 @@ import kotlin.reflect.jvm.jvmName
2020
/**
2121
* The container for all open dialogs.
2222
*/
23-
public object DialogContainer : ContainerEventHandler, NarratableEntry {
23+
public object DialogContainer : ContainerEventHandler, NarratableEntry, Renderable {
2424

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

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

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

0 commit comments

Comments
 (0)