Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/level/GameRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
42 changes: 24 additions & 18 deletions src/main/java/cn/nukkit/level/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down