Skip to content

Commit

Permalink
1.20.60 (#2168)
Browse files Browse the repository at this point in the history
  • Loading branch information
PetteriM1 committed Feb 6, 2024
1 parent b02b73f commit 05f93b1
Show file tree
Hide file tree
Showing 17 changed files with 42,293 additions and 43,817 deletions.
36 changes: 16 additions & 20 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -2122,11 +2122,6 @@ public void handleDataPacket(DataPacket packet) {
return;
}

if (pid == ProtocolInfo.BATCH_PACKET) {
this.server.getNetwork().processBatch((BatchPacket) packet, this);
return;
}

if (log.isTraceEnabled() && !server.isIgnoredPacket(packet.getClass())) {
log.trace("Inbound {}: {}", this.getName(), packet);
}
Expand Down Expand Up @@ -2452,13 +2447,24 @@ public void onCompletion(Server server) {
}

if (this.teleportPosition != null) {
break;
return;
}

// Proper player.isPassenger() check may be needed
if (this.riding instanceof EntityMinecartAbstract) {
((EntityMinecartAbstract) riding).setCurrentSpeed(authPacket.getMotion().getY());
break;
double inputY = authPacket.getMotion().getY();
if (inputY >= -1.001 && inputY <= 1.001) {
((EntityMinecartAbstract) riding).setCurrentSpeed(inputY);
}
} else if (this.riding instanceof EntityBoat && authPacket.getInputData().contains(AuthInputAction.IN_CLIENT_PREDICTED_IN_VEHICLE)) {
if (this.riding.getId() == authPacket.getPredictedVehicle() && this.riding.isControlling(this)) {
if (this.temporalVector.setComponents(authPacket.getPosition().getX(), authPacket.getPosition().getY(), authPacket.getPosition().getZ()).distanceSquared(this.riding) < 100) {
((EntityBoat) this.riding).onInput(authPacket.getPosition().getX(), authPacket.getPosition().getY(), authPacket.getPosition().getZ(), authPacket.getHeadYaw());
}
}
}

if (!this.isSpectator() && authPacket.getInputData().contains(AuthInputAction.MISSED_SWING)) {
level.addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_ATTACK_NODAMAGE, -1, "minecraft:player", false, false);
}

if (authPacket.getInputData().contains(AuthInputAction.START_SPRINTING)) {
Expand Down Expand Up @@ -2609,17 +2615,6 @@ public void onCompletion(Server server) {
this.forceMovement = null;
}
break;
case ProtocolInfo.MOVE_ENTITY_ABSOLUTE_PACKET:
MoveEntityAbsolutePacket moveEntityAbsolutePacket = (MoveEntityAbsolutePacket) packet;
if (this.riding == null || this.riding.getId() != moveEntityAbsolutePacket.eid || !this.riding.isControlling(this)) {
break;
}
if (this.riding instanceof EntityBoat) {
if (this.temporalVector.setComponents(moveEntityAbsolutePacket.x, moveEntityAbsolutePacket.y, moveEntityAbsolutePacket.z).distanceSquared(this.riding) < 1000) {
((EntityBoat) this.riding).onInput(moveEntityAbsolutePacket.x, moveEntityAbsolutePacket.y, moveEntityAbsolutePacket.z, moveEntityAbsolutePacket.headYaw);
}
}
break;
case ProtocolInfo.MOB_EQUIPMENT_PACKET:
if (!this.spawned || !this.isAlive()) {
break;
Expand Down Expand Up @@ -5452,6 +5447,7 @@ public void startFishing(Item fishingRod) {
fishingHook.rod = fishingRod;
fishingHook.checkLure();
fishingHook.spawnToAll();
this.level.addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_THROW, -1, "minecraft:player", false, false);
}
}

Expand Down
23 changes: 10 additions & 13 deletions src/main/java/cn/nukkit/inventory/CraftingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public CraftingManager() {
}
this.rebuildPacket();

