From ea9330ef1e03a64f20fb2b8cf0f44204228b663c Mon Sep 17 00:00:00 2001 From: Wodor <17339354+wode490390@users.noreply.github.com> Date: Fri, 24 Jul 2020 11:34:05 +0800 Subject: [PATCH 1/2] RandomTickSpeed is 1 by default --- src/main/java/cn/nukkit/level/GameRules.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/cn/nukkit/level/GameRules.java b/src/main/java/cn/nukkit/level/GameRules.java index cfce2146dfb..039e27a27a9 100644 --- a/src/main/java/cn/nukkit/level/GameRules.java +++ b/src/main/java/cn/nukkit/level/GameRules.java @@ -40,7 +40,7 @@ public static GameRules getDefault() { gameRules.gameRules.put(MOB_GRIEFING, new Value<>(Type.BOOLEAN, true)); gameRules.gameRules.put(NATURAL_REGENERATION, new Value<>(Type.BOOLEAN, true)); gameRules.gameRules.put(PVP, new Value<>(Type.BOOLEAN, true)); - gameRules.gameRules.put(RANDOM_TICK_SPEED, new Value<>(Type.INTEGER, 3)); + gameRules.gameRules.put(RANDOM_TICK_SPEED, new Value<>(Type.INTEGER, 1)); gameRules.gameRules.put(SEND_COMMAND_FEEDBACK, new Value<>(Type.BOOLEAN, true)); gameRules.gameRules.put(SHOW_COORDINATES, new Value<>(Type.BOOLEAN, false)); gameRules.gameRules.put(TNT_EXPLODES, new Value<>(Type.BOOLEAN, true)); From 9c2772cfc3d00033e5cedd8db643a5a5aebaffdd Mon Sep 17 00:00:00 2001 From: Woder <17339354+wode490390@users.noreply.github.com> Date: Sat, 12 Mar 2022 23:24:10 +0800 Subject: [PATCH 2/2] Changed random tick speed to match vanilla --- src/main/java/cn/nukkit/level/Level.java | 42 ++++++++++++++---------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/main/java/cn/nukkit/level/Level.java b/src/main/java/cn/nukkit/level/Level.java index 1047fb2f137..1d96cf2819b 100644 --- a/src/main/java/cn/nukkit/level/Level.java +++ b/src/main/java/cn/nukkit/level/Level.java @@ -1133,28 +1133,34 @@ private void tickChunks() { if (tickSpeed > 0) { if (this.useSections) { - for (ChunkSection section : ((Chunk) chunk).getSections()) { - if (!(section instanceof EmptyChunkSection)) { - int Y = section.getY(); - for (int i = 0; i < tickSpeed; ++i) { - int lcg = this.getUpdateLCG(); - int x = lcg & 0x0f; - int y = lcg >>> 8 & 0x0f; - int z = lcg >>> 16 & 0x0f; - - int fullId = section.getFullBlock(x, y, z); - int blockId = fullId >> 4; - if (randomTickBlocks[blockId]) { - Block block = Block.get(fullId, this, chunkX * 16 + x, (Y << 4) + y, chunkZ * 16 + z); - block.onUpdate(BLOCK_UPDATE_RANDOM); - } - } + int highestNonAirSectionIndex = -1; + ChunkSection[] sections = ((Chunk) chunk).getSections(); + for (int i = sections.length - 1; i >= 0; i--) { + if (!sections[i].isEmpty()) { + highestNonAirSectionIndex = i; + break; + } + } + int tickCount = (int) ((highestNonAirSectionIndex + 1) * 2.5f) * tickSpeed; + int maxHeight = (highestNonAirSectionIndex + 1) << 4; + for (int i = 0; i < tickCount; i++) { + int lcg = this.getUpdateLCG(); + int x = lcg & 0x0f; + int y = (lcg >>> 8 & 0xff) % maxHeight; + int z = lcg >>> 16 & 0x0f; + + int fullId = chunk.getFullBlock(x, y, z); + int blockId = fullId >> 4; + if (randomTickBlocks[blockId]) { + Block block = Block.get(fullId, this, (chunkX << 4) + x, y, (chunkZ << 4) + z); + block.onUpdate(BLOCK_UPDATE_RANDOM); } } } else { + float tickCount = tickSpeed * 2.5f; for (int Y = 0; Y < 8 && (Y < 3 || blockTest != 0); ++Y) { blockTest = 0; - for (int i = 0; i < tickSpeed; ++i) { + for (int i = 0; i < tickCount; ++i) { int lcg = this.getUpdateLCG(); int x = lcg & 0x0f; int y = lcg >>> 8 & 0x0f; @@ -1164,7 +1170,7 @@ private void tickChunks() { int blockId = fullId >> 4; blockTest |= fullId; if (Level.randomTickBlocks[blockId]) { - Block block = Block.get(fullId, this, x, y + (Y << 4), z); + Block block = Block.get(fullId, this, (chunkX << 4) + x, y + (Y << 4), (chunkZ << 4) + z); block.onUpdate(BLOCK_UPDATE_RANDOM); } }