Skip to content

Commit

Permalink
Merge branch 'master' into 1.20.60
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/cn/nukkit/level/Level.java
#	src/main/java/cn/nukkit/level/format/generic/ChunkPacketCache.java
#	src/main/java/cn/nukkit/level/format/generic/ChunkRequestTask.java
#	src/main/java/cn/nukkit/level/generator/object/ObjectTallGrass.java
#	src/main/java/cn/nukkit/level/generator/object/tree/NewJungleTree.java
#	src/main/java/cn/nukkit/level/generator/object/tree/ObjectSavannaTree.java
#	src/main/java/cn/nukkit/level/generator/object/tree/ObjectSwampTree.java
#	src/main/java/cn/nukkit/level/generator/populator/impl/MushroomPopulator.java
#	src/main/java/cn/nukkit/level/generator/populator/impl/PopulatorTree.java
#	src/main/java/cn/nukkit/level/generator/populator/impl/tree/DarkOakTreePopulator.java
#	src/main/java/cn/nukkit/level/generator/populator/impl/tree/JungleBigTreePopulator.java
#	src/main/java/cn/nukkit/level/generator/populator/impl/tree/JungleFloorPopulator.java
#	src/main/java/cn/nukkit/level/generator/populator/impl/tree/JungleTreePopulator.java
#	src/main/java/cn/nukkit/level/generator/populator/impl/tree/SavannaTreePopulator.java
#	src/main/java/cn/nukkit/level/generator/populator/impl/tree/SpruceBigTreePopulator.java
#	src/main/java/cn/nukkit/level/generator/populator/impl/tree/SpruceMegaTreePopulator.java
#	src/main/java/cn/nukkit/level/generator/populator/impl/tree/SwampTreePopulator.java
  • Loading branch information
wode490390 committed Feb 15, 2024
2 parents c3a9e94 + 8193d8f commit 1fc770f
Show file tree
Hide file tree
Showing 169 changed files with 2,844 additions and 2,390 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<junit.jupiter.version>5.10.1</junit.jupiter.version>
<log4j2.version>2.22.1</log4j2.version>
<jackson.version>2.16.1</jackson.version>
<jline.version>3.25.0</jline.version>
<jline.version>3.25.1</jline.version>
<!-- 本地测试服务端插件目录 -->
<dir.api>../../_api</dir.api>
<dir.server>../../_server</dir.server>
Expand Down Expand Up @@ -331,7 +331,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.3</version>
<version>3.2.5</version>
</plugin>
<!--
<plugin>
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/cn/nukkit/GameVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.util.Map;
import java.util.Objects;

import static cn.nukkit.SharedConstants.*;

