cancel sending signal if user closes the menu
This commit is contained in:
@ -5,6 +5,7 @@ import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.screen.DisconnectedScreen;
|
||||
import net.minecraft.client.util.Window;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.util.Formatting;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@ -31,12 +32,13 @@ public class MixinDisconnectedScreen
|
||||
@Inject(at = @At("RETURN"), method = "render")
|
||||
private void render(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo info)
|
||||
{
|
||||
if(!disconnectedCausedByWolfSignal) return;
|
||||
Window window = MinecraftClient.getInstance().getWindow();
|
||||
TextRenderer renderer = MinecraftClient.getInstance().textRenderer;
|
||||
String text = getMessage();
|
||||
String text = "sending signal " + signal + "using wolfs";
|
||||
renderer.draw(matrices, text,
|
||||
(window.getScaledWidth() - renderer.getWidth(text)) / 2F, // centered
|
||||
(window.getScaledHeight() - reasonHeight) / 2F - 9 * 4, // 9 * 2 higher than the title which is 9 * 2 higher than the disconnect reason
|
||||
getColor());
|
||||
Formatting.WHITE.getColorValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -45,4 +45,18 @@ public class MixinMinecraftClient
|
||||
}
|
||||
}
|
||||
}
|
||||
@Inject(at = @At("INVOKE"), method = "openScreen")
|
||||
private void openScreen(Screen newScreen, CallbackInfo info) {
|
||||
// old and new screen must not be the same type, actually happens very often for some reason
|
||||
if ((currentScreen == null ? null : currentScreen.getClass()) != (newScreen == null ? null : newScreen.getClass())) {
|
||||
if (currentScreen instanceof DisconnectedScreen && ( // exited disconnect screen using...
|
||||
newScreen instanceof MultiplayerScreen || // ...cancel button on disconnect screen
|
||||
newScreen instanceof TitleScreen || // ...escape key
|
||||
newScreen != null && newScreen.getClass().getSimpleName().equals("AuthScreen")) || // ...AuthMe re-authenticate button
|
||||
(currentScreen instanceof ConnectScreen && !(newScreen instanceof DisconnectedScreen))) // connection successful or cancelled using cancel button on connect screen
|
||||
{
|
||||
ticks = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user