Skip to content

Commit 2172e54

Browse files
authored
Backport 1.21.40 support to master (#2201)
1 parent fb217e1 commit 2172e54

14 files changed

+80
-48
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ private static boolean registerBlockState(CompoundTag state, boolean force) {
5757
int runtimeId = state.getInt("runtimeId");
5858
boolean stateOverload = state.getBoolean("stateOverload");
5959

60+
// DO NOT MERGE!
61+
if (meta > 15) { // Not supported here
62+
return true; // Not an overload
63+
}
64+
6065
if (stateOverload && !force) {
6166
return false;
6267
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public byte pid() {
2323
public static final int SPECIAL_HOTBAR = 0x7a;
2424
public static final int SPECIAL_FIXED_INVENTORY = 0x7b;
2525

26+
private static final Item EMPTY_STORAGE_ITEM = Item.get(Item.AIR);
27+
2628
public int inventoryId;
2729
public Item[] slots = new Item[0];
2830

@@ -47,7 +49,7 @@ public void encode() {
4749
}
4850
this.putByte((byte) 0); // fullContainerName.id
4951
this.putBoolean(false); // fullContainerName.optional.present
50-
this.putUnsignedVarInt(0); // dynamicContainerSize
52+
this.putSlot(EMPTY_STORAGE_ITEM);
5153
}
5254

5355
@Override

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public byte pid() {
2121
public int slot;
2222
public Item item;
2323

24+
private static final Item EMPTY_STORAGE_ITEM = Item.get(Item.AIR);
25+
2426
@Override
2527
public void decode() {
2628
}
@@ -32,7 +34,7 @@ public void encode() {
3234
this.putUnsignedVarInt(this.slot);
3335
this.putByte((byte) 0); // fullContainerName.id
3436
this.putBoolean(false); // fullContainerName.optional.present
35-
this.putUnsignedVarInt(0); // dynamicContainerSize
37+
this.putSlot(EMPTY_STORAGE_ITEM);
3638
this.putSlot(this.item);
3739
}
3840
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ public void encode() {
4242
this.putVarInt(this.amplifier);
4343
this.putBoolean(this.particles);
4444
this.putVarInt(this.duration);
45-
this.putLLong(this.tick);
45+
this.putUnsignedVarLong(this.tick);
4646
}
4747
}

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ public class PlayerAuthInputPacket extends DataPacket {
2222
private float headYaw;
2323
private Vector3f position;
2424
private Vector2 motion;
25-
private Set<AuthInputAction> inputData = EnumSet.noneOf(AuthInputAction.class);
25+
private final Set<AuthInputAction> inputData = EnumSet.noneOf(AuthInputAction.class);
2626
private InputMode inputMode;
2727
private ClientPlayMode playMode;
2828
private AuthInteractionModel interactionModel;
29-
private Vector3f vrGazeDirection;
3029
private long tick;
3130
private Vector3f delta;
32-
// private ItemStackRequest itemStackRequest;
33-
private Map<PlayerActionType, PlayerBlockActionData> blockActionData = new EnumMap<>(PlayerActionType.class);
34-
private Vector2 analogMoveVector;
31+
private final Map<PlayerActionType, PlayerBlockActionData> blockActionData = new EnumMap<>(PlayerActionType.class);
3532
private long predictedVehicle;
33+
private Vector2f analogMoveVector;
3634
private Vector2f vehicleRotation;
35+
private Vector2f interactRotation;
36+
private Vector3f cameraOrientation;
3737

3838
@Override
3939
public byte pid() {
@@ -59,18 +59,11 @@ public void decode() {
5959
this.playMode = ClientPlayMode.fromOrdinal((int) this.getUnsignedVarInt());
6060
this.interactionModel = AuthInteractionModel.fromOrdinal((int) this.getUnsignedVarInt());
6161

62-
if (this.playMode == ClientPlayMode.REALITY) {
63-
this.vrGazeDirection = this.getVector3f();
64-
}
62+
this.interactRotation = this.getVector2f();
6563

6664
this.tick = this.getUnsignedVarLong();
6765
this.delta = this.getVector3f();
6866

69-
if (this.inputData.contains(AuthInputAction.PERFORM_ITEM_STACK_REQUEST)) {
70-
// TODO: this.itemStackRequest = readItemStackRequest(buf, protocolVersion);
71-
// We are safe to leave this for later, since it is only sent with ServerAuthInventories
72-
}
73-
7467
if (this.inputData.contains(AuthInputAction.PERFORM_BLOCK_ACTIONS)) {
7568
int arraySize = this.getVarInt();
7669
if (arraySize > 256) throw new IllegalArgumentException("PlayerAuthInputPacket PERFORM_BLOCK_ACTIONS is too long: " + arraySize);
@@ -91,11 +84,12 @@ public void decode() {
9184
}
9285

9386
if (this.inputData.contains(AuthInputAction.IN_CLIENT_PREDICTED_IN_VEHICLE)) {
94-
this.vehicleRotation = new Vector2f(this.getLFloat(), this.getLFloat());
87+
this.vehicleRotation = this.getVector2f();
9588
this.predictedVehicle = this.getVarLong();
9689
}
9790

98-
this.analogMoveVector = new Vector2(this.getLFloat(), this.getLFloat());
91+
this.analogMoveVector = this.getVector2f();
92+
this.cameraOrientation = this.getVector3f();
9993
}
10094

10195
@Override

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ public interface ProtocolInfo {
1414
* Actual Minecraft: PE protocol version
1515
*/
1616
@SuppressWarnings("UnnecessaryBoxing")
17-
int CURRENT_PROTOCOL = Integer.valueOf("729"); // DO NOT REMOVE BOXING
17+
int CURRENT_PROTOCOL = Integer.valueOf("748"); // DO NOT REMOVE BOXING
1818

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

21-
String MINECRAFT_VERSION_NETWORK = "1.21.30";
21+
String MINECRAFT_VERSION_NETWORK = "1.21.40";
2222
String MINECRAFT_VERSION = 'v' + MINECRAFT_VERSION_NETWORK;
2323

2424
byte BATCH_PACKET = (byte) 0xff;
@@ -237,4 +237,6 @@ public interface ProtocolInfo {
237237
byte __INTERNAL__SERVERBOUND_DIAGNOSTICS_PACKET = (byte) 215;
238238
byte __INTERNAL__CAMERA_AIM_ASSIST_PACKET = (byte) 216;
239239
byte __INTERNAL__CONTAINER_REGISTRY_CLEANUP_PACKET = (byte) 217;
240+
byte __INTERNAL__MOVEMENT_EFFECT_PACKET = (byte) 218;
241+
byte __INTERNAL__SET_MOVEMENT_AUTHORITY_PACKET = (byte) 219;
240242
}
Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package cn.nukkit.network.protocol;
22

33
import cn.nukkit.resourcepacks.ResourcePack;
4-
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
54
import lombok.ToString;
6-
import lombok.Value;
7-
8-
import java.util.List;
95

106
@ToString
117
public class ResourcePacksInfoPacket extends DataPacket {
@@ -14,12 +10,9 @@ public class ResourcePacksInfoPacket extends DataPacket {
1410

1511
public boolean mustAccept;
1612
public boolean scripting;
17-
@Deprecated
18-
public boolean forceServerPacks; // pre 1.21.30
1913
public boolean hasAddonPacks;
2014
public ResourcePack[] behaviourPackEntries = ResourcePack.EMPTY_ARRAY;
2115
public ResourcePack[] resourcePackEntries = ResourcePack.EMPTY_ARRAY;
22-
public List<CDNEntry> CDNEntries = new ObjectArrayList<>();
2316

2417
@Override
2518
public void decode() {
@@ -34,12 +27,6 @@ public void encode() {
3427
this.putBoolean(this.scripting);
3528

3629
this.encodeResourcePacks(this.resourcePackEntries);
37-
38-
this.putUnsignedVarInt(this.CDNEntries.size());
39-
this.CDNEntries.forEach((entry) -> {
40-
this.putString(entry.getPackId());
41-
this.putString(entry.getRemoteUrl());
42-
});
4330
}
4431

4532
private void encodeResourcePacks(ResourcePack[] packs) {
@@ -49,22 +36,17 @@ private void encodeResourcePacks(ResourcePack[] packs) {
4936
this.putString(entry.getPackVersion());
5037
this.putLLong(entry.getPackSize());
5138
this.putString(entry.getEncryptionKey());
52-
this.putString(""); // sub-pack name
39+
this.putString(entry.getSubPackName());
5340
this.putString(!entry.getEncryptionKey().isEmpty() ? entry.getPackId().toString() : "");
54-
this.putBoolean(false); // scripting
55-
this.putBoolean(false); // isAddonPack
56-
this.putBoolean(false); // raytracing capable
41+
this.putBoolean(entry.usesScripting());
42+
this.putBoolean(entry.isAddonPack());
43+
this.putBoolean(entry.isRaytracingCapable());
44+
this.putString(entry.getCDNUrl());
5745
}
5846
}
5947

6048
@Override
6149
public byte pid() {
6250
return NETWORK_ID;
6351
}
64-
65-
@Value
66-
public static class CDNEntry {
67-
String packId;
68-
String remoteUrl;
69-
}
7052
}

src/main/java/cn/nukkit/network/protocol/types/AuthInputAction.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,27 @@ public enum AuthInputAction {
101101
/**
102102
* @since v729
103103
*/
104-
DOWN_RIGHT;
104+
DOWN_RIGHT,
105+
/**
106+
* @since v748
107+
*/
108+
START_USING_ITEM,
109+
/**
110+
* @since v748
111+
*/
112+
IS_CAMERA_RELATIVE_MOVEMENT_ENABLED,
113+
/**
114+
* @since v748
115+
*/
116+
IS_ROT_CONTROLLED_BY_MOVE_DIRECTION,
117+
/**
118+
* @since v748
119+
*/
120+
START_SPIN_ATTACK,
121+
/**
122+
* @since v748
123+
*/
124+
STOP_SPIN_ATTACK;
105125

106126
private static final AuthInputAction[] VALUES = values();
107127

src/main/java/cn/nukkit/resourcepacks/ResourcePack.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,24 @@ public interface ResourcePack {
2222
default String getEncryptionKey() {
2323
return "";
2424
}
25+
26+
default String getSubPackName() {
27+
return "";
28+
}
29+
30+
default boolean usesScripting() {
31+
return false;
32+
}
33+
34+
default boolean isAddonPack() {
35+
return false;
36+
}
37+
38+
default boolean isRaytracingCapable() {
39+
return false;
40+
}
41+
42+
default String getCDNUrl() {
43+
return "";
44+
}
2545
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import cn.nukkit.level.GlobalBlockPalette;
1212
import cn.nukkit.math.BlockFace;
1313
import cn.nukkit.math.BlockVector3;
14+
import cn.nukkit.math.Vector2f;
1415
import cn.nukkit.math.Vector3f;
1516
import cn.nukkit.nbt.NBTIO;
1617
import cn.nukkit.nbt.tag.CompoundTag;
@@ -725,7 +726,7 @@ public void putBlockVector3(int x, int y, int z) {
725726
}
726727

727728
public Vector3f getVector3f() {
728-
return new Vector3f(this.getLFloat(4), this.getLFloat(4), this.getLFloat(4));
729+
return new Vector3f(this.getLFloat(), this.getLFloat(), this.getLFloat());
729730
}
730731

731732
public void putVector3f(Vector3f v) {
@@ -738,6 +739,10 @@ public void putVector3f(float x, float y, float z) {
738739
this.putLFloat(z);
739740
}
740741

742+
public Vector2f getVector2f() {
743+
return new Vector2f(this.getLFloat(), this.getLFloat());
744+
}
745+
741746
public void putGameRules(GameRules gameRules) {
742747
Map<GameRule, GameRules.Value> rules = gameRules.getGameRules();
743748
this.putUnsignedVarInt(rules.size());

0 commit comments

Comments
 (0)