diff options
Diffstat (limited to 'src/main/java/ganarchy/friendcode/mixin')
4 files changed, 168 insertions, 0 deletions
diff --git a/src/main/java/ganarchy/friendcode/mixin/DirectConnectScreenMixin.java b/src/main/java/ganarchy/friendcode/mixin/DirectConnectScreenMixin.java new file mode 100644 index 0000000..6b3a182 --- /dev/null +++ b/src/main/java/ganarchy/friendcode/mixin/DirectConnectScreenMixin.java @@ -0,0 +1,65 @@ +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 + } +} diff --git a/src/main/java/ganarchy/friendcode/mixin/FriendCodeIntegratedServerExt.java b/src/main/java/ganarchy/friendcode/mixin/FriendCodeIntegratedServerExt.java new file mode 100644 index 0000000..49d3b3f --- /dev/null +++ b/src/main/java/ganarchy/friendcode/mixin/FriendCodeIntegratedServerExt.java @@ -0,0 +1,17 @@ +package ganarchy.friendcode.mixin; + +import net.minecraft.client.network.LanServerPinger; +import net.minecraft.server.integrated.IntegratedServer; +import net.minecraft.world.GameMode; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(IntegratedServer.class) +public interface FriendCodeIntegratedServerExt { + @Accessor("forcedGameMode") + void forcedGameMode(GameMode gameMode); + @Accessor("lanPort") + void lanPort(int port); + @Accessor("lanPinger") + void lanPinger(LanServerPinger lanPinger); +} diff --git a/src/main/java/ganarchy/friendcode/mixin/LanPingerMixin.java b/src/main/java/ganarchy/friendcode/mixin/LanPingerMixin.java new file mode 100644 index 0000000..187904d --- /dev/null +++ b/src/main/java/ganarchy/friendcode/mixin/LanPingerMixin.java @@ -0,0 +1,29 @@ +package ganarchy.friendcode.mixin; + +import ganarchy.friendcode.client.LanSendPing; +import net.minecraft.client.network.LanServerPinger; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(LanServerPinger.class) +public class LanPingerMixin implements LanSendPing { + @Inject( + method = "run()V", + remap = false, + at = @At( + remap = false, + value = "INVOKE", + target = "Ljava/net/InetAddress;getByName(Ljava/lang/String;)Ljava/net/InetAddress;" + ) + ) + public void onSendPing(CallbackInfo info) { + this.friendcodeSendPing(); + } + + @Override + public void friendcodeSendPing() { + + } +} diff --git a/src/main/java/ganarchy/friendcode/mixin/OpenToLanScreenMixin.java b/src/main/java/ganarchy/friendcode/mixin/OpenToLanScreenMixin.java new file mode 100644 index 0000000..fd2cccb --- /dev/null +++ b/src/main/java/ganarchy/friendcode/mixin/OpenToLanScreenMixin.java @@ -0,0 +1,57 @@ +package ganarchy.friendcode.mixin; + +import ganarchy.friendcode.client.FriendCodeScreen; +import net.minecraft.client.font.TextRenderer; +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.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(OpenToLanScreen.class) +public abstract class OpenToLanScreenMixin extends Screen { + protected OpenToLanScreenMixin(Text title) { + super(title); + } + + @Shadow + private Screen parent; + + @Inject(at = @At("HEAD"), method = "init()V") + private void init(CallbackInfo info) { + // title, meet button + this.addDrawableChild(new ButtonWidget( + this.width / 2 - 155, + 50, + 310, + 20, + this.title, + button -> this.client.setScreen(new FriendCodeScreen(this.parent)) + )); + } + + @Redirect( + method = "render(Lnet/minecraft/client/util/math/MatrixStack;IIF)V", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/gui/screen/OpenToLanScreen;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 + } +} |