Skip to content

Commit

Permalink
Backport 1.21.40 support to master (#2201)
Browse files Browse the repository at this point in the history
  • Loading branch information
PetteriM1 authored Oct 23, 2024
1 parent fb217e1 commit 2172e54
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 48 deletions.
5 changes: 5 additions & 0 deletions src/main/java/cn/nukkit/level/GlobalBlockPalette.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ private static boolean registerBlockState(CompoundTag state, boolean force) {
int runtimeId = state.getInt("runtimeId");
boolean stateOverload = state.getBoolean("stateOverload");

// DO NOT MERGE!
if (meta > 15) { // Not supported here
return true; // Not an overload
}

if (stateOverload && !force) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public byte pid() {
public static final int SPECIAL_HOTBAR = 0x7a;
public static final int SPECIAL_FIXED_INVENTORY = 0x7b;

private static final Item EMPTY_STORAGE_ITEM = Item.get(Item.AIR);

public int inventoryId;
public Item[] slots = new Item[0];

Expand All @@ -47,7 +49,7 @@ public void encode() {
}
this.putByte((byte) 0); // fullContainerName.id
this.putBoolean(false); // fullContainerName.optional.present
this.putUnsignedVarInt(0); // dynamicContainerSize
this.putSlot(EMPTY_STORAGE_ITEM);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public byte pid() {
public int slot;
public Item item;

private static final Item EMPTY_STORAGE_ITEM = Item.get(Item.AIR);

@Override
public void decode() {
}
Expand All @@ -32,7 +34,7 @@ public void encode() {
this.putUnsignedVarInt(this.slot);
this.putByte((byte) 0); // fullContainerName.id
this.putBoolean(false); // fullContainerName.optional.present
this.putUnsignedVarInt(0); // dynamicContainerSize
this.putSlot(EMPTY_STORAGE_ITEM);
this.putSlot(this.item);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public void encode() {
this.putVarInt(this.amplifier);
this.putBoolean(this.particles);
this.putVarInt(this.duration);
this.putLLong(this.tick);
this.putUnsignedVarLong(this.tick);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ public class PlayerAuthInputPacket extends DataPacket {
private float headYaw;
private Vector3f position;
private Vector2 motion;
private Set<AuthInputAction> inputData = EnumSet.noneOf(AuthInputAction.class);
private final Set<AuthInputAction> inputData = EnumSet.noneOf(AuthInputAction.class);
private InputMode inputMode;
private ClientPlayMode playMode;
private AuthInteractionModel interactionModel;
private Vector3f vrGazeDirection;
private long tick;
private Vector3f delta;
// private ItemStackRequest itemStackRequest;
private Map<PlayerActionType, PlayerBlockActionData> blockActionData = new EnumMap<>(PlayerActionType.class);
private Vector2 analogMoveVector;
private final Map<PlayerActionType, PlayerBlockActionData> blockActionData = new EnumMap<>(PlayerActionType.class);
private long predictedVehicle;
private Vector2f analogMoveVector;
private Vector2f vehicleRotation;
private Vector2f interactRotation;
private Vector3f cameraOrientation;

@Override
public byte pid() {
Expand All @@ -59,18 +59,11 @@ public void decode() {
this.playMode = ClientPlayMode.fromOrdinal((int) this.getUnsignedVarInt());
this.interactionModel = AuthInteractionModel.fromOrdinal((int) this.getUnsignedVarInt());

if (this.playMode == ClientPlayMode.REALITY) {
this.vrGazeDirection = this.getVector3f();
}
this.interactRotation = this.getVector2f();

this.tick = this.getUnsignedVarLong();
this.delta = this.getVector3f();

if (this.inputData.contains(AuthInputAction.PERFORM_ITEM_STACK_REQUEST)) {
// TODO: this.itemStackRequest = readItemStackRequest(buf, protocolVersion);
// We are safe to leave this for later, since it is only sent with ServerAuthInventories
}

if (this.inputData.contains(AuthInputAction.PERFORM_BLOCK_ACTIONS)) {
int arraySize = this.getVarInt();
if (arraySize > 256) throw new IllegalArgumentException("PlayerAuthInputPacket PERFORM_BLOCK_ACTIONS is too long: " + arraySize);
Expand All @@ -91,11 +84,12 @@ public void decode() {
}

if (this.inputData.contains(AuthInputAction.IN_CLIENT_PREDICTED_IN_VEHICLE)) {
this.vehicleRotation = new Vector2f(this.getLFloat(), this.getLFloat());
this.vehicleRotation = this.getVector2f();
this.predictedVehicle = this.getVarLong();
}

this.analogMoveVector = new Vector2(this.getLFloat(), this.getLFloat());
this.analogMoveVector = this.getVector2f();
this.cameraOrientation = this.getVector3f();
}

@Override
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/cn/nukkit/network/protocol/ProtocolInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public interface ProtocolInfo {
* Actual Minecraft: PE protocol version
*/
@SuppressWarnings("UnnecessaryBoxing")
int CURRENT_PROTOCOL = Integer.valueOf("729"); // DO NOT REMOVE BOXING
int CURRENT_PROTOCOL = Integer.valueOf("748"); // DO NOT REMOVE BOXING

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

String MINECRAFT_VERSION_NETWORK = "1.21.30";
String MINECRAFT_VERSION_NETWORK = "1.21.40";
String MINECRAFT_VERSION = 'v' + MINECRAFT_VERSION_NETWORK;

byte BATCH_PACKET = (byte) 0xff;
Expand Down Expand Up @@ -237,4 +237,6 @@ public interface ProtocolInfo {
byte __INTERNAL__SERVERBOUND_DIAGNOSTICS_PACKET = (byte) 215;
byte __INTERNAL__CAMERA_AIM_ASSIST_PACKET = (byte) 216;
byte __INTERNAL__CONTAINER_REGISTRY_CLEANUP_PACKET = (byte) 217;
byte __INTERNAL__MOVEMENT_EFFECT_PACKET = (byte) 218;
byte __INTERNAL__SET_MOVEMENT_AUTHORITY_PACKET = (byte) 219;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package cn.nukkit.network.protocol;

import cn.nukkit.resourcepacks.ResourcePack;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import lombok.ToString;
import lombok.Value;

import java.util.List;

@ToString
public class ResourcePacksInfoPacket extends DataPacket {
Expand All @@ -14,12 +10,9 @@ public class ResourcePacksInfoPacket extends DataPacket {

public boolean mustAccept;
public boolean scripting;
@Deprecated
public boolean forceServerPacks; // pre 1.21.30
public boolean hasAddonPacks;
public ResourcePack[] behaviourPackEntries = ResourcePack.EMPTY_ARRAY;
public ResourcePack[] resourcePackEntries = ResourcePack.EMPTY_ARRAY;
public List<CDNEntry> CDNEntries = new ObjectArrayList<>();

@Override
public void decode() {
Expand All @@ -34,12 +27,6 @@ public void encode() {
this.putBoolean(this.scripting);

this.encodeResourcePacks(this.resourcePackEntries);

this.putUnsignedVarInt(this.CDNEntries.size());
this.CDNEntries.forEach((entry) -> {
this.putString(entry.getPackId());
this.putString(entry.getRemoteUrl());
});
}

private void encodeResourcePacks(ResourcePack[] packs) {
Expand All @@ -49,22 +36,17 @@ private void encodeResourcePacks(ResourcePack[] packs) {
this.putString(entry.getPackVersion());
this.putLLong(entry.getPackSize());
this.putString(entry.getEncryptionKey());
this.putString(""); // sub-pack name
this.putString(entry.getSubPackName());
this.putString(!entry.getEncryptionKey().isEmpty() ? entry.getPackId().toString() : "");
this.putBoolean(false); // scripting
this.putBoolean(false); // isAddonPack
this.putBoolean(false); // raytracing capable
this.putBoolean(entry.usesScripting());
this.putBoolean(entry.isAddonPack());
this.putBoolean(entry.isRaytracingCapable());
this.putString(entry.getCDNUrl());
}
}

@Override
public byte pid() {
return NETWORK_ID;
}

@Value
public static class CDNEntry {
String packId;
String remoteUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,27 @@ public enum AuthInputAction {
/**
* @since v729
*/
DOWN_RIGHT;
DOWN_RIGHT,
/**
* @since v748
*/
START_USING_ITEM,
/**
* @since v748
*/
IS_CAMERA_RELATIVE_MOVEMENT_ENABLED,
/**
* @since v748
*/
IS_ROT_CONTROLLED_BY_MOVE_DIRECTION,
/**
* @since v748
*/
START_SPIN_ATTACK,
/**
* @since v748
*/
STOP_SPIN_ATTACK;

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

Expand Down
20 changes: 20 additions & 0 deletions src/main/java/cn/nukkit/resourcepacks/ResourcePack.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,24 @@ public interface ResourcePack {
default String getEncryptionKey() {
return "";
}

default String getSubPackName() {
return "";
}

default boolean usesScripting() {
return false;
}

default boolean isAddonPack() {
return false;
}

default boolean isRaytracingCapable() {
return false;
}

default String getCDNUrl() {
return "";
}
}
7 changes: 6 additions & 1 deletion src/main/java/cn/nukkit/utils/BinaryStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import cn.nukkit.level.GlobalBlockPalette;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.BlockVector3;
import cn.nukkit.math.Vector2f;
import cn.nukkit.math.Vector3f;
import cn.nukkit.nbt.NBTIO;
import cn.nukkit.nbt.tag.CompoundTag;
Expand Down Expand Up @@ -725,7 +726,7 @@ public void putBlockVector3(int x, int y, int z) {
}

public Vector3f getVector3f() {
return new Vector3f(this.getLFloat(4), this.getLFloat(4), this.getLFloat(4));
return new Vector3f(this.getLFloat(), this.getLFloat(), this.getLFloat());
}

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

public Vector2f getVector2f() {
return new Vector2f(this.getLFloat(), this.getLFloat());
}

public void putGameRules(GameRules gameRules) {
Map<GameRule, GameRules.Value> rules = gameRules.getGameRules();
this.putUnsignedVarInt(rules.size());
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/creative_items.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/resources/item_mappings.json

Large diffs are not rendered by default.

Binary file modified src/main/resources/runtime_block_states.dat
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/resources/runtime_item_states.json

Large diffs are not rendered by default.

0 comments on commit 2172e54

Please sign in to comment.