Skip to content

Commit

Permalink
Handle tags packet
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytv committed Dec 6, 2023
1 parent 8a2c188 commit 255536e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ServerboundPackets1_20_3;
import com.viaversion.viaversion.rewriter.ComponentRewriter.ReadType;
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;
import java.util.BitSet;
import java.util.UUID;

Expand All @@ -64,6 +65,9 @@ public Protocol1_20_2To1_20_3() {
protected void registerPackets() {
super.registerPackets();

final TagRewriter<ClientboundPackets1_20_3> tagRewriter = new TagRewriter<>(this);
tagRewriter.registerGeneric(ClientboundPackets1_20_3.TAGS);

final SoundRewriter<ClientboundPackets1_20_3> soundRewriter = new SoundRewriter<>(this);
soundRewriter.register1_19_3Sound(ClientboundPackets1_20_3.SOUND);
soundRewriter.registerEntitySound(ClientboundPackets1_20_3.ENTITY_SOUND);
Expand Down Expand Up @@ -305,24 +309,15 @@ public void register() {
cancelClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_3.RESOURCE_PACK_POP.getId());
registerServerbound(State.CONFIGURATION, ServerboundConfigurationPackets1_20_2.RESOURCE_PACK, resourcePackStatusHandler());
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_3.RESOURCE_PACK_PUSH.getId(), ServerboundConfigurationPackets1_20_2.RESOURCE_PACK.getId(), resourcePackHandler());
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_3.UPDATE_TAGS.getId(), ClientboundConfigurationPackets1_20_2.UPDATE_TAGS.getId(), tagRewriter.getGenericHandler());
// TODO Auto map via packet types provider
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_3.UPDATE_ENABLED_FEATURES.getId(), ClientboundConfigurationPackets1_20_2.UPDATE_ENABLED_FEATURES.getId());
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_3.UPDATE_TAGS.getId(), ClientboundConfigurationPackets1_20_2.UPDATE_TAGS.getId());
}

private PacketHandler resourcePackStatusHandler() {
return wrapper -> {
final ResourcepackIDStorage storage = wrapper.user().get(ResourcepackIDStorage.class);
wrapper.write(Type.UUID, storage != null ? storage.uuid() : UUID.randomUUID());

final int action = wrapper.read(Type.VAR_INT);
if (action == 4) { // Downloaded
wrapper.cancel();
} else if (action > 4) { // Invalid url, failed reload, and discarded
wrapper.write(Type.VAR_INT, 2); // Failed download
} else {
wrapper.write(Type.VAR_INT, action);
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundConfigurationPackets1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundConfigurationPackets1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.Protocol1_20_3To1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundConfigurationPackets1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ServerboundPackets1_20_3;
import com.viaversion.viaversion.rewriter.ComponentRewriter.ReadType;
Expand All @@ -43,7 +43,7 @@
// Protocol1_20_3To1_20_2 (the ViaVersion protocol class the mappings depend on)
// ClientboundPackets1_20_3
// ServerboundPackets1_20_3
// ClientboundConfigurationPackets1_20_2
// ClientboundConfigurationPackets1_20_3
// ServerboundConfigurationPackets1_20_2
// EntityTypes1_19_4 (UNMAPPED type)
// 1.99, 1.98
Expand Down Expand Up @@ -114,7 +114,7 @@ public TranslatableRewriter<ClientboundPackets1_20_3> getTranslatableRewriter()

@Override
protected ClientboundPacketType clientboundFinishConfigurationPacket() {
return ClientboundConfigurationPackets1_20_2.FINISH_CONFIGURATION;
return ClientboundConfigurationPackets1_20_3.FINISH_CONFIGURATION;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundConfigurationPackets1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundConfigurationPackets1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3;

// Replace if needed
Expand All @@ -43,7 +43,7 @@ public void registerPackets() {
registerMetadataRewriter(ClientboundPackets1_20_3.ENTITY_METADATA, /*Types1_OLD.METADATA_LIST, */Types1_20_3.METADATA_LIST); // Specify old and new metadata list if changed
registerRemoveEntities(ClientboundPackets1_20_3.REMOVE_ENTITIES);

protocol.registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.REGISTRY_DATA, new PacketHandlers() {
protocol.registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_3.REGISTRY_DATA, new PacketHandlers() {
@Override
protected void register() {
map(Type.COMPOUND_TAG); // Registry data
Expand Down

0 comments on commit 255536e

Please sign in to comment.