|
1 | 1 | package com.aizistral.nochatreports.common.mixins.client; |
2 | 2 |
|
3 | | -import java.lang.reflect.Field; |
| 3 | +import java.net.InetSocketAddress; |
4 | 4 |
|
| 5 | +import net.minecraft.client.multiplayer.ServerStatusPinger; |
| 6 | +import net.minecraft.client.multiplayer.resolver.ServerAddress; |
| 7 | +import net.minecraft.network.Connection; |
5 | 8 | import org.spongepowered.asm.mixin.Mixin; |
| 9 | +import org.spongepowered.asm.mixin.Unique; |
6 | 10 | import org.spongepowered.asm.mixin.injection.At; |
7 | 11 | import org.spongepowered.asm.mixin.injection.Inject; |
8 | 12 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
|
12 | 16 | import com.aizistral.nochatreports.common.core.ServerDataExtension; |
13 | 17 | import com.aizistral.nochatreports.common.platform.extensions.ServerPingerExtension; |
14 | 18 |
|
15 | | -import net.minecraft.client.Minecraft; |
16 | 19 | import net.minecraft.client.multiplayer.ServerData; |
17 | 20 | import net.minecraft.network.protocol.status.ClientboundStatusResponsePacket; |
18 | 21 | import net.minecraft.network.protocol.status.ServerStatus; |
19 | 22 |
|
| 23 | + |
| 24 | +/** |
| 25 | + * This one ensures "preventsChatReports" property is transferred from {@link ServerStatus} to |
| 26 | + * {@link ServerData} when handling status response. |
| 27 | + * @author fxmorin (original implementation) |
| 28 | + * @author Aizistral (current version) |
| 29 | + * @author pietro-lopes (fixed https://github.com/Aizistral-Studios/No-Chat-Reports/issues/481) |
| 30 | + */ |
| 31 | + |
20 | 32 | @Mixin(targets = "net/minecraft/client/multiplayer/ServerStatusPinger$1") |
21 | 33 | public abstract class MixinServerStatusPinger$1 implements ServerPingerExtension { |
22 | 34 |
|
23 | | - /** |
24 | | - * @reason Ensure "preventsChatReports" property is transferred from {@link ServerStatus} to |
25 | | - * {@link ServerData} when handling status response. |
26 | | - * @author fxmorin (original implementation) |
27 | | - * @author Aizistral (current version) |
28 | | - */ |
| 35 | + @Unique |
| 36 | + private ServerDataExtension nochatreports$serverData; |
| 37 | + |
| 38 | + @Inject(method = "<init>", at = @At("RETURN")) |
| 39 | + private void captureServerData(ServerStatusPinger serverStatusPinger, Connection connection, ServerData serverData, Runnable runnable, Runnable runnable2, InetSocketAddress inetSocketAddress, ServerAddress serverAddress, CallbackInfo ci){ |
| 40 | + this.nochatreports$serverData = (ServerDataExtension) serverData; |
| 41 | + } |
29 | 42 |
|
30 | 43 | @Inject(method = "handleStatusResponse(Lnet/minecraft/network/protocol/status/ClientboundStatusResponsePacket;)V", |
31 | 44 | at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/status/ServerStatus;" |
32 | | - + "description()Lnet/minecraft/network/chat/Component;", |
33 | | - ordinal = 0, shift = At.Shift.BEFORE)) |
| 45 | + + "description()Lnet/minecraft/network/chat/Component;")) |
34 | 46 | private void getNoChatReports(ClientboundStatusResponsePacket packet, CallbackInfo info) { |
35 | 47 | boolean preventsReports = ((ServerDataExtension) (Object) packet.status()).preventsChatReports(); |
36 | | - ((ServerDataExtension) this.getServerData()).setPreventsChatReports(preventsReports); |
| 48 | + |
| 49 | + if (this.nochatreports$serverData == null) { |
| 50 | + NCRCore.LOGGER.error("Failed to capture ServerData instance in MixinServerStatusPinger$1!"); |
| 51 | + NCRCore.LOGGER.catching(new IllegalStateException()); |
| 52 | + return; |
| 53 | + } |
| 54 | + |
| 55 | + this.nochatreports$serverData.setPreventsChatReports(preventsReports); |
37 | 56 |
|
38 | 57 | if (NCRConfig.getCommon().enableDebugLog()) { |
39 | 58 | NCRCore.LOGGER.info("Received status response packet from server, preventsChatReports: {}", |
|
0 commit comments