public enum GameVersion {
V1_4_0(261, "1.4.0", "1.4"),
V1_5_0(270, "1.5.0", "1.5"),
Expand Down Expand Up @@ -53,7 +51,7 @@ public enum GameVersion {
V1_20_60(649, "1.20.60"),
;

private static GameVersion FEATURE_VERSION = ENABLE_BLOCK_STATE_PERSISTENCE ? GameVersion.V1_18_0 : GameVersion.V1_12_0;
private static GameVersion FEATURE_VERSION = GameVersion.V1_18_0;

private final int protocol;
private final String name;
Expand Down
80 changes: 15 additions & 65 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,18 @@
import cn.nukkit.level.GlobalBlockPaletteInterface.StaticVersion;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.level.format.generic.BaseFullChunk;
import cn.nukkit.level.format.generic.ChunkBlobCache;
import cn.nukkit.level.format.generic.ChunkPacketCache;
import cn.nukkit.level.format.generic.ChunkCachedData;
import cn.nukkit.level.particle.PunchBlockParticle;
import cn.nukkit.level.util.AroundPlayerChunkComparator;
import cn.nukkit.math.*;
import cn.nukkit.metadata.MetadataValue;
import cn.nukkit.nbt.NBTIO;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.nbt.tag.DoubleTag;
import cn.nukkit.nbt.tag.FloatTag;
import cn.nukkit.nbt.tag.ListTag;
import cn.nukkit.network.Network;
import cn.nukkit.network.PacketViolationReason;
import cn.nukkit.network.SourceInterface;
import cn.nukkit.network.protocol.*;
import cn.nukkit.network.protocol.BatchPacket.Track;
import cn.nukkit.network.protocol.types.ContainerIds;
import cn.nukkit.network.protocol.types.NetworkInventoryAction;
import cn.nukkit.permission.PermissibleBase;
Expand Down Expand Up @@ -926,7 +922,7 @@ public Position getSpawn() {
}
}

public void sendChunk(int x, int z, int subChunkCount, ChunkBlobCache chunkBlobCache, DataPacket packet) {
public void sendChunk(int x, int z, int subChunkCount, ChunkCachedData cachedData, DataPacket packet) {
if (!this.connected) {
return;
}
Expand All @@ -952,7 +948,7 @@ public void sendChunk(int x, int z, int subChunkCount, ChunkBlobCache chunkBlobC
}
}

public void sendChunk(int x, int z, int subChunkCount, ChunkBlobCache chunkBlobCache, byte[] payload, byte[] subModePayload) {
public void sendChunk(int x, int z, int subChunkCount, ChunkCachedData cachedData, byte[] payload, byte[] subModePayload) {
if (!this.connected) {
return;
}
Expand Down Expand Up @@ -1212,15 +1208,13 @@ public boolean dataPacket(DataPacket packet) {
return false;
}

{
DataPacketSendEvent ev = new DataPacketSendEvent(this, packet);
this.server.getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
return false;
}

this.interfaz.putPacket(this, packet, false, true);
DataPacketSendEvent ev = new DataPacketSendEvent(this, packet);
this.server.getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
return false;
}

this.interfaz.putPacket(this, packet, false, true);
return true;
}

Expand Down Expand Up @@ -1845,7 +1839,8 @@ protected void processMovement(int tickDiff) {
}
}

if (!revert && !isSpectator() && this.y >= level.getMinHeight() + 1 && this.y <= level.getMaxHeight() && deltaXZ > Mth.EPSILON) {
HeightRange heightRange = level.getHeightRange();
if (!revert && !isSpectator() && this.y >= heightRange.getMinY() + 1 && this.y < heightRange.getMaxY() && deltaXZ > Mth.EPSILON) {
int frostWalker = inventory.getBoots().getEnchantmentLevel(Enchantment.FROST_WALKER);
if (frostWalker > 0) {
int playerX = getFloorX();
Expand Down Expand Up @@ -5580,40 +5575,6 @@ public boolean isLoaderActive() {
return this.isConnected();
}

/**
* @deprecated Use {@link Level#getChunkCacheFromData}.
*/
@Deprecated
public static BatchPacket getChunkCacheFromData(int chunkX, int chunkZ, byte[] payload) {
return getChunkCacheFromData(chunkX, chunkZ, payload, false);
}

/**
* @deprecated Use {@link Level#getChunkCacheFromData}.
*/
@Deprecated
public static BatchPacket getChunkCacheFromData(int chunkX, int chunkZ, byte[] payload, boolean zlibRaw) {
FullChunkDataPacket pk = new FullChunkDataPacket();
pk.chunkX = chunkX;
pk.chunkZ = chunkZ;
pk.data = payload;
pk.tryEncode();

BatchPacket batch = new BatchPacket();
byte[][] batchPayload = new byte[2][];
byte[] buf = pk.getBuffer();
batchPayload[0] = Binary.writeUnsignedVarInt(buf.length);
batchPayload[1] = buf;
byte[] data = Binary.appendBytes(batchPayload);
try {
batch.payload = zlibRaw ? Network.deflateRaw(data, Server.getInstance().networkCompressionLevel) : Zlib.deflate(data, Server.getInstance().networkCompressionLevel);
} catch (Exception e) {
throw new RuntimeException(e);
}
batch.tracks = new Track[]{new Track(pk.pid(), pk.getCount())};
return batch;
}

private boolean foodEnabled = true;

public boolean isFoodEnabled() {
Expand Down Expand Up @@ -5903,21 +5864,10 @@ public boolean isForceResources() {
*/
public void startFishing(Item fishingRod) {
Vector3 motion = this.getDirectionVector().multiply(2);

CompoundTag nbt = new CompoundTag()
.putList(new ListTag<DoubleTag>("Pos")
.add(new DoubleTag("", x + motion.x * 0.5))
.add(new DoubleTag("", y + this.getEyeHeight() + motion.y * 0.5))
.add(new DoubleTag("", z + motion.z * 0.5)))
.putList(new ListTag<DoubleTag>("Motion")
.add(new DoubleTag("", motion.x))
.add(new DoubleTag("", motion.y))
.add(new DoubleTag("", motion.z)))
.putList(new ListTag<FloatTag>("Rotation")
.add(new FloatTag("", (float) yaw))
.add(new FloatTag("", (float) pitch)));
CompoundTag nbt = Entity.getDefaultNBT(x + motion.x * 0.5, y + this.getEyeHeight() + motion.y * 0.5, z + motion.z * 0.5, motion, (float) yaw, (float) pitch);
EntityFishingHook fishingHook = new EntityFishingHook(getChunk(), nbt, this);
fishingHook.setMotion(motion);

ProjectileLaunchEvent ev = new ProjectileLaunchEvent(fishingHook);
this.getServer().getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
Expand Down Expand Up @@ -6023,14 +5973,14 @@ public boolean isSubChunkRequestAvailable() {
* 发送未缓存在内存的子区块.
* @since 1.18.0
*/
public void sendSubChunks(int dimension, int x, int z, int subChunkCount, ChunkBlobCache blobCache, Map<StaticVersion, byte[][]> payload, byte[] heightMapType, byte[][] heightMap) {
public void sendSubChunks(int dimension, int x, int z, int subChunkCount, ChunkCachedData cachedData, Map<StaticVersion, byte[][]> payload, byte[] heightMapType, byte[][] heightMap) {
}

/**
* 发送缓存在内存的子区块.
* @since 1.18.0
*/
public void sendSubChunks(int dimension, int x, int z, int subChunkCount, ChunkBlobCache blobCache, ChunkPacketCache packetCache, byte[] heightMapType, byte[][] heightMap) {
public void sendSubChunks(int dimension, int x, int z, int subChunkCount, ChunkCachedData cachedData, byte[] heightMapType, byte[][] heightMap) {
}

public void onSubChunkRequestFail(int dimension, int x, int z) {
Expand Down
16 changes: 2 additions & 14 deletions src/main/java/cn/nukkit/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import cn.nukkit.data.ServerConfiguration;
import cn.nukkit.dispenser.DispenseBehaviorRegister;
import cn.nukkit.entity.Entities;
import cn.nukkit.entity.Entity;
import cn.nukkit.entity.attribute.Attribute;
import cn.nukkit.entity.data.Skin;
import cn.nukkit.event.HandlerList;
Expand Down Expand Up @@ -41,8 +42,6 @@
import cn.nukkit.metadata.PlayerMetadataStore;
import cn.nukkit.nbt.NBTIO;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.nbt.tag.DoubleTag;
import cn.nukkit.nbt.tag.FloatTag;
import cn.nukkit.nbt.tag.ListTag;
import cn.nukkit.network.CompressBatchedTask;
import cn.nukkit.network.Network;
Expand Down Expand Up @@ -1606,24 +1605,13 @@ public CompoundTag getOfflinePlayerData(String name) {
}

Position spawn = this.getDefaultLevel().getSafeSpawn();
CompoundTag nbt = new CompoundTag()
CompoundTag nbt = Entity.getDefaultNBT(spawn)
.putLong("firstPlayed", System.currentTimeMillis() / 1000)
.putLong("lastPlayed", System.currentTimeMillis() / 1000)
.putList(new ListTag<DoubleTag>("Pos")
.add(new DoubleTag("0", spawn.x))
.add(new DoubleTag("1", spawn.y))
.add(new DoubleTag("2", spawn.z)))
.putString("Level", this.getDefaultLevel().getName())
.putList(new ListTag<>("Inventory"))
// .putCompound("Achievements", new CompoundTag())
.putInt("playerGameType", this.getGamemode())
.putList(new ListTag<DoubleTag>("Motion")
.add(new DoubleTag("0", 0))
.add(new DoubleTag("1", 0))
.add(new DoubleTag("2", 0)))
.putList(new ListTag<FloatTag>("Rotation")
.add(new FloatTag("0", 0))
.add(new FloatTag("1", 0)))
.putFloat("FallDistance", 0)
.putShort("Fire", 0)
.putShort("Air", 300)
Expand Down
16 changes: 2 additions & 14 deletions src/main/java/cn/nukkit/SharedConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ public final class SharedConstants {
* Use bitwise operations.
*/
public static final boolean DISABLE_SUB_CHUNK_STORAGE_PADDING = true;
public static final boolean ENABLE_SUB_CHUNK_NETWORK_OPTIMIZATION = true;
public static final boolean ENABLE_EMPTY_SUB_CHUNK_NETWORK_OPTIMIZATION = true;

public static final boolean DUMP_NETWORK_SUB_CHUNK = !PRODUCTION_ENVIRONMENT && false;

public static final boolean CHUNK_REQUEST_DEBUG = true;

// storage

Expand All @@ -41,20 +35,14 @@ public final class SharedConstants {

// misc

public static final boolean USE_FUNCTION_EVENT_EXECUTOR = true;

public static final int RESOURCE_PACK_CHUNK_SIZE = 128 * 1024; // 128KB

public static final boolean ENABLE_BLOCK_DESTROY_SPEED_COMPATIBILITY = true;

// deprecated

public static final boolean ENABLE_BLOCK_STATE_PERSISTENCE = true;

public static final boolean ENABLE_ITEM_NAME_PERSISTENCE = true;

// experimental

public static final boolean USE_FUNCTION_EVENT_EXECUTOR = true;

public static final boolean NEXT_UPDATE_NEW_ENTITY_SYSTEM_PREVIEW = !PRODUCTION_ENVIRONMENT && false;

public static final boolean NEXT_UPDATE_EVENT_POOLING_PREVIEW = !PRODUCTION_ENVIRONMENT && false;
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/cn/nukkit/block/BlockBamboo.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ public boolean canBeActivated() {
public boolean onActivate(Item item, BlockFace face, Player player) {
int id = item.getId();
if (id == ItemID.DYE && item.getDamage() == ItemDye.BONE_MEAL) {
int maxHeight = level.getHeightRange().getMaxY();
BlockBamboo top = seekToTop();
int y = top.getFloorY();
if (y >= level.getMaxHeight() || !top.grow(getMaxHeight(getFloorX(), getFloorZ()), y == level.getMaxHeight() - 1 ? 1 : ThreadLocalRandom.current().nextInt(1, 3))) {
if (y >= maxHeight - 1 || !top.grow(getMaxHeight(getFloorX(), getFloorZ()), y == maxHeight - 2 ? 1 : ThreadLocalRandom.current().nextInt(1, 3))) {
return false;
}
//FIXME: unexpected update
Expand All @@ -148,7 +149,7 @@ public boolean onActivate(Item item, BlockFace face, Player player) {

if (id == getItemId()) {
BlockBamboo top = seekToTop();
if (top.getFloorY() >= level.getMaxHeight() || !top.grow(Short.MAX_VALUE, 1)) {
if (top.getFloorY() >= level.getHeightRange().getMaxY() - 1 || !top.grow(Short.MAX_VALUE, 1)) {
return true;
}

Expand All @@ -175,7 +176,7 @@ public int onUpdate(int type) {
level.useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
} else if (type == Level.BLOCK_UPDATE_RANDOM) {
if (getFloorY() == level.getMaxHeight()) {
if (getFloorY() >= level.getHeightRange().getMaxY() - 1) {
return 0;
}

Expand Down
9 changes: 2 additions & 7 deletions src/main/java/cn/nukkit/block/BlockCaveVines.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

import java.util.concurrent.ThreadLocalRandom;

import static cn.nukkit.SharedConstants.*;

public class BlockCaveVines extends BlockFlowable {
public static final int MAX_AGE = 25;

Expand All @@ -35,10 +33,7 @@ public String getName() {

@Override
public Item toItem(boolean addUserData) {
if (ENABLE_ITEM_NAME_PERSISTENCE) {
return Item.get(Item.GLOW_BERRIES);
}
return Item.get(getItemId(CAVE_VINES));
return Item.get(Item.GLOW_BERRIES);
}

@Override
Expand Down Expand Up @@ -109,7 +104,7 @@ public int onUpdate(int type) {
return 0;
}

if (!level.isValidHeight(getFloorY() - 1)) {
if (!level.getHeightRange().isValidBlockY(getFloorY() - 1)) {
return 0;
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/cn/nukkit/block/BlockDoor.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ public int onUpdate(int type) {

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (this.y >= level.getMaxHeight()) return false;
if (this.y >= level.getHeightRange().getMaxY() - 1) {
return false;
}
if (face == BlockFace.UP) {
Block blockUp = this.up();
Block blockDown = this.down();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockDripleafBig.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public boolean onActivate(Item item, BlockFace face, Player player) {
head = up;
}

if (head.getFloorY() + 1 >= level.getMaxHeight()) {
if (head.getFloorY() + 1 >= level.getHeightRange().getMaxY() - 1) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockDripleafSmall.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public boolean onActivate(Item item, BlockFace face, Player player) {

level.addParticle(new BoneMealParticle(this));

int maxHeight = level.getMaxHeight();
int maxHeight = level.getHeightRange().getMaxY() - 1;
int thisX = getFloorX();
int thisY = getFloorY();
int thisZ = getFloorZ();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockGrass.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public boolean onActivate(Item item, BlockFace face, Player player) {
item.count--;
}
this.level.addParticle(new BoneMealParticle(this));
ObjectTallGrass.growGrass(this.getLevel(), this, NukkitRandom.current());
ObjectTallGrass.growGrass(this.getLevel(), this.asBlockVector3(), NukkitRandom.current());
return true;
} else if (item.isHoe()) {
if (player != null && !player.isCreative()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockKelp.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private boolean grow() {
return false;
}

if (y >= level.getMaxHeight()) {
if (y >= level.getHeightRange().getMaxY() - 1) {
return false;
}

Expand Down
Loading

0 comments on commit 1fc770f

Please sign in to comment.