2018-09-29 01:31:59 +02:00
|
|
|
From 5487faf5715f545c2c3199f94e388d03f85cc73b Mon Sep 17 00:00:00 2001
|
2018-08-17 23:51:56 +02:00
|
|
|
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
|
2018-09-01 00:56:57 +02:00
|
|
|
index 986b1e13a5..45f7794613 100644
|
2018-08-17 23:51:56 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/BlockPosition.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/BlockPosition.java
|
2018-09-01 00:56:57 +02:00
|
|
|
@@ -58,59 +58,96 @@ public class BlockPosition extends BaseBlockPosition {
|
2018-08-17 23:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public BlockPosition up() {
|
|
|
|
- return this.up(1);
|
|
|
|
+ return new BlockPosition(this.getX(), this.getY() + 1, this.getZ()); // Paper - Optimize BlockPosition
|
|
|
|
}
|
|
|
|
|
2018-09-01 00:56:57 +02:00
|
|
|
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
|
2018-08-17 23:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public BlockPosition down() {
|
|
|
|
- return this.down(1);
|
|
|
|
+ return new BlockPosition(this.getX(), this.getY() - 1, this.getZ()); // Paper - Optimize BlockPosition
|
|
|
|
}
|
|
|
|
|
2018-09-01 00:56:57 +02:00
|
|
|
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
|
2018-08-17 23:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public BlockPosition north() {
|
|
|
|
- return this.north(1);
|
|
|
|
+ return new BlockPosition(this.getX(), this.getY(), this.getZ() - 1); // Paper - Optimize BlockPosition
|
|
|
|
}
|
|
|
|
|
2018-09-01 00:56:57 +02:00
|
|
|
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
|
2018-08-17 23:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public BlockPosition south() {
|
|
|
|
- return this.south(1);
|
|
|
|
+ return new BlockPosition(this.getX(), this.getY(), this.getZ() + 1); // Paper - Optimize BlockPosition
|
|
|
|
}
|
|
|
|
|
2018-09-01 00:56:57 +02:00
|
|
|
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
|
2018-08-17 23:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public BlockPosition west() {
|
|
|
|
- return this.west(1);
|
|
|
|
+ return new BlockPosition(this.getX() - 1, this.getY(), this.getZ()); // Paper - Optimize BlockPosition
|
|
|
|
}
|
|
|
|
|
2018-09-01 00:56:57 +02:00
|
|
|
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
|
2018-08-17 23:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public BlockPosition east() {
|
|
|
|
- return this.east(1);
|
|
|
|
+ return new BlockPosition(this.getX() + 1, this.getY(), this.getZ()); // Paper - Optimize BlockPosition
|
|
|
|
}
|
|
|
|
|
2018-09-01 00:56:57 +02:00
|
|
|
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
|
2018-08-17 23:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-09-01 00:56:57 +02:00
|
|
|
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);
|
2018-08-17 23:51:56 +02:00
|
|
|
+ // Paper Start - Optimize BlockPosition
|
2018-09-01 00:56:57 +02:00
|
|
|
+ if (ix == 0) {
|
2018-08-17 23:51:56 +02:00
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+ switch(enumdirection) {
|
|
|
|
+ case UP:
|
2018-09-01 00:56:57 +02:00
|
|
|
+ return new BlockPosition(this.getX(), this.getY() + ix, this.getZ());
|
2018-08-17 23:51:56 +02:00
|
|
|
+ case DOWN:
|
2018-09-01 00:56:57 +02:00
|
|
|
+ return new BlockPosition(this.getX(), this.getY() - ix, this.getZ());
|
2018-08-17 23:51:56 +02:00
|
|
|
+ case NORTH:
|
2018-09-01 00:56:57 +02:00
|
|
|
+ return new BlockPosition(this.getX(), this.getY(), this.getZ() - ix);
|
2018-08-17 23:51:56 +02:00
|
|
|
+ case SOUTH:
|
2018-09-01 00:56:57 +02:00
|
|
|
+ return new BlockPosition(this.getX(), this.getY(), this.getZ() + ix);
|
2018-08-17 23:51:56 +02:00
|
|
|
+ case WEST:
|
2018-09-01 00:56:57 +02:00
|
|
|
+ return new BlockPosition(this.getX() - ix, this.getY(), this.getZ());
|
2018-08-17 23:51:56 +02:00
|
|
|
+ case EAST:
|
2018-09-01 00:56:57 +02:00
|
|
|
+ return new BlockPosition(this.getX() + ix, this.getY(), this.getZ());
|
2018-08-17 23:51:56 +02:00
|
|
|
+ default:
|
2018-09-01 00:56:57 +02:00
|
|
|
+ return new BlockPosition(this.getX() + enumdirection.getAdjacentX() * ix, this.getY() + enumdirection.getAdjacentY() * ix, this.getZ() + enumdirection.getAdjacentZ() * ix);
|
2018-08-17 23:51:56 +02:00
|
|
|
+ }
|
|
|
|
+ // Paper End
|
|
|
|
}
|
|
|
|
|
|
|
|
public BlockPosition a(EnumBlockRotation enumblockrotation) {
|
|
|
|
--
|
2018-09-27 04:35:42 +02:00
|
|
|
2.19.0
|
2018-08-17 23:51:56 +02:00
|
|
|
|