2016-06-23 04:43:02 +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 isValidLocation, getType and getBlockData for inling
|
|
|
|
|
|
|
|
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-05-06 11:48:49 +02:00
|
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
2016-06-23 04:43:02 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/BaseBlockPosition.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/BaseBlockPosition.java
|
|
|
|
@@ -0,0 +0,0 @@ public class BaseBlockPosition implements Comparable<BaseBlockPosition> {
|
|
|
|
private final int b;
|
2019-12-11 03:43:21 +01:00
|
|
|
@Deprecated
|
2016-06-23 04:43:02 +02:00
|
|
|
private final int c;
|
|
|
|
+ // Paper start
|
|
|
|
+ public boolean isValidLocation() {
|
|
|
|
+ return a >= -30000000 && c >= -30000000 && a < 30000000 && c < 30000000 && b >= 0 && b < 256;
|
|
|
|
+ }
|
|
|
|
+ public boolean isInvalidYLocation() {
|
|
|
|
+ return b < 0 || b >= 256;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
public BaseBlockPosition(int i, int j, int k) {
|
|
|
|
this.a = i;
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
2020-05-06 11:48:49 +02:00
|
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
2016-06-23 04:43:02 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
2018-07-15 03:53:17 +02:00
|
|
|
@@ -0,0 +0,0 @@ public class Chunk implements IChunkAccess {
|
2019-04-27 05:05:36 +02:00
|
|
|
return this.sections;
|
2016-06-23 04:43:02 +02:00
|
|
|
}
|
|
|
|
|
2019-04-27 05:05:36 +02:00
|
|
|
- @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());
|
|
|
|
+ }
|
2018-07-15 03:53:17 +02:00
|
|
|
|
2016-06-23 04:43:02 +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;
|
|
|
|
+ if (y >= 0 && i < this.sections.length && this.sections[i] != null) {
|
|
|
|
+ // Inlined ChunkSection.getType() and DataPaletteBlock.a(int,int,int)
|
|
|
|
+ return this.sections[i].blockIds.a((y & 15) << 8 | (z & 15) << 4 | x & 15);
|
|
|
|
+ }
|
|
|
|
+ return Blocks.AIR.getBlockData();
|
|
|
|
+ }
|
2017-05-14 20:05:01 +02:00
|
|
|
+
|
2018-07-15 03:53:17 +02:00
|
|
|
+ public IBlockData getBlockData_unused(int i, int j, int k) {
|
|
|
|
+ // Paper end
|
2019-04-27 05:05:36 +02:00
|
|
|
if (this.world.P() == WorldType.DEBUG_ALL_BLOCK_STATES) {
|
2016-06-23 04:43:02 +02:00
|
|
|
IBlockData iblockdata = null;
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ChunkSection.java b/src/main/java/net/minecraft/server/ChunkSection.java
|
2020-05-06 11:48:49 +02:00
|
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
2016-06-23 04:43:02 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/ChunkSection.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ChunkSection.java
|
|
|
|
@@ -0,0 +0,0 @@ public class ChunkSection {
|
2019-04-27 05:05:36 +02:00
|
|
|
private short nonEmptyBlockCount;
|
|
|
|
private short tickingBlockCount;
|
|
|
|
private short e;
|
2018-07-15 03:53:17 +02:00
|
|
|
- private final DataPaletteBlock<IBlockData> blockIds;
|
2019-12-11 03:43:21 +01:00
|
|
|
+ final DataPaletteBlock<IBlockData> blockIds;
|
2016-06-23 04:43:02 +02:00
|
|
|
|
2019-04-27 05:05:36 +02:00
|
|
|
public ChunkSection(int i) {
|
|
|
|
this(i, (short) 0, (short) 0, (short) 0);
|
2016-06-23 04:43:02 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
2020-05-06 11:48:49 +02:00
|
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
2016-06-23 04:43:02 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
2019-12-11 03:43:21 +01:00
|
|
|
@@ -0,0 +0,0 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
|
2016-06-23 04:43:02 +02:00
|
|
|
}
|
|
|
|
|
2018-07-15 03:53:17 +02:00
|
|
|
public static boolean isValidLocation(BlockPosition blockposition) {
|
2019-05-14 04:20:58 +02:00
|
|
|
- return !isOutsideWorld(blockposition) && blockposition.getX() >= -30000000 && blockposition.getZ() >= -30000000 && blockposition.getX() < 30000000 && blockposition.getZ() < 30000000;
|
2019-12-11 03:43:21 +01:00
|
|
|
+ return blockposition.isValidLocation();
|
2016-06-23 04:43:02 +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();
|
2016-06-23 04:43:02 +02:00
|
|
|
}
|
|
|
|
|
2019-04-27 05:05:36 +02:00
|
|
|
public static boolean b(int i) {
|