Skip to content

Commit 1ca5f04

Browse files
Merge pull request #273 from NukkitX/1.5
1.5
2 parents 0f24446 + 9ae5b6b commit 1ca5f04

File tree

9 files changed

+140
-14
lines changed

9 files changed

+140
-14
lines changed

src/main/java/cn/nukkit/level/Level.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3098,7 +3098,7 @@ public void addEntityMotion(int chunkX, int chunkZ, long entityId, double x, dou
30983098
}
30993099

31003100
public void addEntityMovement(int chunkX, int chunkZ, long entityId, double x, double y, double z, double yaw, double pitch, double headYaw) {
3101-
MoveEntityPacket pk = new MoveEntityPacket();
3101+
MoveEntityAbsolutePacket pk = new MoveEntityAbsolutePacket();
31023102
pk.eid = entityId;
31033103
pk.x = (float) x;
31043104
pk.y = (float) y;

src/main/java/cn/nukkit/level/particle/FloatingTextParticle.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import cn.nukkit.entity.Entity;
44
import cn.nukkit.entity.data.EntityMetadata;
5+
import cn.nukkit.entity.data.Skin;
56
import cn.nukkit.item.Item;
67
import cn.nukkit.math.Vector3;
78
import cn.nukkit.network.protocol.AddPlayerPacket;
89
import cn.nukkit.network.protocol.DataPacket;
10+
import cn.nukkit.network.protocol.PlayerListPacket;
911
import cn.nukkit.network.protocol.RemoveEntityPacket;
1012

1113
import java.util.ArrayList;
@@ -17,7 +19,7 @@
1719
* Package cn.nukkit.level.particle in project Nukkit .
1820
*/
1921
public class FloatingTextParticle extends Particle {
20-
22+
private static final Skin EMPTY_SKIN = new Skin(new byte[0]);
2123

2224
protected String text;
2325
protected String title;
@@ -76,9 +78,18 @@ public DataPacket[] encode() {
7678
packets.add(pk);
7779
}
7880

81+
UUID uuid = UUID.randomUUID();
82+
7983
if (!this.invisible) {
84+
PlayerListPacket playerAdd = new PlayerListPacket();
85+
playerAdd.entries = new PlayerListPacket.Entry[] {
86+
new PlayerListPacket.Entry(uuid, this.entityId, this.title, EMPTY_SKIN)
87+
};
88+
playerAdd.type = PlayerListPacket.TYPE_ADD;
89+
packets.add(playerAdd);
90+
8091
AddPlayerPacket pk = new AddPlayerPacket();
81-
pk.uuid = UUID.randomUUID();
92+
pk.uuid = uuid;
8293
pk.username = this.title + (this.text.isEmpty() ? "" : "\n" + this.text);
8394
pk.entityUniqueId = this.entityId;
8495
pk.entityRuntimeId = this.entityId;
@@ -99,6 +110,13 @@ public DataPacket[] encode() {
99110
.putFloat(Entity.DATA_SCALE, 0.01f); //zero causes problems on debug builds?
100111
pk.item = Item.get(Item.AIR);
101112
packets.add(pk);
113+
114+
PlayerListPacket playerRemove = new PlayerListPacket();
115+
playerRemove.entries = new PlayerListPacket.Entry[] {
116+
new PlayerListPacket.Entry(uuid)
117+
};
118+
playerRemove.type = PlayerListPacket.TYPE_REMOVE;
119+
packets.add(playerRemove);
102120
}
103121

104122
return packets.toArray(new DataPacket[0]);

src/main/java/cn/nukkit/network/Network.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ private void registerPackets() {
257257
this.registerPacket(ProtocolInfo.MOB_EQUIPMENT_PACKET, MobEquipmentPacket.class);
258258
this.registerPacket(ProtocolInfo.MODAL_FORM_REQUEST_PACKET, ModalFormRequestPacket.class);
259259
this.registerPacket(ProtocolInfo.MODAL_FORM_RESPONSE_PACKET, ModalFormResponsePacket.class);
260-
this.registerPacket(ProtocolInfo.MOVE_ENTITY_PACKET, MoveEntityPacket.class);
260+
this.registerPacket(ProtocolInfo.MOVE_ENTITY_ABSOLUTE_PACKET, MoveEntityAbsolutePacket.class);
261261
this.registerPacket(ProtocolInfo.MOVE_PLAYER_PACKET, MovePlayerPacket.class);
262262
this.registerPacket(ProtocolInfo.PLAYER_ACTION_PACKET, PlayerActionPacket.class);
263263
this.registerPacket(ProtocolInfo.PLAYER_INPUT_PACKET, PlayerInputPacket.class);
@@ -295,5 +295,7 @@ private void registerPackets() {
295295
this.registerPacket(ProtocolInfo.UPDATE_ATTRIBUTES_PACKET, UpdateAttributesPacket.class);
296296
this.registerPacket(ProtocolInfo.UPDATE_BLOCK_PACKET, UpdateBlockPacket.class);
297297
this.registerPacket(ProtocolInfo.UPDATE_TRADE_PACKET, UpdateTradePacket.class);
298+
this.registerPacket(ProtocolInfo.MOVE_ENTITY_DELTA_PACKET, MoveEntityDeltaPacket.class);
299+
this.registerPacket(ProtocolInfo.SET_LOCAL_PLAYER_AS_INITIALIZED_PACKET, SetLocalPlayerAsInitializedPacket.class);
298300
}
299301
}

src/main/java/cn/nukkit/network/protocol/MoveEntityPacket.java renamed to src/main/java/cn/nukkit/network/protocol/MoveEntityAbsolutePacket.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* author: MagicDroidX
77
* Nukkit Project
88
*/
9-
public class MoveEntityPacket extends DataPacket {
10-
public static final byte NETWORK_ID = ProtocolInfo.MOVE_ENTITY_PACKET;
9+
public class MoveEntityAbsolutePacket extends DataPacket {
10+
public static final byte NETWORK_ID = ProtocolInfo.MOVE_ENTITY_ABSOLUTE_PACKET;
1111

1212
public long eid;
1313
public double x;
@@ -27,6 +27,9 @@ public byte pid() {
2727
@Override
2828
public void decode() {
2929
this.eid = this.getEntityRuntimeId();
30+
int flags = this.getByte();
31+
teleport = (flags & 0x01) != 0;
32+
onGround = (flags & 0x02) != 0;
3033
Vector3f v = this.getVector3f();
3134
this.x = v.x;
3235
this.y = v.y;
@@ -42,11 +45,17 @@ public void decode() {
4245
public void encode() {
4346
this.reset();
4447
this.putEntityRuntimeId(this.eid);
48+
byte flags = 0;
49+
if (teleport) {
50+
flags |= 0x01;
51+
}
52+
if (onGround) {
53+
flags |= 0x02;
54+
}
55+
this.putByte(flags);
4556
this.putVector3f((float) this.x, (float) this.y, (float) this.z);
4657
this.putByte((byte) (this.pitch / (360d / 256d)));
4758
this.putByte((byte) (this.headYaw / (360d / 256d)));
4859
this.putByte((byte) (this.yaw / (360d / 256d)));
49-
this.putBoolean(this.onGround);
50-
this.putBoolean(this.teleport);
5160
}
5261
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package cn.nukkit.network.protocol;
2+
3+
public class MoveEntityDeltaPacket extends DataPacket {
4+
public static final byte NETWORK_ID = ProtocolInfo.MOVE_ENTITY_DELTA_PACKET;
5+
6+
public static final int FLAG_HAS_X = 0b1;
7+
public static final int FLAG_HAS_Y = 0b10;
8+
public static final int FLAG_HAS_Z = 0b100;
9+
public static final int FLAG_HAS_YAW = 0b1000;
10+
public static final int FLAG_HAS_HEAD_YAW = 0b10000;
11+
public static final int FLAG_HAS_PITCH = 0b100000;
12+
13+
public int flags = 0;
14+
public int xDelta = 0;
15+
public int yDelta = 0;
16+
public int zDelta = 0;
17+
public double yawDelta = 0;
18+
public double headYawDelta = 0;
19+
public double pitchDelta = 0;
20+
21+
@Override
22+
public byte pid() {
23+
return NETWORK_ID;
24+
}
25+
26+
@Override
27+
public void decode() {
28+
this.flags = this.getByte();
29+
this.xDelta = getCoordinate(FLAG_HAS_X);
30+
this.yDelta = getCoordinate(FLAG_HAS_Y);
31+
this.zDelta = getCoordinate(FLAG_HAS_Z);
32+
this.yawDelta = getRotation(FLAG_HAS_YAW);
33+
this.headYawDelta = getRotation(FLAG_HAS_HEAD_YAW);
34+
this.pitchDelta = getRotation(FLAG_HAS_PITCH);
35+
}
36+
37+
@Override
38+
public void encode() {
39+
this.putByte((byte) flags);
40+
putCoordinate(FLAG_HAS_X, this.xDelta);
41+
putCoordinate(FLAG_HAS_Y, this.yDelta);
42+
putCoordinate(FLAG_HAS_Z, this.zDelta);
43+
putRotation(FLAG_HAS_YAW, this.yawDelta);
44+
putRotation(FLAG_HAS_HEAD_YAW, this.headYawDelta);
45+
putRotation(FLAG_HAS_PITCH, this.pitchDelta);
46+
}
47+
48+
private int getCoordinate(int flag) {
49+
if ((flags & flag) != 0) {
50+
return this.getVarInt();
51+
}
52+
return 0;
53+
}
54+
55+
private double getRotation(int flag) {
56+
if ((flags & flag) != 0) {
57+
return this.getByte() * (360d / 256d);
58+
}
59+
return 0d;
60+
}
61+
62+
private void putCoordinate(int flag, int value) {
63+
if ((flags & flag) != 0) {
64+
this.putVarInt(value);
65+
}
66+
}
67+
68+
private void putRotation(int flag, double value) {
69+
if ((flags & flag) != 0) {
70+
this.putByte((byte) (value / (360d / 256d)));
71+
}
72+
}
73+
}

src/main/java/cn/nukkit/network/protocol/ProtocolInfo.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public interface ProtocolInfo {
1313
/**
1414
* Actual Minecraft: PE protocol version
1515
*/
16-
int CURRENT_PROTOCOL = Integer.valueOf("261"); //plugins can change it
16+
int CURRENT_PROTOCOL = Integer.valueOf("274"); //plugins can change it
1717

1818
List<Integer> SUPPORTED_PROTOCOLS = Ints.asList(CURRENT_PROTOCOL);
1919

20-
String MINECRAFT_VERSION = "v1.4";
21-
String MINECRAFT_VERSION_NETWORK = "1.4";
20+
String MINECRAFT_VERSION = "v1.5";
21+
String MINECRAFT_VERSION_NETWORK = "1.5";
2222

2323
byte LOGIN_PACKET = 0x01;
2424
byte PLAY_STATUS_PACKET = 0x02;
@@ -37,7 +37,7 @@ public interface ProtocolInfo {
3737
byte ADD_ITEM_ENTITY_PACKET = 0x0f;
3838
byte ADD_HANGING_ENTITY_PACKET = 0x10;
3939
byte TAKE_ITEM_ENTITY_PACKET = 0x11;
40-
byte MOVE_ENTITY_PACKET = 0x12;
40+
byte MOVE_ENTITY_ABSOLUTE_PACKET = 0x12;
4141
byte MOVE_PLAYER_PACKET = 0x13;
4242
byte RIDER_JUMP_PACKET = 0x14;
4343
byte UPDATE_BLOCK_PACKET = 0x15;
@@ -125,5 +125,7 @@ public interface ProtocolInfo {
125125
byte SERVER_SETTINGS_RESPONSE_PACKET = 0x67;
126126
byte SHOW_PROFILE_PACKET = 0x68;
127127
byte SET_DEFAULT_GAME_TYPE_PACKET = 0x69;
128+
byte MOVE_ENTITY_DELTA_PACKET = 0x6f;
129+
byte SET_LOCAL_PLAYER_AS_INITIALIZED_PACKET = 0x70;
128130
byte BATCH_PACKET = (byte) 0xff;
129131
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cn.nukkit.network.protocol;
2+
3+
public class SetLocalPlayerAsInitializedPacket extends DataPacket {
4+
public static final byte NETWORK_ID = ProtocolInfo.SET_LOCAL_PLAYER_AS_INITIALIZED_PACKET;
5+
6+
public long eid;
7+
8+
@Override
9+
public byte pid() {
10+
return NETWORK_ID;
11+
}
12+
13+
@Override
14+
public void decode() {
15+
eid = this.getUnsignedVarLong();
16+
}
17+
18+
@Override
19+
public void encode() {
20+
this.putUnsignedVarLong(eid);
21+
}
22+
}

src/main/java/cn/nukkit/utils/DummyBossBar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ private void sendSetBossBarTitle() {
196196
* Update boss entity's position when teleport and each 5s.
197197
*/
198198
public void updateBossEntityPosition() {
199-
MoveEntityPacket pk = new MoveEntityPacket();
199+
MoveEntityAbsolutePacket pk = new MoveEntityAbsolutePacket();
200200
pk.eid = this.bossBarId;
201201
pk.x = this.player.x;
202202
pk.y = -10;

src/main/resources/runtimeid_table.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)