Paper/Spigot-Server-Patches/0330-Optimize-BlockPosition-helper-methods.patch
Zach Brown 8ed2992da9
Make scan-for-legacy-ender-dragon config work again
Portion of diff was dropped in the mappings update commit.

Also remove the option to remove invalid statistics. The server will
automatically do this now as of... 1.13?, our option wasn't even doing anything.
2018-12-14 20:17:27 -05:00

126 lines
5.5 KiB
Diff

From 920e9a778232025ce8de4183f13610da418b3843 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Wed, 15 Aug 2018 12:05:12 -0700
Subject: [PATCH] Optimize BlockPosition helper methods
Resolves #1338
diff --git a/src/main/java/net/minecraft/server/BlockPosition.java b/src/main/java/net/minecraft/server/BlockPosition.java
index 9ce3cd9c9..adf648dfd 100644
--- a/src/main/java/net/minecraft/server/BlockPosition.java
+++ b/src/main/java/net/minecraft/server/BlockPosition.java
@@ -58,59 +58,96 @@ public class BlockPosition extends BaseBlockPosition {
}
public BlockPosition up() {
- return this.up(1);
+ return new BlockPosition(this.getX(), this.getY() + 1, this.getZ()); // Paper - Optimize BlockPosition
}
public BlockPosition up(int ix) {
- return this.shift(EnumDirection.UP, ix);
+ return ix == 0 ? this : new BlockPosition(this.getX(), this.getY() + ix, this.getZ()); // Paper - Optimize BlockPosition
}
public BlockPosition down() {
- return this.down(1);
+ return new BlockPosition(this.getX(), this.getY() - 1, this.getZ()); // Paper - Optimize BlockPosition
}
public BlockPosition down(int ix) {
- return this.shift(EnumDirection.DOWN, ix);
+ return ix == 0 ? this : new BlockPosition(this.getX(), this.getY() - ix, this.getZ()); // Paper - Optimize BlockPosition
}
public BlockPosition north() {
- return this.north(1);
+ return new BlockPosition(this.getX(), this.getY(), this.getZ() - 1); // Paper - Optimize BlockPosition
}
public BlockPosition north(int ix) {
- return this.shift(EnumDirection.NORTH, ix);
+ return ix == 0 ? this : new BlockPosition(this.getX(), this.getY(), this.getZ() - ix); // Paper - Optimize BlockPosition
}
public BlockPosition south() {
- return this.south(1);
+ return new BlockPosition(this.getX(), this.getY(), this.getZ() + 1); // Paper - Optimize BlockPosition
}
public BlockPosition south(int ix) {
- return this.shift(EnumDirection.SOUTH, ix);
+ return ix == 0 ? this : new BlockPosition(this.getX(), this.getY(), this.getZ() + ix); // Paper - Optimize BlockPosition
}
public BlockPosition west() {
- return this.west(1);
+ return new BlockPosition(this.getX() - 1, this.getY(), this.getZ()); // Paper - Optimize BlockPosition
}
public BlockPosition west(int ix) {
- return this.shift(EnumDirection.WEST, ix);
+ return ix == 0 ? this : new BlockPosition(this.getX() - ix, this.getY(), this.getZ()); // Paper - Optimize BlockPosition
}
public BlockPosition east() {
- return this.east(1);
+ return new BlockPosition(this.getX() + 1, this.getY(), this.getZ()); // Paper - Optimize BlockPosition
}
public BlockPosition east(int ix) {
- return this.shift(EnumDirection.EAST, ix);
+ return ix == 0 ? this : new BlockPosition(this.getX() + ix, this.getY(), this.getZ()); // Paper - Optimize BlockPosition
}
public BlockPosition shift(EnumDirection enumdirection) {
- return this.shift(enumdirection, 1);
+ // Paper Start - Optimize BlockPosition
+ switch(enumdirection) {
+ case UP:
+ return new BlockPosition(this.getX(), this.getY() + 1, this.getZ());
+ case DOWN:
+ return new BlockPosition(this.getX(), this.getY() - 1, this.getZ());
+ case NORTH:
+ return new BlockPosition(this.getX(), this.getY(), this.getZ() - 1);
+ case SOUTH:
+ return new BlockPosition(this.getX(), this.getY(), this.getZ() + 1);
+ case WEST:
+ return new BlockPosition(this.getX() - 1, this.getY(), this.getZ());
+ case EAST:
+ return new BlockPosition(this.getX() + 1, this.getY(), this.getZ());
+ default:
+ return new BlockPosition(this.getX() + enumdirection.getAdjacentX(), this.getY() + enumdirection.getAdjacentY(), this.getZ() + enumdirection.getAdjacentZ());
+ }
+ // Paper End
}
public BlockPosition shift(EnumDirection enumdirection, int ix) {
- return ix == 0 ? this : new BlockPosition(this.getX() + enumdirection.getAdjacentX() * ix, this.getY() + enumdirection.getAdjacentY() * ix, this.getZ() + enumdirection.getAdjacentZ() * ix);
+ // Paper Start - Optimize BlockPosition
+ if (ix == 0) {
+ return this;
+ }
+ switch(enumdirection) {
+ case UP:
+ return new BlockPosition(this.getX(), this.getY() + ix, this.getZ());
+ case DOWN:
+ return new BlockPosition(this.getX(), this.getY() - ix, this.getZ());
+ case NORTH:
+ return new BlockPosition(this.getX(), this.getY(), this.getZ() - ix);
+ case SOUTH:
+ return new BlockPosition(this.getX(), this.getY(), this.getZ() + ix);
+ case WEST:
+ return new BlockPosition(this.getX() - ix, this.getY(), this.getZ());
+ case EAST:
+ return new BlockPosition(this.getX() + ix, this.getY(), this.getZ());
+ default:
+ return new BlockPosition(this.getX() + enumdirection.getAdjacentX() * ix, this.getY() + enumdirection.getAdjacentY() * ix, this.getZ() + enumdirection.getAdjacentZ() * ix);
+ }
+ // Paper End
}
public BlockPosition a(EnumBlockRotation enumblockrotation) {
--
2.20.0