Skip to content

Commit

Permalink
Updated to Bedrock 1.20.50 and fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Dec 7, 2023
1 parent 2cc90c9 commit 2084244
Show file tree
Hide file tree
Showing 57 changed files with 5,439 additions and 837 deletions.
4 changes: 2 additions & 2 deletions Data Asset Sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This file has been dumped from a BDS server using [CloudburstMC/ProxyPass](https
[PMMP/BedrockBlockUpgradeSchema](https://github.com/pmmp/BedrockBlockUpgradeSchema/blob/79bb3ad542ef19e828fdf1fa6adc54f1fa4b3bb5/block_legacy_id_map.json)

### data/bedrock/block_palette.nbt
[GeyserMC/Geyser](https://github.com/GeyserMC/Geyser/blob/574dad015d11c072d9fc7c5989d94f9689078b77/core/src/main/resources/bedrock/block_palette.1_20_40.nbt)
[GeyserMC/Geyser](https://github.com/GeyserMC/Geyser/blob/998caee156d38245a15e560f15864319ad125cbb/core/src/main/resources/bedrock/block_palette.1_20_50.nbt)

### data/bedrock/entity_identifiers.nbt
This file has been dumped from a BDS server using [CloudburstMC/ProxyPass](https://github.com/CloudburstMC/ProxyPass).
Expand All @@ -26,7 +26,7 @@ This file has been copied from the official bedrock client's assets folder:
`%MC-Root%\data\skin_packs\vanilla\*`

### data/java/via_mappings.json
[ViaVersion Mappings](https://github.com/ViaVersion/Mappings/blob/main/mappings/mapping-1.20.2.json)
[ViaVersion Mappings](https://github.com/ViaVersion/Mappings/blob/main/mappings/mapping-1.20.3.json)

### data/java/registries.nbt
This file has been dumped from a vanilla server using a fabric mod.
Expand Down
8 changes: 4 additions & 4 deletions Update Process.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ This file lists the steps necessary to update ViaBedrock.
2. Update ProtocolConstants class
3. Update hardcoded blockstates: Search all files for `new BlockState("`
4. Update data in `protocol/data` and `protocol/model` packages
5. Replace `Types1_20_2` with the new type
6. Replace `EntityTypes1_19_4` and `Protocol1_19_4To1_19_3.class` with the new type
7. Replace `ClientboundPackets1_20_2` and `ServerboundPackets1_20_2` with the new packet enum
8. Replace `ClientboundConfigurationPackets1_20_2` and `ServerboundConfigurationPackets1_20_2` with the new packet enum
5. Replace `Types1_20_3` with the new type
6. Replace `EntityTypes1_20_3` and `Protocol1_20_3To1_20_2.class` with the new type
7. Replace `ClientboundPackets1_20_3` and `ServerboundPackets1_20_3` with the new packet enum
8. Replace `ClientboundConfigurationPackets1_20_3` and `ServerboundConfigurationPackets1_20_2` with the new packet enum
9. Update changed packet contents
10. Update rewriters
11. Done!
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ repositories {
}

dependencies {
compileOnly "com.viaversion:viaversion-common:4.9.0-23w44a-SNAPSHOT"
compileOnly "com.viaversion:viaversion-common:4.9.1"
compileOnly "org.yaml:snakeyaml:2.2"
compileOnly "com.google.guava:guava:32.1.3-jre"
compileOnly "io.netty:netty-handler:4.1.101.Final"
Expand All @@ -54,7 +54,7 @@ dependencies {
api("net.lenni0451.mcstructs-bedrock:forms:1.2.0") {
exclude group: "com.google.code.gson", module: "gson"
}
api("net.lenni0451.mcstructs:text:2.4.0-SNAPSHOT") {
api("net.lenni0451.mcstructs:text:2.4.0") {
exclude group: "com.google.code.gson", module: "gson"
}
api "com.vdurmont:semver4j:3.1.0"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ org.gradle.configureondemand=true

maven_group=net.raphimc
maven_name=ViaBedrock
maven_version=0.0.3-SNAPSHOT
maven_version=0.0.4-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPackets1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3;
import com.viaversion.viaversion.util.Pair;
import net.raphimc.viabedrock.ViaBedrock;
import net.raphimc.viabedrock.protocol.BedrockProtocol;
import net.raphimc.viabedrock.protocol.ServerboundBedrockPackets;
import net.raphimc.viabedrock.protocol.data.enums.bedrock.*;
import net.raphimc.viabedrock.protocol.model.Position2f;
import net.raphimc.viabedrock.protocol.model.Position3f;
import net.raphimc.viabedrock.protocol.storage.*;
import net.raphimc.viabedrock.protocol.storage.ChunkTracker;
import net.raphimc.viabedrock.protocol.storage.GameSessionStorage;
import net.raphimc.viabedrock.protocol.storage.PacketSyncStorage;
import net.raphimc.viabedrock.protocol.storage.PlayerListStorage;
import net.raphimc.viabedrock.protocol.types.BedrockTypes;

import java.util.UUID;
Expand Down Expand Up @@ -79,21 +82,18 @@ public void tick() throws Exception {
}

public void closeDownloadingTerrainScreen() throws Exception {
final SpawnPositionStorage spawnPositionStorage = this.user.get(SpawnPositionStorage.class);
final ChunkTracker chunkTracker = this.user.get(ChunkTracker.class);

final PacketWrapper spawnPosition = PacketWrapper.create(ClientboundPackets1_20_2.SPAWN_POSITION, this.user);
spawnPosition.write(Type.POSITION1_14, spawnPositionStorage.getSpawnPosition(chunkTracker.getDimensionId())); // position
spawnPosition.write(Type.FLOAT, 0F); // angle
spawnPosition.send(BedrockProtocol.class);
final PacketWrapper gameEvent = PacketWrapper.create(ClientboundPackets1_20_3.GAME_EVENT, this.user);
gameEvent.write(Type.UNSIGNED_BYTE, (short) 13); // LEVEL_CHUNKS_LOAD_START
gameEvent.write(Type.FLOAT, 0F); // value
gameEvent.send(BedrockProtocol.class);
}

public void sendPlayerPositionPacketToClient(final boolean keepRotation) throws Exception {
this.sendPlayerPositionPacketToClient(keepRotation, true);
}

public void sendPlayerPositionPacketToClient(final boolean keepRotation, final boolean fakeTeleport) throws Exception {
final PacketWrapper playerPosition = PacketWrapper.create(ClientboundPackets1_20_2.PLAYER_POSITION, this.user);
final PacketWrapper playerPosition = PacketWrapper.create(ClientboundPackets1_20_3.PLAYER_POSITION, this.user);
this.writePlayerPositionPacketToClient(playerPosition, keepRotation, fakeTeleport);
playerPosition.send(BedrockProtocol.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package net.raphimc.viabedrock.api.model.entity;

import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_4;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_3;
import net.raphimc.viabedrock.protocol.model.Position3f;

import java.util.UUID;
Expand All @@ -30,7 +30,7 @@ public class Entity {
protected final long runtimeId;
protected final int javaId;
protected final UUID javaUuid;
protected final EntityTypes1_19_4 type;
protected final EntityTypes1_20_3 type;

/**
* x, y, z
Expand All @@ -44,7 +44,7 @@ public class Entity {
protected String name;
protected int age;

public Entity(final UserConnection user, final long uniqueId, final long runtimeId, final int javaId, final UUID javaUuid, final EntityTypes1_19_4 type) {
public Entity(final UserConnection user, final long uniqueId, final long runtimeId, final int javaId, final UUID javaUuid, final EntityTypes1_20_3 type) {
this.user = user;
this.uniqueId = uniqueId;
this.runtimeId = runtimeId;
Expand Down Expand Up @@ -77,7 +77,7 @@ public UUID javaUuid() {
return this.javaUuid;
}

public EntityTypes1_19_4 type() {
public EntityTypes1_20_3 type() {
return this.type;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
package net.raphimc.viabedrock.api.model.entity;

import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_4;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_3;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPackets1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3;
import net.raphimc.viabedrock.api.util.StringUtil;
import net.raphimc.viabedrock.api.util.TextUtil;
import net.raphimc.viabedrock.protocol.BedrockProtocol;
Expand All @@ -31,42 +31,42 @@
public class PlayerEntity extends Entity {

public PlayerEntity(final UserConnection user, final long uniqueId, final long runtimeId, final int javaId, final UUID javaUuid) {
super(user, uniqueId, runtimeId, javaId, javaUuid, EntityTypes1_19_4.PLAYER);
super(user, uniqueId, runtimeId, javaId, javaUuid, EntityTypes1_20_3.PLAYER);
}

public void createTeam() throws Exception {
final PacketWrapper teams = PacketWrapper.create(ClientboundPackets1_20_2.TEAMS, this.user);
final PacketWrapper teams = PacketWrapper.create(ClientboundPackets1_20_3.TEAMS, this.user);
teams.write(Type.STRING, "vb_" + this.javaId); // team name
teams.write(Type.BYTE, (byte) 0); // mode | 0 = ADD
teams.write(Type.COMPONENT, TextUtil.stringToGson("vb_" + this.javaId)); // display name
teams.write(Type.TAG, TextUtil.stringToNbt("vb_" + this.javaId)); // display name
teams.write(Type.BYTE, (byte) 3); // flags
teams.write(Type.STRING, "always"); // name tag visibility
teams.write(Type.STRING, "never"); // collision rule
teams.write(Type.VAR_INT, 21); // color | 21 = RESET
teams.write(Type.COMPONENT, TextUtil.stringToGson("")); // prefix
teams.write(Type.COMPONENT, TextUtil.stringToGson("")); // suffix
teams.write(Type.TAG, TextUtil.stringToNbt("")); // prefix
teams.write(Type.TAG, TextUtil.stringToNbt("")); // suffix
teams.write(Type.STRING_ARRAY, new String[]{StringUtil.encodeUUID(this.javaUuid)}); // players
teams.send(BedrockProtocol.class);
}

public void updateName(final String name) throws Exception {
this.setName(name);

final PacketWrapper teams = PacketWrapper.create(ClientboundPackets1_20_2.TEAMS, this.user);
final PacketWrapper teams = PacketWrapper.create(ClientboundPackets1_20_3.TEAMS, this.user);
teams.write(Type.STRING, "vb_" + this.javaId); // team name
teams.write(Type.BYTE, (byte) 2); // mode | 2 = UPDATE
teams.write(Type.COMPONENT, TextUtil.stringToGson("vb_" + this.javaId)); // display name
teams.write(Type.TAG, TextUtil.stringToNbt("vb_" + this.javaId)); // display name
teams.write(Type.BYTE, (byte) 3); // flags
teams.write(Type.STRING, "always"); // name tag visibility
teams.write(Type.STRING, "never"); // collision rule
teams.write(Type.VAR_INT, 21); // color | 21 = RESET
teams.write(Type.COMPONENT, TextUtil.stringToGson(name)); // prefix
teams.write(Type.COMPONENT, TextUtil.stringToGson("")); // suffix
teams.write(Type.TAG, TextUtil.stringToNbt(name)); // prefix
teams.write(Type.TAG, TextUtil.stringToNbt("")); // suffix
teams.send(BedrockProtocol.class);
}

public void deleteTeam() throws Exception {
final PacketWrapper teams = PacketWrapper.create(ClientboundPackets1_20_2.TEAMS, this.user);
final PacketWrapper teams = PacketWrapper.create(ClientboundPackets1_20_3.TEAMS, this.user);
teams.write(Type.STRING, "vb_" + this.javaId); // team name
teams.write(Type.BYTE, (byte) 1); // mode | 1 = REMOVE
teams.send(BedrockProtocol.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPackets1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3;
import net.lenni0451.mcstructs.text.ATextComponent;
import net.raphimc.viabedrock.api.model.inventory.Container;
import net.raphimc.viabedrock.protocol.BedrockProtocol;
Expand Down Expand Up @@ -57,7 +57,7 @@ public void onClosed() throws Exception {
}

protected void close() throws Exception {
final PacketWrapper closeWindow = PacketWrapper.create(ClientboundPackets1_20_2.CLOSE_WINDOW, this.user);
final PacketWrapper closeWindow = PacketWrapper.create(ClientboundPackets1_20_3.CLOSE_WINDOW, this.user);
closeWindow.write(Type.UNSIGNED_BYTE, (short) this.windowId); // window id
closeWindow.send(BedrockProtocol.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@

public class ScoreboardEntry {

public static final int ACTION_CHANGE = 0;
public static final int ACTION_REMOVE = 1;

private boolean isPlayerId;
private Long entityId;
private String fakePlayerName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPackets1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3;
import net.raphimc.viabedrock.protocol.BedrockProtocol;

import java.util.HashMap;
Expand Down Expand Up @@ -66,29 +66,35 @@ public void addEntry(final UserConnection user, final long scoreboardId, final S
this.entries.put(scoreboardId, entry);

entry.updateJavaName(user);
this.updateEntry(user, entry, ScoreboardEntry.ACTION_CHANGE);
this.updateEntry0(user, entry);
}

public void updateEntry(final UserConnection user, final ScoreboardEntry entry) throws Exception {
this.updateEntry(user, entry, ScoreboardEntry.ACTION_REMOVE);
this.removeEntry0(user, entry);
entry.updateJavaName(user);
this.updateEntry(user, entry, ScoreboardEntry.ACTION_CHANGE);
this.updateEntry0(user, entry);
}

public void removeEntry(final UserConnection user, final long scoreboardId) throws Exception {
final ScoreboardEntry entry = this.entries.remove(scoreboardId);

this.updateEntry(user, entry, ScoreboardEntry.ACTION_REMOVE);
this.removeEntry0(user, entry);
}

public void updateEntry(final UserConnection user, final ScoreboardEntry entry, final int action) throws Exception {
final PacketWrapper updateScore = PacketWrapper.create(ClientboundPackets1_20_2.UPDATE_SCORE, user);
public void updateEntry0(final UserConnection user, final ScoreboardEntry entry) throws Exception {
final PacketWrapper updateScore = PacketWrapper.create(ClientboundPackets1_20_3.UPDATE_SCORE, user);
updateScore.write(Type.STRING, entry.javaName()); // player name
updateScore.write(Type.VAR_INT, action); // action
updateScore.write(Type.STRING, this.name); // objective name
if (action == ScoreboardEntry.ACTION_CHANGE) {
updateScore.write(Type.VAR_INT, ascending ? -entry.score() : entry.score()); // score
}
updateScore.write(Type.VAR_INT, ascending ? -entry.score() : entry.score()); // score
updateScore.write(Type.OPTIONAL_TAG, null); // display name
updateScore.write(Type.BOOLEAN, false); // has number format
updateScore.send(BedrockProtocol.class);
}

public void removeEntry0(final UserConnection user, final ScoreboardEntry entry) throws Exception {
final PacketWrapper updateScore = PacketWrapper.create(ClientboundPackets1_20_3.RESET_SCORE, user);
updateScore.write(Type.STRING, entry.javaName()); // player name
updateScore.write(Type.OPTIONAL_STRING, this.name); // objective name
updateScore.send(BedrockProtocol.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPackets1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3;
import net.raphimc.viabedrock.protocol.BedrockProtocol;
import net.raphimc.viabedrock.protocol.model.SkinData;
import net.raphimc.viabedrock.protocol.types.primitive.ImageType;
Expand Down Expand Up @@ -51,7 +51,7 @@ public static void sendSkin(final UserConnection user, final UUID uuid, final Sk
final int chunkCount = (int) Math.ceil(skinData.length / (double) maxPayloadSize);

{
final PacketWrapper pluginMessage = PacketWrapper.create(ClientboundPackets1_20_2.PLUGIN_MESSAGE, user);
final PacketWrapper pluginMessage = PacketWrapper.create(ClientboundPackets1_20_3.PLUGIN_MESSAGE, user);
pluginMessage.write(Type.STRING, CHANNEL); // Channel
pluginMessage.write(Type.INT, MESSAGE_SKIN_INFORMATION);
pluginMessage.write(Type.INT, VERSION);
Expand All @@ -68,7 +68,7 @@ public static void sendSkin(final UserConnection user, final UUID uuid, final Sk
pluginMessage.send(BedrockProtocol.class);
}
for (int i = 0; i < chunkCount; i++) {
final PacketWrapper pluginMessage = PacketWrapper.create(ClientboundPackets1_20_2.PLUGIN_MESSAGE, user);
final PacketWrapper pluginMessage = PacketWrapper.create(ClientboundPackets1_20_3.PLUGIN_MESSAGE, user);
pluginMessage.write(Type.STRING, CHANNEL); // Channel
pluginMessage.write(Type.INT, MESSAGE_SKIN_DATA);
pluginMessage.write(Type.UUID, uuid);
Expand All @@ -83,7 +83,7 @@ public static void sendSkin(final UserConnection user, final UUID uuid, final Sk
if (skin.capeData() != null) {
final byte[] capeData = ImageType.getImageData(skin.capeData());

final PacketWrapper pluginMessage = PacketWrapper.create(ClientboundPackets1_20_2.PLUGIN_MESSAGE, user);
final PacketWrapper pluginMessage = PacketWrapper.create(ClientboundPackets1_20_3.PLUGIN_MESSAGE, user);
pluginMessage.write(Type.STRING, CHANNEL); // Channel
pluginMessage.write(Type.INT, MESSAGE_CAPE);
pluginMessage.write(Type.INT, VERSION);
Expand Down
Loading

0 comments on commit 2084244

Please sign in to comment.