This commit is contained in:
Nassim Jahnke 2024-09-18 16:01:35 +02:00
parent 2a2afa3821
commit db20bc0ae4
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
13 changed files with 46 additions and 8 deletions

View File

@ -86,7 +86,7 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
public static final ProtocolVersion v1_20_3 = register(765, "1.20.3-1.20.4", new SubVersionRange("1.20", 3, 4)); public static final ProtocolVersion v1_20_3 = register(765, "1.20.3-1.20.4", new SubVersionRange("1.20", 3, 4));
public static final ProtocolVersion v1_20_5 = register(766, "1.20.5-1.20.6", new SubVersionRange("1.20", 5, 6)); public static final ProtocolVersion v1_20_5 = register(766, "1.20.5-1.20.6", new SubVersionRange("1.20", 5, 6));
public static final ProtocolVersion v1_21 = register(767, "1.21-1.21.1", new SubVersionRange("1.21", 0, 1)); public static final ProtocolVersion v1_21 = register(767, "1.21-1.21.1", new SubVersionRange("1.21", 0, 1));
public static final ProtocolVersion v1_21_2 = register(768, 209, "1.21.2"); public static final ProtocolVersion v1_21_2 = register(768, 210, "1.21.2");
public static final ProtocolVersion unknown = new ProtocolVersion(VersionType.SPECIAL, -1, -1, "UNKNOWN", null); public static final ProtocolVersion unknown = new ProtocolVersion(VersionType.SPECIAL, -1, -1, "UNKNOWN", null);
public static ProtocolVersion register(int version, String name) { public static ProtocolVersion register(int version, String name) {

View File

@ -23,11 +23,14 @@ import com.viaversion.viaversion.protocols.base.packet.BaseClientboundPacket;
public enum ClientboundLoginPackets implements BaseClientboundPacket { public enum ClientboundLoginPackets implements BaseClientboundPacket {
LOGIN_DISCONNECT, // 0x00 LOGIN_DISCONNECT, // 0x00
HELLO, // 0x01 HELLO, // 0x01
GAME_PROFILE, // 0x02 LOGIN_FINISHED, // 0x02
LOGIN_COMPRESSION, // 0x03 LOGIN_COMPRESSION, // 0x03
CUSTOM_QUERY, // 0x04 CUSTOM_QUERY, // 0x04
COOKIE_REQUEST; // 0x05 COOKIE_REQUEST; // 0x05
@Deprecated(forRemoval = true)
public static final ClientboundLoginPackets GAME_PROFILE = LOGIN_FINISHED;
@Override @Override
public final int getId() { public final int getId() {
return ordinal(); return ordinal();

View File

@ -128,7 +128,7 @@ public class ClientboundBaseProtocol1_7 extends AbstractProtocol<BaseClientbound
}); });
// Track player name/uuid and setup connection + track state // Track player name/uuid and setup connection + track state
registerClientbound(ClientboundLoginPackets.GAME_PROFILE, wrapper -> { registerClientbound(ClientboundLoginPackets.LOGIN_FINISHED, wrapper -> {
final ProtocolInfo info = wrapper.user().getProtocolInfo(); final ProtocolInfo info = wrapper.user().getProtocolInfo();
if (info.serverProtocolVersion().olderThan(ProtocolVersion.v1_16)) { if (info.serverProtocolVersion().olderThan(ProtocolVersion.v1_16)) {

View File

@ -81,7 +81,7 @@ public class Protocol1_15_2To1_16 extends AbstractProtocol<ClientboundPackets1_1
new StatisticsRewriter<>(this).register(ClientboundPackets1_15.AWARD_STATS); new StatisticsRewriter<>(this).register(ClientboundPackets1_15.AWARD_STATS);
// Login Success // Login Success
registerClientbound(State.LOGIN, ClientboundLoginPackets.GAME_PROFILE, wrapper -> { registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_FINISHED, wrapper -> {
// Transform string to a uuid // Transform string to a uuid
UUID uuid = UUID.fromString(wrapper.read(Types.STRING)); UUID uuid = UUID.fromString(wrapper.read(Types.STRING));
wrapper.write(Types.UUID, uuid); wrapper.write(Types.UUID, uuid);

View File

@ -232,7 +232,7 @@ public final class Protocol1_18_2To1_19 extends AbstractProtocol<ClientboundPack
cancelServerbound(ServerboundPackets1_19.CHAT_PREVIEW); cancelServerbound(ServerboundPackets1_19.CHAT_PREVIEW);
// Login changes // Login changes
registerClientbound(State.LOGIN, ClientboundLoginPackets.GAME_PROFILE, new PacketHandlers() { registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_FINISHED, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Types.UUID); // UUID map(Types.UUID); // UUID

View File

@ -211,7 +211,7 @@ public final class Protocol1_20_3To1_20_5 extends AbstractProtocol<ClientboundPa
new CommandRewriter1_19_4<>(this).registerDeclareCommands1_19(ClientboundPackets1_20_3.COMMANDS); new CommandRewriter1_19_4<>(this).registerDeclareCommands1_19(ClientboundPackets1_20_3.COMMANDS);
registerClientbound(State.LOGIN, ClientboundLoginPackets.GAME_PROFILE, wrapper -> { registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_FINISHED, wrapper -> {
wrapper.passthrough(Types.UUID); // UUID wrapper.passthrough(Types.UUID); // UUID
wrapper.passthrough(Types.STRING); // Name wrapper.passthrough(Types.STRING); // Name

View File

@ -144,7 +144,7 @@ public final class Protocol1_20To1_20_2 extends AbstractProtocol<ClientboundPack
// We need to wait for it send the login ack before actually sending the play login, // We need to wait for it send the login ack before actually sending the play login,
// hence packets are added to a queue. With the data from the login packet, we sent what is needed // hence packets are added to a queue. With the data from the login packet, we sent what is needed
// during the configuration phase before finally transitioning to the play state with the client as well. // during the configuration phase before finally transitioning to the play state with the client as well.
registerClientbound(State.LOGIN, ClientboundLoginPackets.GAME_PROFILE, wrapper -> { registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_FINISHED, wrapper -> {
wrapper.user().get(ConfigurationState.class).setBridgePhase(BridgePhase.PROFILE_SENT); wrapper.user().get(ConfigurationState.class).setBridgePhase(BridgePhase.PROFILE_SENT);
wrapper.user().getProtocolInfo().setServerState(State.PLAY); wrapper.user().getProtocolInfo().setServerState(State.PLAY);
}); });

View File

@ -24,6 +24,7 @@ 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.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State;
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;
import com.viaversion.viaversion.api.rewriter.ComponentRewriter; import com.viaversion.viaversion.api.rewriter.ComponentRewriter;
@ -31,6 +32,7 @@ import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.ParticleType; import com.viaversion.viaversion.api.type.types.misc.ParticleType;
import com.viaversion.viaversion.api.type.types.version.Types1_21_2; import com.viaversion.viaversion.api.type.types.version.Types1_21_2;
import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundConfigurationPackets1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundConfigurationPackets1_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.ServerboundPacket1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5;
@ -94,6 +96,20 @@ public final class Protocol1_21To1_21_2 extends AbstractProtocol<ClientboundPack
cancelServerbound(ServerboundPackets1_21_2.BUNDLE_ITEM_SELECTED); cancelServerbound(ServerboundPackets1_21_2.BUNDLE_ITEM_SELECTED);
cancelServerbound(ServerboundPackets1_21_2.CLIENT_TICK_END); cancelServerbound(ServerboundPackets1_21_2.CLIENT_TICK_END);
registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_FINISHED, wrapper -> {
wrapper.passthrough(Types.UUID); // UUID
wrapper.passthrough(Types.STRING); // Name
final int properties = wrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < properties; i++) {
wrapper.passthrough(Types.STRING); // Name
wrapper.passthrough(Types.STRING); // Value
wrapper.passthrough(Types.OPTIONAL_STRING); // Signature
}
wrapper.read(Types.BOOLEAN); // Strict error handling
});
} }
private void clientInformation(final PacketWrapper wrapper) { private void clientInformation(final PacketWrapper wrapper) {

View File

@ -228,7 +228,7 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter<
@Override @Override
public void handleRecipeType(final PacketWrapper wrapper, final String type) { public void handleRecipeType(final PacketWrapper wrapper, final String type) {
if (type.equals("crafting_special_suspiciousstew")) { if (type.equals("crafting_special_suspiciousstew") || type.equals("crafting_special_shulkerboxcoloring")) {
wrapper.read(Types.VAR_INT); // Crafting book category wrapper.read(Types.VAR_INT); // Crafting book category
} else { } else {
super.handleRecipeType(wrapper, type); super.handleRecipeType(wrapper, type);

View File

@ -54,6 +54,9 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
recipeHandlers.put("smithing_transform", this::handleSmithingTransform); recipeHandlers.put("smithing_transform", this::handleSmithingTransform);
recipeHandlers.put("smithing_trim", this::handleSmithingTrim); recipeHandlers.put("smithing_trim", this::handleSmithingTrim);
recipeHandlers.put("crafting_decorated_pot", this::handleSimpleRecipe); recipeHandlers.put("crafting_decorated_pot", this::handleSimpleRecipe);
// Added in 1.21.2
recipeHandlers.put("crafting_transmute", this::handleTransmute);
} }
public void handleRecipeType(PacketWrapper wrapper, String type) { public void handleRecipeType(PacketWrapper wrapper, String type) {
@ -160,6 +163,22 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
handleIngredient(wrapper); // Additions handleIngredient(wrapper); // Additions
} }
private void handleTransmute(final PacketWrapper wrapper) {
wrapper.passthrough(Types.STRING); // Group
wrapper.passthrough(Types.VAR_INT); // Crafting book category
handleIngredient(wrapper); // Input
handleIngredient(wrapper); // Material
final int resultItemId = wrapper.read(Types.VAR_INT);
wrapper.write(Types.VAR_INT, rewrite(resultItemId));
}
protected int rewrite(final int itemId) {
if (protocol.getMappingData() != null && protocol.getItemRewriter() != null) {
return protocol.getMappingData().getNewItemId(itemId);
}
return itemId;
}
protected @Nullable Item rewrite(UserConnection connection, @Nullable Item item) { protected @Nullable Item rewrite(UserConnection connection, @Nullable Item item) {
if (protocol.getItemRewriter() != null) { if (protocol.getItemRewriter() != null) {
return protocol.getItemRewriter().handleItemToClient(connection, item); return protocol.getItemRewriter().handleItemToClient(connection, item);