Skip to content

Commit 5441c10

Browse files
committed
Add Titles Conversion & Cleanup
1 parent d633b9c commit 5441c10

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/main/java/btw/lowercase/viasnapshot/protocol/v15w31ato1_8/rewriter/PacketRewriter15w31a.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
99
import com.viaversion.viaversion.api.type.Types;
1010
import com.viaversion.viaversion.api.type.types.version.Types1_8;
11-
import com.viaversion.viaversion.libs.gson.Gson;
12-
import com.viaversion.viaversion.libs.gson.GsonBuilder;
1311
import com.viaversion.viaversion.protocols.v1_8to1_9.Protocol1_8To1_9;
1412
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_8;
1513
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ServerboundPackets1_8;
@@ -19,8 +17,6 @@
1917

2018
// https://wiki.vg/index.php?title=Pre-release_protocol&direction=prev&oldid=6740
2119
public class PacketRewriter15w31a {
22-
private static final Gson gson = new GsonBuilder().setLenient().create();
23-
2420
public static void register(final Protocol15w31a_To1_8 protocol) {
2521
// NOTE/TODO: Entity action no longer sends 6 for open inventory
2622
// TODO: client status contains open inventory now, needs to send entity action to 1.8 server
@@ -115,6 +111,9 @@ protected void register() {
115111
}
116112
});
117113

114+
// TODO: Remap entity data
115+
protocol.cancelClientbound(ClientboundPackets1_8.SET_ENTITY_DATA);
116+
118117
protocol.registerClientbound(ClientboundPackets1_8.OPEN_SCREEN, new PacketHandlers() {
119118
@Override
120119
protected void register() {
@@ -138,15 +137,28 @@ protected void register() {
138137

139138
protocol.registerClientbound(ClientboundPackets1_8.DISCONNECT, new PacketHandlers() {
140139
public void register() {
141-
map(Types.STRING, Protocol1_8To1_9.STRING_TO_JSON);
140+
map(Types.STRING, Protocol1_8To1_9.STRING_TO_JSON); // Kick Message
141+
}
142+
});
143+
144+
// TODO: Issues in 1.21?
145+
protocol.registerClientbound(ClientboundPackets1_8.SET_TITLES, new PacketHandlers() {
146+
public void register() {
147+
map(Types.VAR_INT); // Action
148+
handler((wrapper) -> {
149+
final int action = wrapper.get(Types.VAR_INT, 0);
150+
if (action == 0 || action == 1) {
151+
Protocol1_8To1_9.STRING_TO_JSON.write(wrapper, wrapper.read(Types.STRING));
152+
}
153+
});
142154
}
143155
});
144156

145157
// TODO: Issues in 1.21?
146158
protocol.registerClientbound(ClientboundPackets1_8.TAB_LIST, new PacketHandlers() {
147159
public void register() {
148-
map(Types.STRING, Protocol1_8To1_9.STRING_TO_JSON);
149-
map(Types.STRING, Protocol1_8To1_9.STRING_TO_JSON);
160+
map(Types.STRING, Protocol1_8To1_9.STRING_TO_JSON); // Title Text
161+
map(Types.STRING, Protocol1_8To1_9.STRING_TO_JSON); // Footer Text
150162
}
151163
});
152164

@@ -243,14 +255,5 @@ protected void register() {
243255
read(Types.BYTE); // Hand (Ignore for 1.8)
244256
}
245257
});
246-
247-
// Workarounds / Broken stuff
248-
{
249-
// TODO: Figure out why I can't remap the values to a component, I even tried the code from 1.9->1.8 class
250-
protocol.cancelClientbound(ClientboundPackets1_8.SET_TITLES);
251-
252-
// TODO: Remap entity data
253-
protocol.cancelClientbound(ClientboundPackets1_8.SET_ENTITY_DATA);
254-
}
255258
}
256259
}

0 commit comments

Comments
 (0)