Skip to content

Commit

Permalink
Add Titles Conversion & Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lowercasebtw committed Oct 16, 2024
1 parent d633b9c commit 5441c10
Showing 1 changed file with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_8;
import com.viaversion.viaversion.libs.gson.Gson;
import com.viaversion.viaversion.libs.gson.GsonBuilder;
import com.viaversion.viaversion.protocols.v1_8to1_9.Protocol1_8To1_9;
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_8;
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ServerboundPackets1_8;
Expand All @@ -19,8 +17,6 @@

// https://wiki.vg/index.php?title=Pre-release_protocol&direction=prev&oldid=6740
public class PacketRewriter15w31a {
private static final Gson gson = new GsonBuilder().setLenient().create();

public static void register(final Protocol15w31a_To1_8 protocol) {
// NOTE/TODO: Entity action no longer sends 6 for open inventory
// TODO: client status contains open inventory now, needs to send entity action to 1.8 server
Expand Down Expand Up @@ -115,6 +111,9 @@ protected void register() {
}
});

// TODO: Remap entity data
protocol.cancelClientbound(ClientboundPackets1_8.SET_ENTITY_DATA);

protocol.registerClientbound(ClientboundPackets1_8.OPEN_SCREEN, new PacketHandlers() {
@Override
protected void register() {
Expand All @@ -138,15 +137,28 @@ protected void register() {

protocol.registerClientbound(ClientboundPackets1_8.DISCONNECT, new PacketHandlers() {
public void register() {
map(Types.STRING, Protocol1_8To1_9.STRING_TO_JSON);
map(Types.STRING, Protocol1_8To1_9.STRING_TO_JSON); // Kick Message
}
});

// TODO: Issues in 1.21?
protocol.registerClientbound(ClientboundPackets1_8.SET_TITLES, new PacketHandlers() {
public void register() {
map(Types.VAR_INT); // Action
handler((wrapper) -> {
final int action = wrapper.get(Types.VAR_INT, 0);
if (action == 0 || action == 1) {
Protocol1_8To1_9.STRING_TO_JSON.write(wrapper, wrapper.read(Types.STRING));
}
});
}
});

// TODO: Issues in 1.21?
protocol.registerClientbound(ClientboundPackets1_8.TAB_LIST, new PacketHandlers() {
public void register() {
map(Types.STRING, Protocol1_8To1_9.STRING_TO_JSON);
map(Types.STRING, Protocol1_8To1_9.STRING_TO_JSON);
map(Types.STRING, Protocol1_8To1_9.STRING_TO_JSON); // Title Text
map(Types.STRING, Protocol1_8To1_9.STRING_TO_JSON); // Footer Text
}
});

Expand Down Expand Up @@ -243,14 +255,5 @@ protected void register() {
read(Types.BYTE); // Hand (Ignore for 1.8)
}
});

// Workarounds / Broken stuff
{
// TODO: Figure out why I can't remap the values to a component, I even tried the code from 1.9->1.8 class
protocol.cancelClientbound(ClientboundPackets1_8.SET_TITLES);

// TODO: Remap entity data
protocol.cancelClientbound(ClientboundPackets1_8.SET_ENTITY_DATA);
}
}
}

0 comments on commit 5441c10

Please sign in to comment.