Skip to content

Commit

Permalink
Transform setKeyPair method instead of copying contents
Browse files Browse the repository at this point in the history
  • Loading branch information
Aizistral committed Oct 29, 2024
1 parent 85c2993 commit ce49d40
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
4 changes: 3 additions & 1 deletion forge/src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ public net.minecraft.client.gui.components.Tooltip <init>(Lnet/minecraft/network
#public-f net.minecraft.client.gui.components.CycleButton m_257795_()V #updateTooltip

public-f net.minecraft.client.gui.components.AbstractWidget m_88315_(Lnet/minecraft/client/gui/GuiGraphics;IIF)V #render
public net.minecraft.client.gui.components.WidgetTooltipHolder m_323619_(Lnet/minecraft/client/gui/navigation/ScreenRectangle;ZZ)Lnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner; #createTooltipPositioner
public net.minecraft.client.gui.components.WidgetTooltipHolder m_323619_(Lnet/minecraft/client/gui/navigation/ScreenRectangle;ZZ)Lnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner; #createTooltipPositioner

public net.minecraft.client.multiplayer.ClientPacketListener m_260951_(Lnet/minecraft/world/entity/player/ProfileKeyPair;)V #setKeyPair
4 changes: 3 additions & 1 deletion neoforge/src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ public net.minecraft.client.gui.components.Tooltip <init>(Lnet/minecraft/network
#public-f net.minecraft.client.gui.components.CycleButton updateTooltip()V

public-f net.minecraft.client.gui.components.AbstractWidget render(Lnet/minecraft/client/gui/GuiGraphics;IIF)V
public net.minecraft.client.gui.components.WidgetTooltipHolder createTooltipPositioner(Lnet/minecraft/client/gui/navigation/ScreenRectangle;ZZ)Lnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner;
public net.minecraft.client.gui.components.WidgetTooltipHolder createTooltipPositioner(Lnet/minecraft/client/gui/navigation/ScreenRectangle;ZZ)Lnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner;

public net.minecraft.client.multiplayer.ClientPacketListener setKeyPair(Lnet/minecraft/world/entity/player/ProfileKeyPair;)V
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,19 @@ public static boolean allowChatSigning() {

public static CompletableFuture<Void> setAllowChatSigning(boolean allow) {
if (ALLOW_CHAT_SIGNING.compareAndSet(!allow, allow)) {
if (Minecraft.getInstance().player != null) {
var connection = Minecraft.getInstance().player.connection;
Minecraft mc = Minecraft.getInstance();

if (mc.player != null) {
var connection = mc.player.connection;

if (allow && connection.chatSession == null)
return Minecraft.getInstance().getProfileKeyPairManager().prepareKeyPair()
return mc.getProfileKeyPairManager().prepareKeyPair()
.thenAcceptAsync(optional -> optional.ifPresent(profileKeyPair -> {
Minecraft minecraft = Minecraft.getInstance();
if (minecraft.isLocalPlayer(minecraft.getGameProfile().getId())) {
if (connection.chatSession == null || !connection.chatSession.keyPair().equals(profileKeyPair)) {
connection.chatSession = LocalChatSession.create(profileKeyPair);
connection.signedMessageEncoder = connection.chatSession.createMessageEncoder(minecraft.getGameProfile().getId());
connection.send(new ServerboundChatSessionUpdatePacket(connection.chatSession.asRemote().asData()));
}
}
connection.setKeyPair(profileKeyPair);

SIGNING_ACTIONS.forEach(Runnable::run);
SIGNING_ACTIONS.clear();
}), Minecraft.getInstance());
}), mc);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.aizistral.nochatreports.common.mixins.client;

import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.TitleScreen;
import net.minecraft.network.chat.CommonComponents;
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;

import com.aizistral.nochatreports.common.gui.RealmsWarningScreen;
import com.mojang.realmsclient.RealmsMainScreen;

@Mixin(TitleScreen.class)
public class MixinTitleScreen extends Screen {
Expand All @@ -13,13 +20,12 @@ protected MixinTitleScreen() {
throw new IllegalStateException("Can't touch this");
}

// TODO: Fix this
// @Inject(method = { "realmsButtonClicked", "method_55814", "lambda$createNormalMenuOptions$9" }, at = @At("HEAD"), cancellable = true)
// private void onRealmsButtonClicked(Button button, CallbackInfo info) {
// if (RealmsWarningScreen.shouldShow()) {
// this.minecraft.setScreen(new RealmsWarningScreen(new TitleScreen(), new RealmsMainScreen(this)));
// info.cancel();
// }
// }
@Inject(method = { "realmsButtonClicked", "method_55814", "lambda$createNormalMenuOptions$10" }, at = @At("HEAD"), cancellable = true)
private void onRealmsButtonClicked(Button button, CallbackInfo info) {
if (RealmsWarningScreen.shouldShow()) {
this.minecraft.setScreen(new RealmsWarningScreen(new TitleScreen(), new RealmsMainScreen(this)));
info.cancel();
}
}

}
4 changes: 3 additions & 1 deletion src/main/resources/nochatreports.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ accessible field net/minecraft/client/gui/components/AbstractWidget tooltip Lnet
mutable field net/minecraft/client/gui/components/AbstractWidget tooltip Lnet/minecraft/client/gui/components/WidgetTooltipHolder;

accessible method net/minecraft/client/gui/components/WidgetTooltipHolder createTooltipPositioner (Lnet/minecraft/client/gui/navigation/ScreenRectangle;ZZ)Lnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner;
extendable method net/minecraft/client/gui/components/WidgetTooltipHolder createTooltipPositioner (Lnet/minecraft/client/gui/navigation/ScreenRectangle;ZZ)Lnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner;
extendable method net/minecraft/client/gui/components/WidgetTooltipHolder createTooltipPositioner (Lnet/minecraft/client/gui/navigation/ScreenRectangle;ZZ)Lnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner;

accessible method net/minecraft/client/multiplayer/ClientPacketListener setKeyPair (Lnet/minecraft/world/entity/player/ProfileKeyPair;)V

0 comments on commit ce49d40

Please sign in to comment.