Skip to content

Commit

Permalink
feat: correct random tick speed to match vanilla and improve the perf…
Browse files Browse the repository at this point in the history
…ormance
  • Loading branch information
smartcmd committed Dec 17, 2024
1 parent d54f9a5 commit 34e15fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.allaymc.server.datastruct.palette;

import com.google.common.base.Objects;
import com.google.common.base.Predicate;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufOutputStream;
import it.unimi.dsi.fastutil.objects.ReferenceArrayList;
Expand Down Expand Up @@ -207,6 +208,15 @@ public boolean oneEntryOnly() {
return true;
}

public boolean allEntriesMatch(Predicate<V> predicate) {
for (var entry : palette) {
if (!predicate.test(entry)) {
return false;
}
}
return true;
}

public void copyTo(Palette<V> palette) {
palette.bitArray = this.bitArray.copy();
palette.palette.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,15 @@ protected void tickRandomUpdates(Dimension dimension) {
if (section.isAirSection()) {
continue;
}
// Check the entry list of this section, and
// if there is no block that support random tick
// in this section, we can just skip this section
if (section.blockLayers()[0].allEntriesMatch(blockState -> !blockState.getBehavior().canRandomUpdate())) {
continue;
}

int sectionY = section.sectionY();
for (int i = 0; i < randomTickSpeed; i++) {
for (int i = 0; i < randomTickSpeed * 3; i++) {
int lcg = nextUpdateLCG();
int localX = lcg & 0x0f;
int localZ = lcg >>> 8 & 0x0f;
Expand Down

0 comments on commit 34e15fa

Please sign in to comment.