mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 15:30:19 +01:00
8c5b837e05
Firstly, the old methods all routed to the CompletableFuture method. However, the CF method could not guarantee that if the caller was off-main that the future would be "completed" on-main. Since the callback methods used the CF one, this meant that the callback methods did not guarantee that the callbacks were to be called on the main thread. Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb) so that the methods with the callback are guaranteed to invoke the callback on the main thread. The CF behavior remains unchanged; it may still appear to complete on main if invoked off-main. Secondly, remove the scheduleOnMain invocation in the async chunk completion. This unnecessarily delays the callback by 1 tick. Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which will load chunks within an area. This method is provided as a helper as keeping all chunks loaded within an area can be complicated to implement for plugins (due to the lacking ticket API), and is already implemented internally anyways. Fourthly, remove the ticket addition that occured with getChunkAt and getChunkAtAsync. The ticket addition may delay the unloading of the chunk unnecessarily. It also fixes a very rare timing bug where the future/callback would be completed after the chunk unloads.
101 lines
5 KiB
Diff
101 lines
5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Thu, 3 Mar 2016 02:07:55 -0600
|
|
Subject: [PATCH] Optimize isInWorldBounds and getBlockState for inlining
|
|
|
|
Hot methods, so reduce # of instructions for the method.
|
|
|
|
Move is valid location test to the BlockPosition class so that it can access local variables.
|
|
|
|
Replace all calls to the new place to the unnecessary forward.
|
|
|
|
Optimize getType and getBlockData to manually inline and optimize the calls
|
|
|
|
Feature patch
|
|
|
|
diff --git a/src/main/java/net/minecraft/core/Vec3i.java b/src/main/java/net/minecraft/core/Vec3i.java
|
|
index 2f2bcc1b9b32e58bf70ae6c171177ceb333ed6cd..d7afddd1d961495f0b50302a8da0a70fcd3ba1b0 100644
|
|
--- a/src/main/java/net/minecraft/core/Vec3i.java
|
|
+++ b/src/main/java/net/minecraft/core/Vec3i.java
|
|
@@ -28,6 +28,12 @@ public class Vec3i implements Comparable<Vec3i> {
|
|
);
|
|
}
|
|
|
|
+ // Paper start
|
|
+ public final boolean isInsideBuildHeightAndWorldBoundsHorizontal(net.minecraft.world.level.LevelHeightAccessor levelHeightAccessor) {
|
|
+ return getX() >= -30000000 && getZ() >= -30000000 && getX() < 30000000 && getZ() < 30000000 && !levelHeightAccessor.isOutsideBuildHeight(getY());
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
public Vec3i(int x, int y, int z) {
|
|
this.x = x;
|
|
this.y = y;
|
|
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
|
|
index 96f18fa8fb5eb856a95e94a42504c00046eb491a..a124a360f45cd71810b8253ce266d52145b6f83b 100644
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
|
@@ -339,7 +339,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
|
// Paper end
|
|
|
|
public boolean isInWorldBounds(BlockPos pos) {
|
|
- return !this.isOutsideBuildHeight(pos) && Level.isInWorldBoundsHorizontal(pos);
|
|
+ return pos.isInsideBuildHeightAndWorldBoundsHorizontal(this); // Paper - use better/optimized check
|
|
}
|
|
|
|
public static boolean isInSpawnableBounds(BlockPos pos) {
|
|
diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java b/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
|
|
index 37795b9e264c571efe9c718fa9996197dca4ed54..a846dd210ed1de0dc3e8b686663ee346bff33dc8 100644
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
|
|
@@ -128,6 +128,7 @@ public abstract class ChunkAccess implements BiomeManager.NoiseBiomeSource, Ligh
|
|
return GameEventListenerRegistry.NOOP;
|
|
}
|
|
|
|
+ public abstract BlockState getBlockState(final int x, final int y, final int z); // Paper
|
|
@Nullable
|
|
public abstract BlockState setBlockState(BlockPos pos, BlockState state, boolean moved);
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java b/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java
|
|
index 7cce66d4c6efe6fd3cc22a6acf72878c964c61ae..f38700e5fbeeb8a913272d4464b8aa325d511dac 100644
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java
|
|
@@ -56,6 +56,12 @@ public class ImposterProtoChunk extends ProtoChunk {
|
|
public BlockState getBlockState(BlockPos pos) {
|
|
return this.wrapped.getBlockState(pos);
|
|
}
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public final BlockState getBlockState(final int x, final int y, final int z) {
|
|
+ return this.wrapped.getBlockStateFinal(x, y, z);
|
|
+ }
|
|
+ // Paper end
|
|
|
|
@Override
|
|
public FluidState getFluidState(BlockPos pos) {
|
|
diff --git a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java b/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java
|
|
index 5321109ca638036572df9a7e17eafcef2b4f5112..4d5704df4a7ac6e148774f1a986d46bfb7e95f95 100644
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java
|
|
@@ -97,14 +97,18 @@ public class ProtoChunk extends ChunkAccess {
|
|
|
|
@Override
|
|
public BlockState getBlockState(BlockPos pos) {
|
|
- int i = pos.getY();
|
|
- if (this.isOutsideBuildHeight(i)) {
|
|
+ // Paper start
|
|
+ return getBlockState(pos.getX(), pos.getY(), pos.getZ());
|
|
+ }
|
|
+ public BlockState getBlockState(final int x, final int y, final int z) {
|
|
+ if (this.isOutsideBuildHeight(y)) {
|
|
return Blocks.VOID_AIR.defaultBlockState();
|
|
} else {
|
|
- LevelChunkSection levelChunkSection = this.getSection(this.getSectionIndex(i));
|
|
- return levelChunkSection.hasOnlyAir() ? Blocks.AIR.defaultBlockState() : levelChunkSection.getBlockState(pos.getX() & 15, i & 15, pos.getZ() & 15);
|
|
+ LevelChunkSection levelChunkSection = this.getSections()[this.getSectionIndex(y)];
|
|
+ return levelChunkSection.hasOnlyAir() ? Blocks.AIR.defaultBlockState() : levelChunkSection.getBlockState(x & 15, y & 15, z & 15);
|
|
}
|
|
}
|
|
+ // Paper end
|
|
|
|
@Override
|
|
public FluidState getFluidState(BlockPos pos) {
|