package ganarchy.friendcode.mixin; import ganarchy.friendcode.client.FriendCodeScreen; import ganarchy.friendcode.client.FriendConnectScreen; import it.unimi.dsi.fastutil.booleans.BooleanConsumer; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.screen.DirectConnectScreen; import net.minecraft.client.gui.screen.OpenToLanScreen; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.network.ServerInfo; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(DirectConnectScreen.class) public abstract class DirectConnectScreenMixin extends Screen { protected DirectConnectScreenMixin(Text title) { super(title); } @Shadow private Screen parent; @Shadow private BooleanConsumer callback; @Shadow private ServerInfo serverEntry; @Inject(at = @At("HEAD"), method = "init()V") private void init(CallbackInfo info) { // title, meet button this.addDrawableChild(new ButtonWidget( this.width / 2 - 100, 20, 200, 20, this.title, button -> this.client.setScreen(new FriendConnectScreen(this.parent, this.callback, this.serverEntry)) )); } @Redirect( method = "render(Lnet/minecraft/client/util/math/MatrixStack;IIF)V", at = @At( value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/DirectConnectScreen;drawCenteredText(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/Text;III)V", ordinal = 0 ) ) private void removeTitle( MatrixStack matrices, TextRenderer renderer, Text text, int centerX, int y, int color ) { // literally does nothing } }