Skip to content

Commit 8669c17

Browse files
committed
Update VV usage
1 parent fe993fc commit 8669c17

File tree

16 files changed

+55
-98
lines changed

16 files changed

+55
-98
lines changed

common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
4040
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
4141
import com.viaversion.viaversion.rewriter.StructuredItemRewriter;
42+
import com.viaversion.viaversion.util.Key;
4243
import java.util.ArrayList;
4344
import java.util.List;
4445
import java.util.function.BiConsumer;
@@ -244,6 +245,20 @@ protected void restoreStringData(final StructuredDataKey<String> key, final Stru
244245
}
245246
}
246247

248+
protected void saveKeyData(final StructuredDataKey<Key> key, final StructuredDataContainer data, final CompoundTag backupTag) {
249+
final Key value = data.get(key);
250+
if (value != null) {
251+
backupTag.putString(key.identifier(), value.original());
252+
}
253+
}
254+
255+
protected void restoreKeyData(final StructuredDataKey<Key> key, final StructuredDataContainer data, final CompoundTag backupTag) {
256+
final String value = backupTag.getString(key.identifier());
257+
if (value != null) {
258+
data.set(key, Key.of(value));
259+
}
260+
}
261+
247262
protected void saveIntData(final StructuredDataKey<Integer> key, final StructuredDataContainer data, final CompoundTag backupTag) {
248263
final Integer variant = data.get(key);
249264
if (variant != null) {

common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ protected void registerPackets() {
106106
@Override
107107
public void init(final UserConnection connection) {
108108
addEntityTracker(connection, new EntityTrackerBase(connection, EntityTypes1_21_4.PLAYER));
109-
addItemHasher(connection, new ItemHasherBase(connection, SerializerVersion.V1_21_5, SerializerVersion.V1_21_5, MAPPINGS));
109+
addItemHasher(connection, new ItemHasherBase(this, connection, SerializerVersion.V1_21_5, SerializerVersion.V1_21_5));
110110
}
111111

112112
@Override

common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/rewriter/PlayerPacketRewriter1_13.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,7 @@ public void register() {
150150
if (action == 0) { // Add
151151
String name = packetWrapper.passthrough(Types.STRING);
152152
storage.usernames().put(uuid, name);
153-
int nProperties = packetWrapper.passthrough(Types.VAR_INT);
154-
for (int j = 0; j < nProperties; j++) {
155-
packetWrapper.passthrough(Types.STRING);
156-
packetWrapper.passthrough(Types.STRING);
157-
packetWrapper.passthrough(Types.OPTIONAL_STRING);
158-
}
153+
packetWrapper.passthrough(Types.PROFILE_PROPERTY_ARRAY);
159154
packetWrapper.passthrough(Types.VAR_INT);
160155
packetWrapper.passthrough(Types.VAR_INT);
161156
packetWrapper.passthrough(Types.OPTIONAL_COMPONENT);

common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/rewriter/EntityPacketRewriter1_16.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,7 @@ public void register() {
230230
wrapper.passthrough(Types.UUID);
231231
if (action == 0) { // Add
232232
wrapper.passthrough(Types.STRING);
233-
int properties = wrapper.passthrough(Types.VAR_INT);
234-
for (int j = 0; j < properties; j++) {
235-
wrapper.passthrough(Types.STRING);
236-
wrapper.passthrough(Types.STRING);
237-
wrapper.passthrough(Types.OPTIONAL_STRING);
238-
}
233+
wrapper.passthrough(Types.PROFILE_PROPERTY_ARRAY);
239234
wrapper.passthrough(Types.VAR_INT);
240235
wrapper.passthrough(Types.VAR_INT);
241236
// Display Name

common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_3to1_19_1/rewriter/EntityPacketRewriter1_19_3.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,7 @@ public void register() {
131131
for (int i = 0; i < entries; i++) {
132132
playerInfoPacket.write(Types.UUID, wrapper.read(Types.UUID));
133133
playerInfoPacket.write(Types.STRING, wrapper.read(Types.STRING)); // Player Name
134-
135-
final int properties = wrapper.read(Types.VAR_INT);
136-
playerInfoPacket.write(Types.VAR_INT, properties);
137-
for (int j = 0; j < properties; j++) {
138-
playerInfoPacket.write(Types.STRING, wrapper.read(Types.STRING)); // Name
139-
playerInfoPacket.write(Types.STRING, wrapper.read(Types.STRING)); // Value
140-
playerInfoPacket.write(Types.OPTIONAL_STRING, wrapper.read(Types.OPTIONAL_STRING)); // Signature
141-
}
134+
playerInfoPacket.write(Types.PROFILE_PROPERTY_ARRAY, wrapper.read(Types.PROFILE_PROPERTY_ARRAY));
142135

143136
// Now check for the other parts individually and add dummy values if not present
144137
final ProfileKey profileKey;

common/src/main/java/com/viaversion/viabackwards/protocol/v1_19to1_18_2/Protocol1_19To1_18_2.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,7 @@ public void register() {
296296
public void register() {
297297
map(Types.UUID); // UUID
298298
map(Types.STRING); // Name
299-
handler(wrapper -> {
300-
final int properties = wrapper.read(Types.VAR_INT);
301-
for (int i = 0; i < properties; i++) {
302-
wrapper.read(Types.STRING); // Name
303-
wrapper.read(Types.STRING); // Value
304-
wrapper.read(Types.OPTIONAL_STRING); // Optional signature
305-
}
306-
});
299+
map(Types.PROFILE_PROPERTY_ARRAY);
307300
}
308301
});
309302

common/src/main/java/com/viaversion/viabackwards/protocol/v1_19to1_18_2/rewriter/EntityPacketRewriter1_19.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,7 @@ public void register() {
268268
wrapper.passthrough(Types.UUID); // UUID
269269
if (action == 0) { // Add player
270270
wrapper.passthrough(Types.STRING); // Player Name
271-
272-
final int properties = wrapper.passthrough(Types.VAR_INT);
273-
for (int j = 0; j < properties; j++) {
274-
wrapper.passthrough(Types.STRING); // Name
275-
wrapper.passthrough(Types.STRING); // Value
276-
wrapper.passthrough(Types.OPTIONAL_STRING); // Signature
277-
}
278-
271+
wrapper.passthrough(Types.PROFILE_PROPERTY_ARRAY);
279272
wrapper.passthrough(Types.VAR_INT); // Gamemode
280273
wrapper.passthrough(Types.VAR_INT); // Ping
281274
wrapper.passthrough(Types.OPTIONAL_COMPONENT); // Display name

common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_3to1_20_2/Protocol1_20_3To1_20_2.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,7 @@ public void register() {
291291
wrapper.passthrough(Types.UUID);
292292
if (actions.get(0)) {
293293
wrapper.passthrough(Types.STRING); // Player Name
294-
295-
final int properties = wrapper.passthrough(Types.VAR_INT);
296-
for (int j = 0; j < properties; j++) {
297-
wrapper.passthrough(Types.STRING); // Name
298-
wrapper.passthrough(Types.STRING); // Value
299-
wrapper.passthrough(Types.OPTIONAL_STRING); // Signature
300-
}
294+
wrapper.passthrough(Types.PROFILE_PROPERTY_ARRAY);
301295
}
302296
if (actions.get(1) && wrapper.passthrough(Types.BOOLEAN)) {
303297
wrapper.passthrough(Types.UUID); // Session UUID

common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/Protocol1_20_5To1_20_3.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,7 @@ public void handleArgument(final PacketWrapper wrapper, final String argumentTyp
167167
registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_FINISHED, wrapper -> {
168168
wrapper.passthrough(Types.UUID); // UUID
169169
wrapper.passthrough(Types.STRING); // Name
170-
171-
final int properties = wrapper.passthrough(Types.VAR_INT);
172-
for (int i = 0; i < properties; i++) {
173-
wrapper.passthrough(Types.STRING); // Name
174-
wrapper.passthrough(Types.STRING); // Value
175-
wrapper.passthrough(Types.OPTIONAL_STRING); // Signature
176-
}
177-
170+
wrapper.passthrough(Types.PROFILE_PROPERTY_ARRAY);
178171
wrapper.read(Types.BOOLEAN); // Strict error handling
179172
});
180173

common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,7 @@ protected void registerPackets() {
114114
registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_FINISHED, wrapper -> {
115115
wrapper.passthrough(Types.UUID); // UUID
116116
wrapper.passthrough(Types.STRING); // Name
117-
118-
final int properties = wrapper.passthrough(Types.VAR_INT);
119-
for (int i = 0; i < properties; i++) {
120-
wrapper.passthrough(Types.STRING); // Name
121-
wrapper.passthrough(Types.STRING); // Value
122-
wrapper.passthrough(Types.OPTIONAL_STRING); // Signature
123-
}
124-
117+
wrapper.passthrough(Types.PROFILE_PROPERTY_ARRAY);
125118
wrapper.write(Types.BOOLEAN, true); // Strict error handling. Always enabled for newer clients, so mimic that behavior
126119
});
127120

0 commit comments

Comments
 (0)