3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Handle chat and horse container changes

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-05-29 18:19:48 +02:00
Ursprung 23dd8c55ad
Commit 5d0846abe2
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
3 geänderte Dateien mit 112 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,68 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.HolderType;
import io.netty.buffer.ByteBuf;
public record ChatType(ChatTypeDecoration chatDecoration, ChatTypeDecoration narrationDecoration) {
public static final HolderType<ChatType> TYPE = new HolderType<>() {
@Override
public ChatType readDirect(final ByteBuf buffer) {
final ChatTypeDecoration chatDecoration = ChatTypeDecoration.TYPE.read(buffer);
final ChatTypeDecoration narrationDecoration = ChatTypeDecoration.TYPE.read(buffer);
return new ChatType(chatDecoration, narrationDecoration);
}
@Override
public void writeDirect(final ByteBuf buffer, final ChatType value) {
ChatTypeDecoration.TYPE.write(buffer, value.chatDecoration());
ChatTypeDecoration.TYPE.write(buffer, value.narrationDecoration());
}
};
public record ChatTypeDecoration(String translationKey, int[] parameters, Tag style) {
public static final Type<ChatTypeDecoration> TYPE = new Type<>(ChatTypeDecoration.class) {
@Override
public ChatTypeDecoration read(final ByteBuf buffer) {
final String translationKey = Types.STRING.read(buffer);
final int[] parameters = Types.INT_ARRAY_PRIMITIVE.read(buffer);
final Tag style = Types.TAG.read(buffer);
return new ChatTypeDecoration(translationKey, parameters, style);
}
@Override
public void write(final ByteBuf buffer, final ChatTypeDecoration value) {
Types.STRING.write(buffer, value.translationKey());
Types.INT_ARRAY_PRIMITIVE.write(buffer, value.parameters());
Types.TAG.write(buffer, value.style());
}
};
}
}

Datei anzeigen

@ -18,8 +18,10 @@
package com.viaversion.viaversion.protocols.v1_20_5to1_21; package com.viaversion.viaversion.protocols.v1_20_5to1_21;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Holder;
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey; import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
import com.viaversion.viaversion.api.minecraft.item.data.ChatType;
import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider; import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider; import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider;
@ -74,6 +76,40 @@ public final class Protocol1_20_5To1_21 extends AbstractProtocol<ClientboundPack
new StatisticsRewriter<>(this).register(ClientboundPackets1_20_5.AWARD_STATS); new StatisticsRewriter<>(this).register(ClientboundPackets1_20_5.AWARD_STATS);
registerClientbound(ClientboundPackets1_20_5.DISGUISED_CHAT, wrapper -> {
wrapper.passthrough(Types.TAG); // Message
// Holder time
final int chatType = wrapper.read(Types.VAR_INT);
wrapper.write(ChatType.TYPE, Holder.of(chatType));
});
registerClientbound(ClientboundPackets1_20_5.PLAYER_CHAT, wrapper -> {
wrapper.passthrough(Types.UUID); // Sender
wrapper.passthrough(Types.VAR_INT); // Index
wrapper.passthrough(Types.OPTIONAL_SIGNATURE_BYTES); // Signature
wrapper.passthrough(Types.STRING); // Plain content
wrapper.passthrough(Types.LONG); // Timestamp
wrapper.passthrough(Types.LONG); // Salt
final int lastSeen = wrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < lastSeen; i++) {
final int index = wrapper.passthrough(Types.VAR_INT);
if (index == 0) {
wrapper.passthrough(Types.SIGNATURE_BYTES);
}
}
wrapper.passthrough(Types.OPTIONAL_TAG); // Unsigned content
final int filterMaskType = wrapper.passthrough(Types.VAR_INT);
if (filterMaskType == 2) {
wrapper.passthrough(Types.LONG_ARRAY_PRIMITIVE); // Mask
}
final int chatType = wrapper.read(Types.VAR_INT);
wrapper.write(ChatType.TYPE, Holder.of(chatType));
});
registerClientbound(ClientboundPackets1_20_5.UPDATE_ATTRIBUTES, wrapper -> { registerClientbound(ClientboundPackets1_20_5.UPDATE_ATTRIBUTES, wrapper -> {
wrapper.passthrough(Types.VAR_INT); // Entity ID wrapper.passthrough(Types.VAR_INT); // Entity ID

Datei anzeigen

@ -69,6 +69,14 @@ public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter<Cl
registerLevelParticles1_20_5(ClientboundPackets1_20_5.LEVEL_PARTICLES, Types1_20_5.PARTICLE, Types1_21.PARTICLE); registerLevelParticles1_20_5(ClientboundPackets1_20_5.LEVEL_PARTICLES, Types1_20_5.PARTICLE, Types1_21.PARTICLE);
registerExplosion(ClientboundPackets1_20_5.EXPLODE, Types1_20_5.PARTICLE, Types1_21.PARTICLE); // Rewrites the included sound and particles registerExplosion(ClientboundPackets1_20_5.EXPLODE, Types1_20_5.PARTICLE, Types1_21.PARTICLE); // Rewrites the included sound and particles
protocol.registerClientbound(ClientboundPackets1_20_5.HORSE_SCREEN_OPEN, wrapper -> {
wrapper.passthrough(Types.UNSIGNED_BYTE); // Container id
// Now written as columns
final int size = wrapper.read(Types.VAR_INT);
wrapper.write(Types.VAR_INT, Math.max(1, (size - 1) / 3));
});
protocol.registerClientbound(ClientboundPackets1_20_5.LEVEL_EVENT, wrapper -> { protocol.registerClientbound(ClientboundPackets1_20_5.LEVEL_EVENT, wrapper -> {
final int id = wrapper.passthrough(Types.INT); final int id = wrapper.passthrough(Types.INT);
wrapper.passthrough(Types.BLOCK_POSITION1_14); wrapper.passthrough(Types.BLOCK_POSITION1_14);