2021-06-11 12:02:28 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Thu, 3 Mar 2016 02:07:55 -0600
|
2021-12-05 23:32:02 +00:00
|
|
|
Subject: [PATCH] Optimize isInWorldBounds and getBlockState for inlining
|
2021-06-11 12:02:28 +00: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
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/core/Vec3i.java b/src/main/java/net/minecraft/core/Vec3i.java
|
2024-04-12 19:14:06 +00:00
|
|
|
index 21387401c7958414fa6f3fd530488481d92a6eca..17bb8fb0353a818d946a0831781918781314c0ce 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/core/Vec3i.java
|
|
|
|
+++ b/src/main/java/net/minecraft/core/Vec3i.java
|
2024-04-12 19:14:06 +00:00
|
|
|
@@ -30,6 +30,12 @@ public class Vec3i implements Comparable<Vec3i> {
|
|
|
|
);
|
2021-11-23 12:15:10 +00:00
|
|
|
}
|
2021-06-11 12:02:28 +00:00
|
|
|
|
|
|
|
+ // Paper start
|
2021-12-05 23:32:02 +00:00
|
|
|
+ public final boolean isInsideBuildHeightAndWorldBoundsHorizontal(net.minecraft.world.level.LevelHeightAccessor levelHeightAccessor) {
|
2021-06-14 15:10:25 +00:00
|
|
|
+ return getX() >= -30000000 && getZ() >= -30000000 && getX() < 30000000 && getZ() < 30000000 && !levelHeightAccessor.isOutsideBuildHeight(getY());
|
2021-06-11 12:02:28 +00:00
|
|
|
+ }
|
|
|
|
+ // 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
|
2024-04-06 19:53:39 +00:00
|
|
|
index 9c743c980697a14d7348554fb77f242d5eaa152e..6c4af5e5e26930a7b0d140f8058d798355e4d53b 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
2024-02-01 09:15:57 +00:00
|
|
|
@@ -337,7 +337,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
2023-09-10 02:28:03 +00:00
|
|
|
// Paper end
|
2021-06-11 12:02:28 +00:00
|
|
|
|
2021-06-12 02:24:43 +00:00
|
|
|
public boolean isInWorldBounds(BlockPos pos) {
|
|
|
|
- return !this.isOutsideBuildHeight(pos) && Level.isInWorldBoundsHorizontal(pos);
|
2021-12-05 23:32:02 +00:00
|
|
|
+ return pos.isInsideBuildHeightAndWorldBoundsHorizontal(this); // Paper - use better/optimized check
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2023-10-17 01:57:45 +00:00
|
|
|
index 3e5addb60ae8f466dad09edb3ae1fc88fe2681e9..5e8d2e4245757a0889645ea79ee68afb53f7dde4 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
|
2023-10-17 01:57:45 +00:00
|
|
|
@@ -172,6 +172,7 @@ public abstract class ChunkAccess implements BlockGetter, BiomeManager.NoiseBiom
|
2022-12-07 18:52:24 +00:00
|
|
|
return GameEventListenerRegistry.NOOP;
|
2021-06-12 02:24:43 +00:00
|
|
|
}
|
2021-06-11 12:02:28 +00:00
|
|
|
|
2021-12-05 23:32:02 +00:00
|
|
|
+ public abstract BlockState getBlockState(final int x, final int y, final int z); // Paper
|
2021-06-11 12:02:28 +00:00
|
|
|
@Nullable
|
2021-11-23 12:15:10 +00:00
|
|
|
public abstract BlockState setBlockState(BlockPos pos, BlockState state, boolean moved);
|
2021-06-11 12:02:28 +00:00
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java b/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java
|
2024-04-12 19:14:06 +00:00
|
|
|
index 030fafe3b0bcad9e95251f5824ac2ef58640c705..b4e05ce176dfc6a2e66b294ed461c32020adf203 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java
|
2024-04-12 19:14:06 +00:00
|
|
|
@@ -97,6 +97,12 @@ public class ImposterProtoChunk extends ProtoChunk {
|
2021-06-11 12:02:28 +00:00
|
|
|
public BlockState getBlockState(BlockPos pos) {
|
|
|
|
return this.wrapped.getBlockState(pos);
|
|
|
|
}
|
|
|
|
+ // Paper start
|
2021-12-05 23:32:02 +00:00
|
|
|
+ @Override
|
|
|
|
+ public final BlockState getBlockState(final int x, final int y, final int z) {
|
|
|
|
+ return this.wrapped.getBlockStateFinal(x, y, z);
|
2021-06-11 12:02:28 +00:00
|
|
|
+ }
|
|
|
|
+ // 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
|
2024-04-12 19:14:06 +00:00
|
|
|
index 1036ff2ac8ba0967a36eb7977ed49500a05a33e6..a1f6274c9b1ab02ee55f1ae6011fc2dbb6e4824f 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java
|
2024-04-12 19:14:06 +00:00
|
|
|
@@ -95,14 +95,18 @@ public class ProtoChunk extends ChunkAccess {
|
2021-06-11 12:02:28 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockState getBlockState(BlockPos pos) {
|
|
|
|
- int i = pos.getY();
|
2021-06-12 02:24:43 +00:00
|
|
|
- if (this.isOutsideBuildHeight(i)) {
|
|
|
|
+ // Paper start
|
2021-12-05 23:32:02 +00:00
|
|
|
+ return getBlockState(pos.getX(), pos.getY(), pos.getZ());
|
2021-06-11 12:02:28 +00:00
|
|
|
+ }
|
2021-12-05 23:32:02 +00:00
|
|
|
+ public BlockState getBlockState(final int x, final int y, final int z) {
|
2021-06-12 02:24:43 +00:00
|
|
|
+ if (this.isOutsideBuildHeight(y)) {
|
2021-06-11 12:02:28 +00:00
|
|
|
return Blocks.VOID_AIR.defaultBlockState();
|
|
|
|
} else {
|
2021-11-23 12:15:10 +00:00
|
|
|
- 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);
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidState getFluidState(BlockPos pos) {
|