MainLogger.getLogger().info("Loaded " + this.recipes.size() + " recipes.");
MainLogger.getLogger().info("Loaded " + this.recipes.size() + " recipes");
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -99,12 +99,9 @@ private void loadRecipes(Config config) {
// Bake sorted list
sorted.sort(recipeComparator);

String recipeId = (String) recipe.get("id");
int priority = Utils.toInt(recipe.get("priority"));

ShapelessRecipe result = new ShapelessRecipe(recipeId, priority, Item.fromJson(first), sorted);

this.registerRecipe(result);
Item resultItem = Item.fromJson(first, true);
if (resultItem == null) continue; // TODO: remove when new blocks are supported
this.registerRecipe(new ShapelessRecipe(null, Utils.toInt(recipe.get("priority")), resultItem, sorted)); // null recipeId will be replaced with recipe uuid
break;
case 1:
craftingBlock = (String) recipe.get("block");
Expand Down Expand Up @@ -137,10 +134,9 @@ private void loadRecipes(Config config) {
extraResults.add(Item.fromJson(data));
}

recipeId = (String) recipe.get("id");
priority = Utils.toInt(recipe.get("priority"));

this.registerRecipe(new ShapedRecipe(recipeId, priority, Item.fromJson(first), shape, ingredients, extraResults));
resultItem = Item.fromJson(first, true);
if (resultItem == null) continue; // TODO: remove when new blocks are supported
this.registerRecipe(new ShapedRecipe(null, Utils.toInt(recipe.get("priority")), resultItem, shape, ingredients, extraResults));
break;
case 2:
case 3:
Expand All @@ -150,7 +146,8 @@ private void loadRecipes(Config config) {
continue;
}
Map<String, Object> resultMap = (Map) recipe.get("output");
Item resultItem = Item.fromJson(resultMap);
resultItem = Item.fromJson(resultMap, true);
if (resultItem == null) continue; // TODO: remove when new blocks are supported
Item inputItem;
try {
Map<String, Object> inputMap = (Map) recipe.get("input");
Expand Down Expand Up @@ -216,7 +213,7 @@ private void createLegacyPlanksRecipe(Map<String, Object> recipe, Map<String, Ob
ingredients.put(ingredientChar, ingredient);
}
this.registerRecipe(
new ShapedRecipe(recipe.get("id") + "_" + planksMeta, Utils.toInt(recipe.get("priority")), Item.fromJson(first), shape, ingredients, extraResults));
new ShapedRecipe(null, Utils.toInt(recipe.get("priority")), Item.fromJson(first), shape, ingredients, extraResults));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/item/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public static Item fromJson(Map<String, Object> data) {
return fromJson(data, false);
}

private static Item fromJson(Map<String, Object> data, boolean ignoreUnsupported) {
public static Item fromJson(Map<String, Object> data, boolean ignoreUnsupported) {
String nbt = (String) data.get("nbt_b64");
byte[] nbtBytes;
if (nbt != null) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/cn/nukkit/item/ItemID.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ public interface ItemID {
int APPLEENCHANTED = 466;
int HEART_OF_THE_SEA = 467;
int SCUTE = 468;
int TURTLE_SCUTE = 468;
int TURTLE_SHELL = 469;
int TURTLE_HELMET = 469;
int PHANTOM_MEMBRANE = 470;
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/cn/nukkit/network/CompressionProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public byte[] compress(BinaryStream packet, int level) throws Exception {
public byte[] decompress(byte[] compressed) throws Exception {
return compressed;
}

@Override
public byte getPrefix() {
return (byte) 0xff;
}
};

CompressionProvider ZLIB = new CompressionProvider() {
Expand All @@ -27,6 +32,11 @@ public byte[] compress(BinaryStream packet, int level) throws Exception {
public byte[] decompress(byte[] compressed) throws Exception {
return Network.inflateRaw(compressed);
}

@Override
public byte getPrefix() {
return (byte) 0x00;
}
};


Expand All @@ -41,4 +51,18 @@ static CompressionProvider from(PacketCompressionAlgorithm algorithm) {
}
throw new UnsupportedOperationException();
}

default byte getPrefix() {
throw new UnsupportedOperationException();
}

static CompressionProvider byPrefix(byte prefix) {
switch (prefix) {
case 0x00:
return ZLIB;
case (byte) 0xff:
return NONE;
}
throw new IllegalArgumentException("Unsupported compression type: " + prefix);
}
}
26 changes: 1 addition & 25 deletions src/main/java/cn/nukkit/network/Network.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cn.nukkit.network;

import cn.nukkit.Nukkit;
import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.nbt.stream.FastByteArrayOutputStream;
import cn.nukkit.network.protocol.*;
Expand All @@ -12,7 +11,6 @@
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import lombok.extern.log4j.Log4j2;

import java.io.ByteArrayInputStream;
Expand All @@ -22,7 +20,6 @@
import java.net.ProtocolException;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
Expand Down Expand Up @@ -222,17 +219,7 @@ public Server getServer() {
return server;
}

public void processBatch(BatchPacket packet, Player player) {
List<DataPacket> packets = new ObjectArrayList<>();
try {
this.processBatch(packet.payload, packets, player.getNetworkSession().getCompression());
} catch (ProtocolException e) {
player.close("", e.getMessage());
log.error("Unable to process player packets ", e);
}
}

public void processBatch(byte[] payload, Collection<DataPacket> packets, CompressionProvider compression) throws ProtocolException {
public void processBatch(byte[] payload, Collection<DataPacket> packets, CompressionProvider compression) {
byte[] data;
try {
data = compression.decompress(payload);
Expand Down Expand Up @@ -284,17 +271,6 @@ public void processBatch(byte[] payload, Collection<DataPacket> packets, Compres
}
}

/**
* Process packets obtained from batch packets
* Required to perform additional analyses and filter unnecessary packets
*
* @param packets
*/
public void processPackets(Player player, List<DataPacket> packets) {
if (packets.isEmpty()) return;
packets.forEach(player::handleDataPacket);
}

public DataPacket getPacket(int id) {
Class<? extends DataPacket> clazz = this.packetPool[id];
if (clazz != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public byte pid() {

public int chunkX;
public int chunkZ;
public int dimension;
public int subChunkCount;
public boolean cacheEnabled;
public boolean requestSubChunks;
Expand All @@ -34,6 +35,7 @@ public void encode() {
this.reset();
this.putVarInt(this.chunkX);
this.putVarInt(this.chunkZ);
this.putVarInt(this.dimension);
if (!this.requestSubChunks) {
this.putUnsignedVarInt(this.subChunkCount);
} else if (this.subChunkLimit < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class PlayerAuthInputPacket extends DataPacket {
// private ItemStackRequest itemStackRequest;
private Map<PlayerActionType, PlayerBlockActionData> blockActionData = new EnumMap<>(PlayerActionType.class);
private Vector2 analogMoveVector;
private long predictedVehicle;

@Override
public byte pid() {
Expand Down Expand Up @@ -86,6 +87,10 @@ public void decode() {
}
}

if (this.inputData.contains(AuthInputAction.IN_CLIENT_PREDICTED_IN_VEHICLE)) {
this.predictedVehicle = this.getVarLong();
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void encode() {
this.putSkin(entry.skin);
this.putBoolean(entry.isTeacher);
this.putBoolean(entry.isHost);
this.putBoolean(entry.isSubClient);
}
}

Expand Down Expand Up @@ -67,6 +68,7 @@ public static class Entry {
public Skin skin;
public boolean isTeacher;
public boolean isHost;
public boolean isSubClient;

public Entry(UUID uuid) {
this.uuid = uuid;
Expand Down
4 changes: 2 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("630"); // DO NOT REMOVE BOXING
int CURRENT_PROTOCOL = Integer.valueOf("649"); // DO NOT REMOVE BOXING

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

String MINECRAFT_VERSION_NETWORK = "1.20.50";
String MINECRAFT_VERSION_NETWORK = "1.20.60";
String MINECRAFT_VERSION = 'v' + MINECRAFT_VERSION_NETWORK;

byte BATCH_PACKET = (byte) 0xff;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,15 @@ public enum AuthInputAction {
/**
* @since v618
*/
STOP_FLYING;
STOP_FLYING,
/**
* @since v622
*/
RECEIVED_SERVER_DATA,
/**
* @since v649
*/
IN_CLIENT_PREDICTED_IN_VEHICLE;

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

Expand Down
Loading

1 comment on commit 05f93b1

@waternoob1005
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gud

Please sign in to comment.