mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-09-27 04:22:36 +02:00
Add networking fixes to 1.20.3->.5
This commit is contained in:
parent
d69a3a9bd2
commit
f471068696
@ -51,6 +51,7 @@ import org.spongepowered.asm.mixin.Mutable;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
@ -77,10 +78,34 @@ public abstract class MixinClientPlayNetworkHandler extends ClientCommonNetworkH
|
||||
@Shadow
|
||||
protected abstract boolean isSecureChatEnforced();
|
||||
|
||||
@Shadow public abstract void sendChatCommand(String command);
|
||||
|
||||
protected MixinClientPlayNetworkHandler(MinecraftClient client, ClientConnection connection, ClientConnectionState connectionState) {
|
||||
super(client, connection, connectionState);
|
||||
}
|
||||
|
||||
@Redirect(method = "sendChatCommand", at = @At(value = "INVOKE", target = "Ljava/util/List;isEmpty()Z"))
|
||||
private boolean alwaysSignCommands(List<?> instance) {
|
||||
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_20_3)) {
|
||||
return false;
|
||||
} else {
|
||||
return instance.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "sendCommand", at = @At("HEAD"), cancellable = true)
|
||||
public void alwaysSendSignedCommand(String command, CallbackInfoReturnable<Boolean> cir) {
|
||||
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_20_3)) {
|
||||
sendChatCommand(command);
|
||||
cir.setReturnValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@WrapWithCondition(method = "onEnterReconfiguration", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendAcknowledgment()V"))
|
||||
private boolean dontSendChatAck(ClientPlayNetworkHandler instance) {
|
||||
return ProtocolTranslator.getTargetVersion().newerThanOrEqualTo(ProtocolVersion.v1_20_5);
|
||||
}
|
||||
|
||||
@WrapWithCondition(method = "onPlayerRespawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;startWorldLoading(Lnet/minecraft/client/network/ClientPlayerEntity;Lnet/minecraft/client/world/ClientWorld;Lnet/minecraft/client/gui/screen/DownloadingTerrainScreen$WorldEntryReason;)V"))
|
||||
private boolean checkDimensionChange(ClientPlayNetworkHandler instance, ClientPlayerEntity player, ClientWorld world, DownloadingTerrainScreen.WorldEntryReason worldEntryReason, @Local(ordinal = 0) RegistryKey<World> registryKey) {
|
||||
return ProtocolTranslator.getTargetVersion().newerThanOrEqualTo(ProtocolVersion.v1_20_3) || registryKey != this.client.player.getWorld().getRegistryKey();
|
||||
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
||||
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> and RK_01/RaphiMC
|
||||
* Copyright (C) 2023-2024 contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.florianmichael.viafabricplus.injection.mixin.fixes.viaversion;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundPacket1_20_3;
|
||||
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundPackets1_20_3;
|
||||
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ServerboundPacket1_20_3;
|
||||
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ServerboundPackets1_20_3;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.Protocol1_20_3To1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPacket1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPackets1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
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(value = Protocol1_20_3To1_20_5.class, remap = false)
|
||||
public abstract class MixinProtocol1_20_3To1_20_5 extends AbstractProtocol<ClientboundPacket1_20_3, ClientboundPacket1_20_5, ServerboundPacket1_20_3, ServerboundPacket1_20_5> {
|
||||
|
||||
@Inject(method = "registerPackets", at = @At("RETURN"))
|
||||
public void removeCommandHandlers(CallbackInfo ci) {
|
||||
// Don't fake acknowledgements for chat messages.
|
||||
registerClientbound(ClientboundPackets1_20_3.PLAYER_CHAT, ClientboundPackets1_20_5.PLAYER_CHAT, wrapper -> {}, true);
|
||||
registerServerbound(ServerboundPackets1_20_5.CHAT, ServerboundPackets1_20_3.CHAT, wrapper -> {}, true);
|
||||
|
||||
// Directly map types, no changes are needed.
|
||||
registerServerbound(ServerboundPackets1_20_5.CHAT_COMMAND_SIGNED, ServerboundPackets1_20_3.CHAT_COMMAND, wrapper -> {}, true);
|
||||
// If the client for whatever reason sends an unsigned command, map to signed by calling game code:
|
||||
registerServerbound(ServerboundPackets1_20_5.CHAT_COMMAND, wrapper -> {
|
||||
final String command = wrapper.read(Types.STRING);
|
||||
wrapper.cancel();
|
||||
MinecraftClient.getInstance().getNetworkHandler().sendChatCommand(command); // TODO sync to correct thread?
|
||||
});
|
||||
|
||||
// Don't cancel any packets we receive.
|
||||
registerServerbound(ServerboundPackets1_20_5.CHAT_ACK, ServerboundPackets1_20_3.CHAT_ACK, wrapper -> {}, true);
|
||||
registerServerbound(ServerboundPackets1_20_5.CHAT_SESSION_UPDATE, ServerboundPackets1_20_3.CHAT_SESSION_UPDATE, wrapper -> {}, true);
|
||||
}
|
||||
|
||||
}
|
@ -12,6 +12,7 @@
|
||||
"base.connect.MixinConnectScreen_1",
|
||||
"base.integration.MixinAddServerScreen",
|
||||
"base.integration.MixinChunkTracker",
|
||||
"base.integration.MixinClientConnection",
|
||||
"base.integration.MixinConnectScreen_1",
|
||||
"base.integration.MixinDebugHud",
|
||||
"base.integration.MixinDirectConnectScreen",
|
||||
@ -162,8 +163,8 @@
|
||||
"fixes.minecraft.screen.screenhandler.MixinScreenHandler",
|
||||
"fixes.vialegacy.MixinClassicProtocolExtension",
|
||||
"fixes.vialegacy.MixinClientboundPacketsc0_30cpe",
|
||||
"fixes.vialegacy.MixinProtocolr1_7_6_10Tor1_8",
|
||||
"fixes.vialegacy.MixinProtocolc0_30cpeToc0_28_30",
|
||||
"fixes.vialegacy.MixinProtocolr1_7_6_10Tor1_8",
|
||||
"fixes.viaversion.MixinBlockItemPacketRewriter1_20_5",
|
||||
"fixes.viaversion.MixinCommandBlockProvider",
|
||||
"fixes.viaversion.MixinCommonBoss",
|
||||
@ -195,7 +196,7 @@
|
||||
"viabedrock.MixinJoinPackets",
|
||||
"vialegacy.MixinExtensionProtocolMetadataStorage",
|
||||
"vialegacy.MixinViaLegacyConfig",
|
||||
"base.integration.MixinClientConnection"
|
||||
"fixes.viaversion.MixinProtocol1_20_3To1_20_5"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
Loading…
Reference in New Issue
Block a user