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
|
2021-12-06 00:32:02 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/core/Vec3i.java b/src/main/java/net/minecraft/core/Vec3i.java
|
|
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
|
|
--- a/src/main/java/net/minecraft/core/Vec3i.java
|
|
|
|
+++ b/src/main/java/net/minecraft/core/Vec3i.java
|
|
|
|
@@ -0,0 +0,0 @@ public class Vec3i implements Comparable<Vec3i> {
|
2021-11-23 13:15:10 +01:00
|
|
|
return CODEC.flatXmap(checkOffsetAxes(maxAbsValue), checkOffsetAxes(maxAbsValue));
|
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
+ // Paper start
|
2021-12-06 00:32:02 +01:00
|
|
|
+ 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;
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
|
|
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
|
|
|
@@ -0,0 +0,0 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
|
|
|
}
|
|
|
|
|
2021-06-12 04:24:43 +02:00
|
|
|
public boolean isInWorldBounds(BlockPos pos) {
|
|
|
|
- return !this.isOutsideBuildHeight(pos) && Level.isInWorldBoundsHorizontal(pos);
|
2021-12-06 00:32:02 +01:00
|
|
|
+ return pos.isInsideBuildHeightAndWorldBoundsHorizontal(this); // Paper - use better/optimized check
|
2021-06-11 14:02:28 +02: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
|
|
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
|
2021-11-23 13:15:10 +01:00
|
|
|
@@ -0,0 +0,0 @@ public abstract class ChunkAccess implements BlockGetter, BiomeManager.NoiseBiom
|
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
|
|
|
|
2021-12-06 00:32:02 +01:00
|
|
|
+ public abstract BlockState getBlockState(final int x, final int y, final int z); // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
@Nullable
|
2021-11-23 13:15:10 +01:00
|
|
|
public abstract BlockState setBlockState(BlockPos pos, BlockState state, boolean moved);
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/chunk/EmptyLevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/EmptyLevelChunk.java
|
|
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/EmptyLevelChunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/EmptyLevelChunk.java
|
|
|
|
@@ -0,0 +0,0 @@ public class EmptyLevelChunk extends LevelChunk {
|
2022-09-26 10:02:51 +02:00
|
|
|
public void setBlockEmptinessMap(final boolean[] emptinessMap) {}
|
|
|
|
// Paper end - starlight
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
+ // Paper start
|
2021-12-06 00:32:02 +01:00
|
|
|
+ @Override
|
|
|
|
+ public BlockState getBlockState(int x, int y, int z) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ return Blocks.VOID_AIR.defaultBlockState();
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
@Override
|
|
|
|
public BlockState getBlockState(BlockPos pos) {
|
|
|
|
return Blocks.VOID_AIR.defaultBlockState();
|
|
|
|
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java
|
|
|
|
@@ -0,0 +0,0 @@ public class ImposterProtoChunk extends ProtoChunk {
|
|
|
|
public BlockState getBlockState(BlockPos pos) {
|
|
|
|
return this.wrapped.getBlockState(pos);
|
|
|
|
}
|
|
|
|
+ // Paper start
|
2021-12-06 00:32:02 +01: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 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidState getFluidState(BlockPos pos) {
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
|
|
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
|
2021-11-23 13:15:10 +01:00
|
|
|
@@ -0,0 +0,0 @@ public class LevelChunk extends ChunkAccess {
|
2022-06-07 21:55:39 +02:00
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start - Optimize getBlockData to reduce instructions
|
2021-06-12 04:24:43 +02:00
|
|
|
@Override
|
2021-06-11 14:02:28 +02:00
|
|
|
public BlockState getBlockState(BlockPos pos) {
|
|
|
|
- int i = pos.getX();
|
|
|
|
- int j = pos.getY();
|
|
|
|
- int k = pos.getZ();
|
2021-12-06 00:32:02 +01:00
|
|
|
+ return this.getBlockStateFinal(pos.getX(), pos.getY(), pos.getZ());
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
2021-06-12 04:24:43 +02:00
|
|
|
+
|
2021-12-06 00:32:02 +01:00
|
|
|
+ @Override
|
|
|
|
+ public BlockState getBlockState(final int x, final int y, final int z) {
|
|
|
|
+ return this.getBlockStateFinal(x, y, z);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
2021-12-06 00:32:02 +01:00
|
|
|
+ public final BlockState getBlockStateFinal(final int x, final int y, final int z) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Method body / logic copied from below
|
2021-06-12 04:24:43 +02:00
|
|
|
+ final int i = this.getSectionIndex(y);
|
2021-12-06 00:32:02 +01:00
|
|
|
+ if (i < 0 || i >= this.sections.length || this.sections[i].nonEmptyBlockCount == 0 || this.sections[i].hasOnlyAir()) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ return Blocks.AIR.defaultBlockState();
|
|
|
|
+ }
|
|
|
|
+ // Inlined ChunkSection.getType() and DataPaletteBlock.a(int,int,int)
|
|
|
|
+ return this.sections[i].states.get((y & 15) << 8 | (z & 15) << 4 | x & 15);
|
2021-06-12 04:24:43 +02:00
|
|
|
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
2021-12-06 00:32:02 +01:00
|
|
|
+ public BlockState getBlockState_unused(int i, int j, int k) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper end
|
2021-06-12 04:24:43 +02:00
|
|
|
if (this.level.isDebug()) {
|
2021-06-11 14:02:28 +02:00
|
|
|
BlockState iblockdata = null;
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
|
|
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
|
|
|
|
@@ -0,0 +0,0 @@ public class LevelChunkSection {
|
2021-06-12 04:24:43 +02:00
|
|
|
public static final int SECTION_SIZE = 4096;
|
2021-11-23 13:15:10 +01:00
|
|
|
public static final int BIOME_CONTAINER_BITS = 2;
|
2021-06-11 14:02:28 +02:00
|
|
|
private final int bottomBlockY;
|
|
|
|
- private short nonEmptyBlockCount;
|
|
|
|
+ short nonEmptyBlockCount; // Paper - package-private
|
|
|
|
private short tickingBlockCount;
|
|
|
|
private short tickingFluidCount;
|
2021-11-23 13:15:10 +01:00
|
|
|
public final PalettedContainer<BlockState> states;
|
2021-06-11 14:02:28 +02:00
|
|
|
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java
|
2021-11-23 13:15:10 +01:00
|
|
|
@@ -0,0 +0,0 @@ public class ProtoChunk extends ChunkAccess {
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockState getBlockState(BlockPos pos) {
|
|
|
|
- int i = pos.getY();
|
2021-06-12 04:24:43 +02:00
|
|
|
- if (this.isOutsideBuildHeight(i)) {
|
|
|
|
+ // Paper start
|
2021-12-06 00:32:02 +01:00
|
|
|
+ return getBlockState(pos.getX(), pos.getY(), pos.getZ());
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
2021-12-06 00:32:02 +01:00
|
|
|
+ public BlockState getBlockState(final int x, final int y, final int z) {
|
2021-06-12 04:24:43 +02:00
|
|
|
+ if (this.isOutsideBuildHeight(y)) {
|
2021-06-11 14:02:28 +02:00
|
|
|
return Blocks.VOID_AIR.defaultBlockState();
|
|
|
|
} else {
|
2021-11-23 13:15:10 +01: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 14:02:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidState getFluidState(BlockPos pos) {
|