Skip to content

Commit ab9d1d2

Browse files
authored
Use TagRewriter in 1.14->1.13.2 (#1251)
1 parent 65b2c30 commit ab9d1d2

1 file changed

Lines changed: 11 additions & 29 deletions

File tree

common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/Protocol1_14To1_13_2.java

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.viaversion.viabackwards.protocol.v1_14to1_13_2.storage.DifficultyStorage;
3131
import com.viaversion.viaversion.api.connection.UserConnection;
3232
import com.viaversion.viaversion.api.minecraft.ClientWorld;
33+
import com.viaversion.viaversion.api.minecraft.RegistryType;
3334
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14;
3435
import com.viaversion.viaversion.api.type.Types;
3536
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
@@ -39,6 +40,7 @@
3940
import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ServerboundPackets1_14;
4041
import com.viaversion.viaversion.rewriter.BlockRewriter;
4142
import com.viaversion.viaversion.rewriter.ParticleRewriter;
43+
import com.viaversion.viaversion.rewriter.TagRewriter;
4244
import com.viaversion.viaversion.rewriter.text.ComponentRewriterBase;
4345

4446
public class Protocol1_14To1_13_2 extends BackwardsProtocol<ClientboundPackets1_14, ClientboundPackets1_13, ServerboundPackets1_14, ServerboundPackets1_13> {
@@ -49,6 +51,7 @@ public class Protocol1_14To1_13_2 extends BackwardsProtocol<ClientboundPackets1_
4951
private final BlockRewriter<ClientboundPackets1_14> blockRewriter = BlockRewriter.legacy(this);
5052
private final ParticleRewriter<ClientboundPackets1_14> particleRewriter = new ParticleRewriter<>(this);
5153
private final JsonNBTComponentRewriter<ClientboundPackets1_14> translatableRewriter = new JsonNBTComponentRewriter<>(this, ComponentRewriterBase.ReadType.JSON);
54+
private final TagRewriter<ClientboundPackets1_14> tagRewriter = new TagRewriter<>(this);
5255

5356
public Protocol1_14To1_13_2() {
5457
super(ClientboundPackets1_14.class, ClientboundPackets1_13.class, ServerboundPackets1_14.class, ServerboundPackets1_13.class);
@@ -66,35 +69,9 @@ protected void registerPackets() {
6669
cancelClientbound(ClientboundPackets1_14.SET_CHUNK_CACHE_RADIUS);
6770

6871
registerClientbound(ClientboundPackets1_14.UPDATE_TAGS, wrapper -> {
69-
int blockTagsSize = wrapper.passthrough(Types.VAR_INT);
70-
for (int i = 0; i < blockTagsSize; i++) {
71-
wrapper.passthrough(Types.STRING);
72-
int[] blockIds = wrapper.passthrough(Types.VAR_INT_ARRAY_PRIMITIVE);
73-
for (int j = 0; j < blockIds.length; j++) {
74-
int id = blockIds[j];
75-
// Ignore new blocktags
76-
int blockId = MAPPINGS.getNewBlockId(id);
77-
blockIds[j] = blockId;
78-
}
79-
}
80-
81-
int itemTagsSize = wrapper.passthrough(Types.VAR_INT);
82-
for (int i = 0; i < itemTagsSize; i++) {
83-
wrapper.passthrough(Types.STRING);
84-
int[] itemIds = wrapper.passthrough(Types.VAR_INT_ARRAY_PRIMITIVE);
85-
for (int j = 0; j < itemIds.length; j++) {
86-
int itemId = itemIds[j];
87-
// Ignore new itemtags
88-
int oldId = MAPPINGS.getItemMappings().getNewId(itemId);
89-
itemIds[j] = oldId;
90-
}
91-
}
92-
93-
int fluidTagsSize = wrapper.passthrough(Types.VAR_INT); // fluid tags
94-
for (int i = 0; i < fluidTagsSize; i++) {
95-
wrapper.passthrough(Types.STRING);
96-
wrapper.passthrough(Types.VAR_INT_ARRAY_PRIMITIVE);
97-
}
72+
tagRewriter.handle(wrapper, RegistryType.BLOCK);
73+
tagRewriter.handle(wrapper, RegistryType.ITEM);
74+
tagRewriter.handle(wrapper, RegistryType.FLUID);
9875

9976
// Eat entity tags
10077
int entityTagsSize = wrapper.read(Types.VAR_INT);
@@ -194,4 +171,9 @@ public ParticleRewriter<ClientboundPackets1_14> getParticleRewriter() {
194171
public JsonNBTComponentRewriter<ClientboundPackets1_14> getComponentRewriter() {
195172
return translatableRewriter;
196173
}
174+
175+
@Override
176+
public TagRewriter<ClientboundPackets1_14> getTagRewriter() {
177+
return tagRewriter;
178+
}
197179
}

0 commit comments

Comments
 (0)