Update signed chat command fix in <= 1.20.6

This commit is contained in:
FlorianMichael 2024-07-05 01:09:15 +02:00
parent 969ca32624
commit 4ff29f9e7d
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
2 changed files with 10 additions and 17 deletions

View File

@ -49,7 +49,6 @@ import java.util.concurrent.CompletableFuture;
* - LivingEntity#takeKnockback with 1.0E-5F for loop is new
* - KnowledgeBookItem#use decrementUnlessCreative is new
* - JukeboxBlock#onUse override is new (added state.get(HAS_RECORD) condition)
* - HangingEntity bounding box calculation changes
* - BoatEntity#updateVelocity isSpaceEmpty condition new
* - LivingEntity#remove -> added activeEffects.clear call
* - PlayerEntity#tickMovement getSaturationLevel/setSaturationLevel handling is new

View File

@ -19,18 +19,15 @@
package de.florianmichael.viafabricplus.injection.mixin.fixes.viaversion;
import com.viaversion.viaversion.api.Via;
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;
@ -41,22 +38,19 @@ public abstract class MixinProtocol1_20_3To1_20_5 extends AbstractProtocol<Clien
@Inject(method = "registerPackets", at = @At("RETURN"))
private 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);
// Remove any special handling for chat acknowledgements
registerServerbound(ServerboundPackets1_20_5.CHAT, ServerboundPackets1_20_3.CHAT, null, true);
registerServerbound(ServerboundPackets1_20_5.CHAT_ACK, ServerboundPackets1_20_3.CHAT_ACK, null, true);
registerServerbound(ServerboundPackets1_20_5.CHAT_SESSION_UPDATE, ServerboundPackets1_20_3.CHAT_SESSION_UPDATE, null, 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:
// Map signed command packet to normal one since we modify the game to always send signed commands
registerServerbound(ServerboundPackets1_20_5.CHAT_COMMAND_SIGNED, ServerboundPackets1_20_3.CHAT_COMMAND, null, true);
// Don't allow mods to directly send packets - Use ClientPlayNetworkHandler#sendChatCommand instead
registerServerbound(ServerboundPackets1_20_5.CHAT_COMMAND, ServerboundPackets1_20_3.CHAT_COMMAND, wrapper -> {
final String command = wrapper.read(Types.STRING);
Via.getPlatform().getLogger().severe("Tried to remap >=1.20.5 CHAT_COMMAND packet which is impossible without breaking the content! Find the cause and fix it!");
wrapper.cancel();
MinecraftClient.getInstance().getNetworkHandler().sendChatCommand(command); // TODO sync to correct thread?
}, true);
// 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);
}
}