PaperMC/paper-server/patches/features/0002-Optimize-isInWorldBounds-and-getBlockState-for-inlin.patch

99 lines
4.6 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
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
2021-06-11 14:02:28 +02:00
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
2024-12-15 12:41:29 +01:00
diff --git a/net/minecraft/core/Vec3i.java b/net/minecraft/core/Vec3i.java
index 03e2178430849d26c9826517e34ad069c94fc00a..11555ce7159ca6c8ddfe9691f86d3720c07cb086 100644
--- a/net/minecraft/core/Vec3i.java
+++ b/net/minecraft/core/Vec3i.java
@@ -28,6 +28,12 @@ public class Vec3i implements Comparable<Vec3i> {
);
2021-11-23 13:15:10 +01:00
}
2021-06-11 14:02:28 +02:00
+ // Paper start
+ public final boolean isInsideBuildHeightAndWorldBoundsHorizontal(net.minecraft.world.level.LevelHeightAccessor levelHeightAccessor) {
2021-06-14 17:10:25 +02:00
+ return getX() >= -30000000 && getZ() >= -30000000 && getX() < 30000000 && getZ() < 30000000 && !levelHeightAccessor.isOutsideBuildHeight(getY());
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
+
public Vec3i(int x, int y, int z) {
this.x = x;
this.y = y;
2024-12-15 12:41:29 +01:00
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
2024-12-16 15:17:46 +01:00
index e0239091729f6be138c037951fd5c138497ee358..691fee2e2097244126f4fac0f5d00bf6916b9766 100644
2024-12-15 12:41:29 +01:00
--- a/net/minecraft/world/level/Level.java
+++ b/net/minecraft/world/level/Level.java
2024-12-16 15:17:46 +01:00
@@ -350,7 +350,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
// Paper end
2021-06-11 14:02:28 +02:00
2021-06-12 04:24:43 +02:00
public boolean isInWorldBounds(BlockPos pos) {
2024-12-15 12:41:29 +01:00
- return !this.isOutsideBuildHeight(pos) && isInWorldBoundsHorizontal(pos);
+ return pos.isInsideBuildHeightAndWorldBoundsHorizontal(this); // Paper - use better/optimized check
2021-06-11 14:02:28 +02:00
}
public static boolean isInSpawnableBounds(BlockPos pos) {
2024-12-15 12:41:29 +01:00
diff --git a/net/minecraft/world/level/chunk/ChunkAccess.java b/net/minecraft/world/level/chunk/ChunkAccess.java
index f68f3f5e8ef39a0dc371e75110227a39791c04c8..12d9b532e466ec4e46920d409b5f1b3ae60b80f8 100644
--- a/net/minecraft/world/level/chunk/ChunkAccess.java
+++ b/net/minecraft/world/level/chunk/ChunkAccess.java
@@ -130,6 +130,7 @@ public abstract class ChunkAccess implements BiomeManager.NoiseBiomeSource, Ligh
2022-12-07 19:52:24 +01:00
return GameEventListenerRegistry.NOOP;
2021-06-12 04:24:43 +02:00
}
2021-06-11 14:02:28 +02:00
+ public abstract BlockState getBlockState(final int x, final int y, final int z); // Paper
2021-06-11 14:02:28 +02:00
@Nullable
2024-12-15 12:41:29 +01:00
public abstract BlockState setBlockState(BlockPos pos, BlockState state, boolean isMoving);
2021-06-11 14:02:28 +02:00
2024-12-15 12:41:29 +01:00
diff --git a/net/minecraft/world/level/chunk/ImposterProtoChunk.java b/net/minecraft/world/level/chunk/ImposterProtoChunk.java
index 6c43e5e685871289968db8171342fd84189edcba..e7c0f4da8508fbca467326f475668d66454d7b77 100644
--- a/net/minecraft/world/level/chunk/ImposterProtoChunk.java
+++ b/net/minecraft/world/level/chunk/ImposterProtoChunk.java
@@ -56,6 +56,12 @@ public class ImposterProtoChunk extends ProtoChunk {
2021-06-11 14:02:28 +02:00
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);
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
@Override
public FluidState getFluidState(BlockPos pos) {
2024-12-15 12:41:29 +01:00
diff --git a/net/minecraft/world/level/chunk/ProtoChunk.java b/net/minecraft/world/level/chunk/ProtoChunk.java
index e359b5f694210f05e5675a995dbfc1a95cec76db..8c333d7f390d823a7c7f303e2f444f52ec16f799 100644
--- a/net/minecraft/world/level/chunk/ProtoChunk.java
+++ b/net/minecraft/world/level/chunk/ProtoChunk.java
@@ -99,12 +99,18 @@ public class ProtoChunk extends ChunkAccess {
2021-06-11 14:02:28 +02:00
@Override
public BlockState getBlockState(BlockPos pos) {
2024-12-15 12:41:29 +01:00
- int y = pos.getY();
2021-06-12 04:24:43 +02:00
+ // Paper start
+ return getBlockState(pos.getX(), pos.getY(), pos.getZ());
2021-06-11 14:02:28 +02:00
+ }
+ public BlockState getBlockState(final int x, final int y, final int z) {
2024-12-15 12:41:29 +01:00
+ // Paper end
if (this.isOutsideBuildHeight(y)) {
2021-06-11 14:02:28 +02:00
return Blocks.VOID_AIR.defaultBlockState();
} else {
2024-12-15 12:41:29 +01:00
- LevelChunkSection section = this.getSection(this.getSectionIndex(y));
- return section.hasOnlyAir() ? Blocks.AIR.defaultBlockState() : section.getBlockState(pos.getX() & 15, y & 15, pos.getZ() & 15);
+ // Paper start
+ LevelChunkSection section = this.getSections()[this.getSectionIndex(y)];
+ return section.hasOnlyAir() ? Blocks.AIR.defaultBlockState() : section.getBlockState(x & 15, y & 15, z & 15);
+ // Paper end
2021-06-11 14:02:28 +02:00
}
}