2020-05-06 11:48:49 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2019-04-27 05:05:36 +02:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Thu, 3 Mar 2016 02:07:55 -0600
|
2020-06-05 07:25:11 +02:00
|
|
|
Subject: [PATCH] Optimize isValidLocation, getType and getBlockData for
|
|
|
|
inlining
|
2019-04-27 05:05:36 +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/server/BaseBlockPosition.java b/src/main/java/net/minecraft/server/BaseBlockPosition.java
|
2020-08-02 07:39:36 +02:00
|
|
|
index b190cd9ef8f447e4e9ff1adb74bff6e63750caad..1e1f4663525db5ab80e7c645be19a6ab4f335e5b 100644
|
2019-04-27 05:05:36 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/BaseBlockPosition.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/BaseBlockPosition.java
|
2020-06-25 13:00:35 +02:00
|
|
|
@@ -20,6 +20,15 @@ public class BaseBlockPosition implements Comparable<BaseBlockPosition> {
|
2020-08-02 07:39:36 +02:00
|
|
|
private int b;public final void setY(final int y) { this.b = y; } // Paper - OBFHELPER
|
|
|
|
private int e;public final void setZ(final int z) { this.e = z; } // Paper - OBFHELPER
|
2020-06-25 13:00:35 +02:00
|
|
|
|
2019-04-27 05:05:36 +02:00
|
|
|
+ // Paper start
|
|
|
|
+ public boolean isValidLocation() {
|
2020-06-25 13:00:35 +02:00
|
|
|
+ return getX() >= -30000000 && getZ() >= -30000000 && getX() < 30000000 && getZ() < 30000000 && getY() >= 0 && getY() < 256;
|
2019-04-27 05:05:36 +02:00
|
|
|
+ }
|
|
|
|
+ public boolean isInvalidYLocation() {
|
|
|
|
+ return b < 0 || b >= 256;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2020-06-25 13:00:35 +02:00
|
|
|
+
|
2019-04-27 05:05:36 +02:00
|
|
|
public BaseBlockPosition(int i, int j, int k) {
|
|
|
|
this.a = i;
|
2020-06-25 13:00:35 +02:00
|
|
|
this.b = j;
|
2019-04-27 05:05:36 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
2020-08-02 07:39:36 +02:00
|
|
|
index 421997be8a8519ed6e24eae2db5e77a4322adb2a..64a1c6f4672626818e28842bca7e8d78d013d14a 100644
|
2019-04-27 05:05:36 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
2020-06-25 13:00:35 +02:00
|
|
|
@@ -308,12 +308,27 @@ public class Chunk implements IChunkAccess {
|
2019-04-27 05:05:36 +02:00
|
|
|
return this.sections;
|
|
|
|
}
|
|
|
|
|
|
|
|
- @Override
|
2019-05-14 04:20:58 +02:00
|
|
|
+ // Paper start - Optimize getBlockData to reduce instructions
|
|
|
|
+ public final IBlockData getBlockData(BlockPosition pos) { return getBlockData(pos.getX(), pos.getY(), pos.getZ()); } // Paper
|
|
|
|
public IBlockData getType(BlockPosition blockposition) {
|
2019-04-27 05:05:36 +02:00
|
|
|
- int i = blockposition.getX();
|
|
|
|
- int j = blockposition.getY();
|
|
|
|
- int k = blockposition.getZ();
|
|
|
|
+ return this.getBlockData(blockposition.getX(), blockposition.getY(), blockposition.getZ());
|
|
|
|
+ }
|
2020-06-05 07:25:11 +02:00
|
|
|
+
|
|
|
|
+ public IBlockData getType(final int x, final int y, final int z) {
|
|
|
|
+ return getBlockData(x, y, z);
|
|
|
|
+ }
|
2019-04-27 05:05:36 +02:00
|
|
|
+ public final IBlockData getBlockData(final int x, final int y, final int z) {
|
|
|
|
+ // Method body / logic copied from below
|
|
|
|
+ final int i = y >> 4;
|
2020-06-05 07:25:11 +02:00
|
|
|
+ if (y < 0 || i >= this.sections.length || this.sections[i] == null || this.sections[i].nonEmptyBlockCount == 0) {
|
|
|
|
+ return Blocks.AIR.getBlockData();
|
2019-04-27 05:05:36 +02:00
|
|
|
+ }
|
2020-06-05 07:25:11 +02:00
|
|
|
+ // Inlined ChunkSection.getType() and DataPaletteBlock.a(int,int,int)
|
|
|
|
+ return this.sections[i].blockIds.a((y & 15) << 8 | (z & 15) << 4 | x & 15);
|
2019-04-27 05:05:36 +02:00
|
|
|
+ }
|
2020-06-05 07:25:11 +02:00
|
|
|
|
2019-04-27 05:05:36 +02:00
|
|
|
+ public IBlockData getBlockData_unused(int i, int j, int k) {
|
|
|
|
+ // Paper end
|
2020-06-25 13:00:35 +02:00
|
|
|
if (this.world.isDebugWorld()) {
|
2019-04-27 05:05:36 +02:00
|
|
|
IBlockData iblockdata = null;
|
|
|
|
|
2020-06-05 07:25:11 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/ChunkEmpty.java b/src/main/java/net/minecraft/server/ChunkEmpty.java
|
|
|
|
index 82fdd3db6f698f8b77c8bbd1f17cb21980ecfeec..fd49438961451987bd102a85484be24b341d946b 100644
|
|
|
|
--- a/src/main/java/net/minecraft/server/ChunkEmpty.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ChunkEmpty.java
|
|
|
|
@@ -7,7 +7,7 @@ import javax.annotation.Nullable;
|
|
|
|
|
|
|
|
public class ChunkEmpty extends Chunk {
|
|
|
|
|
|
|
|
- private static final BiomeBase[] b = (BiomeBase[]) SystemUtils.a((Object) (new BiomeBase[BiomeStorage.a]), (abiomebase) -> {
|
|
|
|
+ private static final BiomeBase[] b = (BiomeBase[]) SystemUtils.a((new BiomeBase[BiomeStorage.a]), (abiomebase) -> { // Paper - decompile error
|
|
|
|
Arrays.fill(abiomebase, Biomes.PLAINS);
|
|
|
|
});
|
|
|
|
|
|
|
|
@@ -15,6 +15,11 @@ public class ChunkEmpty extends Chunk {
|
|
|
|
super(world, chunkcoordintpair, new BiomeStorage(ChunkEmpty.b));
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ @Override public IBlockData getType(int x, int y, int z) {
|
|
|
|
+ return Blocks.VOID_AIR.getBlockData();
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
@Override
|
|
|
|
public IBlockData getType(BlockPosition blockposition) {
|
|
|
|
return Blocks.VOID_AIR.getBlockData();
|
2019-04-27 05:05:36 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/ChunkSection.java b/src/main/java/net/minecraft/server/ChunkSection.java
|
2020-06-25 13:00:35 +02:00
|
|
|
index 882c2733beaff1df68b892d44fc77cacf4364ff4..bd2290a4d4ec314b7afdb1f63d711f80803153cd 100644
|
2019-04-27 05:05:36 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/ChunkSection.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ChunkSection.java
|
2020-06-25 13:00:35 +02:00
|
|
|
@@ -7,10 +7,10 @@ public class ChunkSection {
|
2020-06-05 07:25:11 +02:00
|
|
|
|
|
|
|
public static final DataPalette<IBlockData> GLOBAL_PALETTE = new DataPaletteGlobal<>(Block.REGISTRY_ID, Blocks.AIR.getBlockData());
|
|
|
|
private final int yPos;
|
|
|
|
- private short nonEmptyBlockCount;
|
|
|
|
+ short nonEmptyBlockCount; // Paper - package-private
|
2019-04-27 05:05:36 +02:00
|
|
|
private short tickingBlockCount;
|
|
|
|
private short e;
|
|
|
|
- private final DataPaletteBlock<IBlockData> blockIds;
|
2019-12-11 03:43:21 +01:00
|
|
|
+ final DataPaletteBlock<IBlockData> blockIds;
|
2019-04-27 05:05:36 +02:00
|
|
|
|
|
|
|
public ChunkSection(int i) {
|
|
|
|
this(i, (short) 0, (short) 0, (short) 0);
|
2020-06-25 13:00:35 +02:00
|
|
|
@@ -24,8 +24,8 @@ public class ChunkSection {
|
|
|
|
this.blockIds = new DataPaletteBlock<>(ChunkSection.GLOBAL_PALETTE, Block.REGISTRY_ID, GameProfileSerializer::c, GameProfileSerializer::a, Blocks.AIR.getBlockData());
|
2020-06-05 07:25:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- public IBlockData getType(int i, int j, int k) {
|
|
|
|
- return (IBlockData) this.blockIds.a(i, j, k);
|
|
|
|
+ public final IBlockData getType(int i, int j, int k) { // Paper
|
|
|
|
+ return this.blockIds.a(j << 8 | k << 4 | i); // Paper - inline
|
|
|
|
}
|
|
|
|
|
|
|
|
public Fluid b(int i, int j, int k) {
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/DataPaletteBlock.java b/src/main/java/net/minecraft/server/DataPaletteBlock.java
|
2020-08-02 07:39:36 +02:00
|
|
|
index 32849e360a396128bd228db269ad1a8f7c6583a8..eabc9d7b934f27c823e012f3f10fffc23b461292 100644
|
2020-06-05 07:25:11 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/DataPaletteBlock.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/DataPaletteBlock.java
|
2020-06-25 13:00:35 +02:00
|
|
|
@@ -124,7 +124,7 @@ public class DataPaletteBlock<T> implements DataPaletteExpandable<T> {
|
2020-06-05 07:25:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public T a(int i, int j, int k) {
|
|
|
|
- return this.a(b(i, j, k));
|
|
|
|
+ return this.a(j << 8 | k << 4 | i); // Paper - inline
|
|
|
|
}
|
|
|
|
|
|
|
|
protected T a(int i) {
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/IChunkAccess.java b/src/main/java/net/minecraft/server/IChunkAccess.java
|
2020-06-25 13:00:35 +02:00
|
|
|
index 91efe3e9d8da340b383847bc1ba29d26b7971cd2..3adb35b6abd0df9617e27e10fa3e0d365958ba42 100644
|
2020-06-05 07:25:11 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/IChunkAccess.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/IChunkAccess.java
|
2020-06-25 13:00:35 +02:00
|
|
|
@@ -12,6 +12,7 @@ import org.apache.logging.log4j.LogManager;
|
2020-06-05 07:25:11 +02:00
|
|
|
|
|
|
|
public interface IChunkAccess extends IBlockAccess, IStructureAccess {
|
|
|
|
|
|
|
|
+ IBlockData getType(final int x, final int y, final int z); // Paper
|
|
|
|
@Nullable
|
|
|
|
IBlockData setType(BlockPosition blockposition, IBlockData iblockdata, boolean flag);
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ProtoChunk.java b/src/main/java/net/minecraft/server/ProtoChunk.java
|
2020-06-25 13:00:35 +02:00
|
|
|
index 070449198273e6c42e72c891882b82361d1c8dbd..5114ce15ad1be23ca83b3a3fcaba10a34fcb1a6f 100644
|
2020-06-05 07:25:11 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/ProtoChunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ProtoChunk.java
|
2020-06-25 13:00:35 +02:00
|
|
|
@@ -95,16 +95,18 @@ public class ProtoChunk implements IChunkAccess {
|
2020-06-05 07:25:11 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public IBlockData getType(BlockPosition blockposition) {
|
|
|
|
- int i = blockposition.getY();
|
|
|
|
-
|
|
|
|
- if (World.b(i)) {
|
|
|
|
+ return getType(blockposition.getX(), blockposition.getY(), blockposition.getZ());
|
|
|
|
+ }
|
|
|
|
+ // Paper start
|
|
|
|
+ public IBlockData getType(final int x, final int y, final int z) {
|
|
|
|
+ if (y < 0 || y >= 256) {
|
|
|
|
return Blocks.VOID_AIR.getBlockData();
|
|
|
|
} else {
|
|
|
|
- ChunkSection chunksection = this.getSections()[i >> 4];
|
|
|
|
-
|
|
|
|
- return ChunkSection.a(chunksection) ? Blocks.AIR.getBlockData() : chunksection.getType(blockposition.getX() & 15, i & 15, blockposition.getZ() & 15);
|
|
|
|
+ ChunkSection chunksection = this.getSections()[y >> 4];
|
|
|
|
+ return chunksection == Chunk.EMPTY_CHUNK_SECTION || chunksection.c() ? Blocks.AIR.getBlockData() : chunksection.getType(x & 15, y & 15, z & 15);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Fluid getFluid(BlockPosition blockposition) {
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ProtoChunkExtension.java b/src/main/java/net/minecraft/server/ProtoChunkExtension.java
|
2020-06-25 13:00:35 +02:00
|
|
|
index c5d7a013e65c2c81b14ceb2476c1c6dfe3239f0d..ee8df274d43be753887fb77e4203e2ee30ea02b3 100644
|
2020-06-05 07:25:11 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/ProtoChunkExtension.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ProtoChunkExtension.java
|
|
|
|
@@ -26,6 +26,11 @@ public class ProtoChunkExtension extends ProtoChunk {
|
|
|
|
public IBlockData getType(BlockPosition blockposition) {
|
|
|
|
return this.a.getType(blockposition);
|
|
|
|
}
|
|
|
|
+ // Paper start
|
|
|
|
+ public final IBlockData getType(final int x, final int y, final int z) {
|
|
|
|
+ return this.a.getBlockData(x, y, z);
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Fluid getFluid(BlockPosition blockposition) {
|
2019-04-27 05:05:36 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
2020-07-23 01:35:44 +02:00
|
|
|
index 08d9268c6b6883757d6a6f008dda846d34d63dca..8308c1dbff44226f93715670ce03504f53f6fdb7 100644
|
2019-04-27 05:05:36 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
2020-06-26 18:20:03 +02:00
|
|
|
@@ -181,7 +181,7 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
|
2019-04-27 05:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isValidLocation(BlockPosition blockposition) {
|
2020-06-25 13:00:35 +02:00
|
|
|
- return !isOutsideWorld(blockposition) && e(blockposition);
|
2019-12-11 03:43:21 +01:00
|
|
|
+ return blockposition.isValidLocation();
|
2019-04-27 05:05:36 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 13:00:35 +02:00
|
|
|
public static boolean k(BlockPosition blockposition) {
|
2020-06-26 18:20:03 +02:00
|
|
|
@@ -197,7 +197,7 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
|
2020-06-25 13:00:35 +02:00
|
|
|
}
|
|
|
|
|
2019-05-14 04:20:58 +02:00
|
|
|
public static boolean isOutsideWorld(BlockPosition blockposition) {
|
2019-04-27 05:05:36 +02:00
|
|
|
- return b(blockposition.getY());
|
2019-12-11 03:43:21 +01:00
|
|
|
+ return blockposition.isInvalidYLocation();
|
2019-04-27 05:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean b(int i) {
|