Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-24 23:30:10 +01:00
60 Zeilen
3.6 KiB
Diff
60 Zeilen
3.6 KiB
Diff
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||
|
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
||
|
Date: Thu, 16 Apr 2020 16:13:59 -0700
|
||
|
Subject: [PATCH] Optimize ChunkProviderServer's chunk level checking helper
|
||
|
methods
|
||
|
|
||
|
These can be hot functions (i.e entity ticking and block ticking),
|
||
|
so inline where possible, and avoid the abstraction of the
|
||
|
Either class.
|
||
|
|
||
|
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||
|
index 3744cce8611ac01b1b6c76cd3c4890795c1f06a2..531fe1259a1d60ff69321c3fefbf97f7141e6475 100644
|
||
|
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||
|
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||
|
@@ -24,7 +24,6 @@ import net.minecraft.network.protocol.Packet;
|
||
|
import net.minecraft.server.MCUtil;
|
||
|
import net.minecraft.server.MinecraftServer;
|
||
|
import net.minecraft.server.level.progress.ChunkProgressListener;
|
||
|
-import net.minecraft.util.Mth;
|
||
|
import net.minecraft.util.profiling.ProfilerFiller;
|
||
|
import net.minecraft.util.thread.BlockableEventLoop;
|
||
|
import net.minecraft.world.entity.Entity;
|
||
|
@@ -644,21 +643,29 @@ public class ServerChunkCache extends ChunkSource {
|
||
|
|
||
|
public final boolean isInEntityTickingChunk(Entity entity) { return this.isEntityTickingChunk(entity); } // Paper - OBFHELPER
|
||
|
@Override public boolean isEntityTickingChunk(Entity entity) {
|
||
|
- long i = ChunkPos.asLong(Mth.floor(entity.getX()) >> 4, Mth.floor(entity.getZ()) >> 4);
|
||
|
-
|
||
|
- return this.checkChunkFuture(i, (Function<ChunkHolder, CompletableFuture<Either<LevelChunk, ChunkHolder.ChunkLoadingFailure>>>) ChunkHolder::getEntityTickingChunkFuture); // CraftBukkit - decompile error
|
||
|
+ // Paper start - optimize is ticking ready type functions
|
||
|
+ // entity ticking
|
||
|
+ ChunkHolder playerChunk = this.getVisibleChunkIfPresent(MCUtil.getCoordinateKey(entity));
|
||
|
+ return playerChunk != null && playerChunk.isEntityTickingReady();
|
||
|
+ // Paper end - optimize is ticking ready type functions
|
||
|
}
|
||
|
|
||
|
public final boolean isEntityTickingChunk(ChunkPos chunkcoordintpair) { return this.isEntityTickingChunk(chunkcoordintpair); } // Paper - OBFHELPER
|
||
|
@Override public boolean isEntityTickingChunk(ChunkPos pos) {
|
||
|
- return this.checkChunkFuture(pos.toLong(), (Function<ChunkHolder, CompletableFuture<Either<LevelChunk, ChunkHolder.ChunkLoadingFailure>>>) ChunkHolder::getEntityTickingChunkFuture); // CraftBukkit - decompile error
|
||
|
+ // Paper start - optimize is ticking ready type functions
|
||
|
+ // is entity ticking ready
|
||
|
+ ChunkHolder playerChunk = this.getVisibleChunkIfPresent(MCUtil.getCoordinateKey(pos));
|
||
|
+ return playerChunk != null && playerChunk.isEntityTickingReady();
|
||
|
+ // Paper end - optimize is ticking ready type functions
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean isTickingChunk(BlockPos pos) {
|
||
|
- long i = ChunkPos.asLong(pos.getX() >> 4, pos.getZ() >> 4);
|
||
|
-
|
||
|
- return this.checkChunkFuture(i, (Function<ChunkHolder, CompletableFuture<Either<LevelChunk, ChunkHolder.ChunkLoadingFailure>>>) ChunkHolder::getTickingChunkFuture); // CraftBukkit - decompile error
|
||
|
+ // Paper start - optimize is ticking ready type functions
|
||
|
+ // is ticking ready
|
||
|
+ ChunkHolder playerChunk = this.getVisibleChunkIfPresent(MCUtil.getCoordinateKey(pos));
|
||
|
+ return playerChunk != null && playerChunk.isTickingReady();
|
||
|
+ // Paper end - optimize is ticking ready type functions
|
||
|
}
|
||
|
|
||
|
private boolean checkChunkFuture(long pos, Function<ChunkHolder, CompletableFuture<Either<LevelChunk, ChunkHolder.ChunkLoadingFailure>>> futureFunction) {
|