Skip to content

Commit d729d18

Browse files
committed
Add 15w31b client support
1 parent 5441c10 commit d729d18

File tree

9 files changed

+231
-8
lines changed

9 files changed

+231
-8
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
# ViaSnapshot
2+
23
### ⚠️ WARNING: This is experimental and is not safe to use on public servers. Use at your own risk!
3-
**Allows you to join servers from snapshots, using ViaProxy. Currently only supports 15w31a.**
4+
5+
**Allows you to join servers from snapshots, using ViaProxy.**
6+
7+
Supported Versions:
8+
9+
- 15w31a
10+
- 15w31b
411

512
Known Issues:
13+
614
- Item Drops are stone
715
- Entity metadata is missing
816
- Item interaction in newer versions is broken
@@ -11,6 +19,7 @@ Known Issues:
1119
- And more, possibly on purpose as some packets were disabled
1220

1321
## Installation and Usage
22+
1423
1. Download the latest version from [GitHub Actions](https://github.com/ViaVersionAddons/ViaSnapshot/actions).
1524
2. Put the jar file into the plugins folder of ViaProxy
1625
3. Run ViaProxy. You should now be able to connect from a snapshot client to ViaProxy.

src/main/java/btw/lowercase/viasnapshot/SnapshotProtocolVersion.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import com.viaversion.viaversion.protocol.RedirectProtocolVersion;
55

66
public class SnapshotProtocolVersion {
7-
public static final ProtocolVersion v15w31a = registerSnapshot(49, "15w31a (Client Only)", ProtocolVersion.v1_8);
7+
public static final ProtocolVersion v15w31a = registerSnapshot1_8(49, "15w31a (Client Only)");
8+
public static final ProtocolVersion v15w31b = registerSnapshot1_8(50, "15w31b (Client Only)");
89

9-
private static ProtocolVersion registerSnapshot(final int version, final String name, final ProtocolVersion origin) {
10-
final ProtocolVersion protocolVersion = new RedirectProtocolVersion(version, name, origin);
10+
private static ProtocolVersion registerSnapshot1_8(final int version, final String name) {
11+
final ProtocolVersion protocolVersion = new RedirectProtocolVersion(version, name, ProtocolVersion.v1_8);
1112
ProtocolVersion.register(protocolVersion);
1213
return protocolVersion;
1314
}

src/main/java/btw/lowercase/viasnapshot/ViaSnapshot.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package btw.lowercase.viasnapshot;
22

33
import btw.lowercase.viasnapshot.protocol.v15w31ato1_8.Protocol15w31a_To1_8;
4+
import btw.lowercase.viasnapshot.protocol.v15w31bto15w31a.Protocol15w31b_To15w31a;
45
import com.viaversion.viaversion.api.Via;
56
import com.viaversion.viaversion.api.protocol.ProtocolManager;
67
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
@@ -16,13 +17,13 @@ public void onEnable() {
1617
}
1718

1819
@EventHandler
19-
public void onInitializeEvent(ProtocolTranslatorInitEvent event) {
20+
private void onInitializeEvent(ProtocolTranslatorInitEvent event) {
2021
event.registerPlatform(() -> {
2122
// Adds this to the VV dump
2223
Via.getManager().getSubPlatforms().add(String.format("git-ViaSnapshot-%s", getVersion()));
23-
2424
final ProtocolManager protocolManager = Via.getManager().getProtocolManager();
2525
protocolManager.registerProtocol(new Protocol15w31a_To1_8(), SnapshotProtocolVersion.v15w31a, ProtocolVersion.v1_8);
26+
protocolManager.registerProtocol(new Protocol15w31b_To15w31a(), SnapshotProtocolVersion.v15w31b, SnapshotProtocolVersion.v15w31a);
2627
return null;
2728
});
2829
}

src/main/java/btw/lowercase/viasnapshot/protocol/v15w31ato1_8/packet/ClientboundPackets15w31a.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public enum ClientboundPackets15w31a implements ClientboundPacketType {
7878
RESOURCE_PACK,
7979
UPDATE_ENTITY_NBT;
8080

81-
private ClientboundPackets15w31a() {
81+
ClientboundPackets15w31a() {
8282
}
8383

8484
public int getId() {

src/main/java/btw/lowercase/viasnapshot/protocol/v15w31ato1_8/packet/ServerboundPackets15w31a.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public enum ServerboundPackets15w31a implements ServerboundPacketType {
3131
TELEPORT_TO_ENTITY,
3232
RESOURCE_PACK;
3333

34-
private ServerboundPackets15w31a() {
34+
ServerboundPackets15w31a() {
3535
}
3636

3737
public int getId() {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package btw.lowercase.viasnapshot.protocol.v15w31bto15w31a;
2+
3+
import btw.lowercase.viasnapshot.protocol.v15w31ato1_8.packet.ClientboundPackets15w31a;
4+
import btw.lowercase.viasnapshot.protocol.v15w31ato1_8.packet.ServerboundPackets15w31a;
5+
import btw.lowercase.viasnapshot.protocol.v15w31bto15w31a.packet.ClientboundPackets15w31b;
6+
import btw.lowercase.viasnapshot.protocol.v15w31bto15w31a.packet.ServerboundPackets15w31b;
7+
import btw.lowercase.viasnapshot.protocol.v15w31bto15w31a.rewriter.PacketRewriter15w31b;
8+
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
9+
10+
public class Protocol15w31b_To15w31a extends AbstractProtocol<ClientboundPackets15w31a, ClientboundPackets15w31b, ServerboundPackets15w31a, ServerboundPackets15w31b> {
11+
public Protocol15w31b_To15w31a() {
12+
super(ClientboundPackets15w31a.class, ClientboundPackets15w31b.class, ServerboundPackets15w31a.class, ServerboundPackets15w31b.class);
13+
}
14+
15+
@Override
16+
protected void registerPackets() {
17+
PacketRewriter15w31b.register(this);
18+
}
19+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package btw.lowercase.viasnapshot.protocol.v15w31bto15w31a.packet;
2+
3+
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
4+
5+
public enum ClientboundPackets15w31b implements ClientboundPacketType {
6+
KEEP_ALIVE,
7+
LOGIN,
8+
CHAT,
9+
SET_TIME,
10+
SET_EQUIPPED_ITEM,
11+
SET_DEFAULT_SPAWN_POSITION,
12+
SET_HEALTH,
13+
RESPAWN,
14+
PLAYER_POSITION,
15+
SET_CARRIED_ITEM,
16+
PLAYER_SLEEP,
17+
ANIMATE,
18+
ADD_PLAYER,
19+
TAKE_ITEM_ENTITY,
20+
ADD_ENTITY,
21+
ADD_MOB,
22+
ADD_PAINTING,
23+
ADD_EXPERIENCE_ORB,
24+
SET_ENTITY_MOTION,
25+
REMOVE_ENTITIES,
26+
MOVE_ENTITY,
27+
MOVE_ENTITY_POS,
28+
MOVE_ENTITY_ROT,
29+
MOVE_ENTITY_POS_ROT,
30+
TELEPORT_ENTITY,
31+
ROTATE_HEAD,
32+
ENTITY_EVENT,
33+
SET_ENTITY_LINK,
34+
SET_ENTITY_DATA,
35+
UPDATE_MOB_EFFECT,
36+
REMOVE_MOB_EFFECT,
37+
SET_EXPERIENCE,
38+
UPDATE_ATTRIBUTES,
39+
LEVEL_CHUNK,
40+
CHUNK_BLOCKS_UPDATE,
41+
BLOCK_UPDATE,
42+
BLOCK_EVENT,
43+
BLOCK_DESTRUCTION,
44+
MAP_BULK_CHUNK,
45+
EXPLODE,
46+
LEVEL_EVENT,
47+
CUSTOM_SOUND,
48+
LEVEL_PARTICLES,
49+
GAME_EVENT,
50+
ADD_GLOBAL_ENTITY,
51+
OPEN_SCREEN,
52+
CONTAINER_CLOSE,
53+
CONTAINER_SET_SLOT,
54+
CONTAINER_SET_CONTENT,
55+
CONTAINER_SET_DATA,
56+
CONTAINER_ACK,
57+
UPDATE_SIGN,
58+
MAP_ITEM_DATA,
59+
BLOCK_ENTITY_DATA,
60+
OPEN_SIGN_EDITOR,
61+
AWARD_STATS,
62+
PLAYER_INFO,
63+
PLAYER_ABILITIES,
64+
COMMAND_SUGGESTIONS,
65+
SET_OBJECTIVE,
66+
SET_SCORE,
67+
SET_DISPLAY_OBJECTIVE,
68+
SET_PLAYER_TEAM,
69+
CUSTOM_PAYLOAD,
70+
DISCONNECT,
71+
CHANGE_DIFFICULTY,
72+
PLAYER_COMBAT,
73+
SET_CAMERA,
74+
SET_BORDER,
75+
SET_TITLES,
76+
SET_COMPRESSION,
77+
TAB_LIST,
78+
RESOURCE_PACK,
79+
BOSS_BAR;
80+
81+
ClientboundPackets15w31b() {
82+
}
83+
84+
public int getId() {
85+
return this.ordinal();
86+
}
87+
88+
public String getName() {
89+
return this.name();
90+
}
91+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package btw.lowercase.viasnapshot.protocol.v15w31bto15w31a.packet;
2+
3+
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
4+
5+
public enum ServerboundPackets15w31b implements ServerboundPacketType {
6+
KEEP_ALIVE,
7+
CHAT,
8+
INTERACT,
9+
MOVE_PLAYER_STATUS_ONLY,
10+
MOVE_PLAYER_POS,
11+
MOVE_PLAYER_ROT,
12+
MOVE_PLAYER_POS_ROT,
13+
PLAYER_ACTION,
14+
USE_ITEM,
15+
USE_ITEM_ON,
16+
SET_CARRIED_ITEM,
17+
SWING,
18+
PLAYER_COMMAND,
19+
PLAYER_INPUT,
20+
CONTAINER_CLOSE,
21+
CONTAINER_CLICK,
22+
CONTAINER_ACK,
23+
SET_CREATIVE_MODE_SLOT,
24+
CONTAINER_BUTTON_CLICK,
25+
SIGN_UPDATE,
26+
PLAYER_ABILITIES,
27+
COMMAND_SUGGESTION,
28+
CLIENT_INFORMATION,
29+
CLIENT_COMMAND,
30+
CUSTOM_PAYLOAD,
31+
TELEPORT_TO_ENTITY,
32+
RESOURCE_PACK;
33+
34+
ServerboundPackets15w31b() {
35+
}
36+
37+
public int getId() {
38+
return this.ordinal();
39+
}
40+
41+
public String getName() {
42+
return this.name();
43+
}
44+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package btw.lowercase.viasnapshot.protocol.v15w31bto15w31a.rewriter;
2+
3+
import btw.lowercase.viasnapshot.protocol.v15w31ato1_8.packet.ClientboundPackets15w31a;
4+
import btw.lowercase.viasnapshot.protocol.v15w31bto15w31a.Protocol15w31b_To15w31a;
5+
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
6+
import com.viaversion.viaversion.api.type.Types;
7+
import com.viaversion.viaversion.protocols.v1_8to1_9.Protocol1_8To1_9;
8+
9+
// https://wiki.vg/index.php?title=Pre-release_protocol&direction=prev&oldid=6751
10+
public class PacketRewriter15w31b {
11+
public static void register(final Protocol15w31b_To15w31a protocol) {
12+
// Player List Item
13+
protocol.registerClientbound(ClientboundPackets15w31a.PLAYER_INFO, new PacketHandlers() {
14+
public void register() {
15+
map(Types.VAR_INT); // Action
16+
map(Types.VAR_INT); // Count
17+
handler((wrapper) -> {
18+
final int action = wrapper.get(Types.VAR_INT, 0);
19+
final int count = wrapper.get(Types.VAR_INT, 1);
20+
for (int i = 0; i < count; ++i) {
21+
wrapper.passthrough(Types.UUID); // UUID
22+
if (action != 0) {
23+
if (action != 1 && action != 2) {
24+
// Update Display Name
25+
if (action == 3) {
26+
String displayName = wrapper.read(Types.OPTIONAL_STRING);
27+
wrapper.write(Types.OPTIONAL_COMPONENT, displayName != null ? Protocol1_8To1_9.STRING_TO_JSON.transform(wrapper, displayName) : null);
28+
}
29+
} else {
30+
// ?
31+
wrapper.passthrough(Types.VAR_INT);
32+
}
33+
} else {
34+
// Add Player
35+
wrapper.passthrough(Types.STRING); // Name
36+
37+
final int properties = wrapper.passthrough(Types.VAR_INT); // Number of properties
38+
for (int j = 0; j < properties; ++j) {
39+
wrapper.passthrough(Types.STRING);
40+
wrapper.passthrough(Types.STRING);
41+
wrapper.passthrough(Types.OPTIONAL_STRING);
42+
}
43+
44+
wrapper.passthrough(Types.VAR_INT);
45+
wrapper.passthrough(Types.VAR_INT);
46+
47+
String displayName = wrapper.read(Types.OPTIONAL_STRING);
48+
wrapper.write(Types.OPTIONAL_COMPONENT, displayName != null ? Protocol1_8To1_9.STRING_TO_JSON.transform(wrapper, displayName) : null);
49+
}
50+
}
51+
});
52+
}
53+
});
54+
55+
56+
protocol.cancelClientbound(ClientboundPackets15w31a.UPDATE_ENTITY_NBT); // TODO: now bossbar
57+
}
58+
}

0 commit comments

Comments
 (0)