2019-07-20 06:01:24 +02:00
|
|
|
From bc08ff9417570d7df849e53f35df454caab58231 Mon Sep 17 00:00:00 2001
|
2019-01-01 04:15:55 +01: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
|
2019-07-20 06:01:24 +02:00
|
|
|
index 04f754d2c1..16f0930404 100644
|
2019-01-01 04:15:55 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/BlockPosition.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/BlockPosition.java
|
2019-05-05 04:23:25 +02:00
|
|
|
@@ -134,55 +134,72 @@ public class BlockPosition extends BaseBlockPosition implements MinecraftSeriali
|
2019-01-01 04:15:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public BlockPosition up() {
|
|
|
|
- return this.up(1);
|
|
|
|
+ return new BlockPosition(this.getX(), this.getY() + 1, this.getZ()); // Paper - Optimize BlockPosition
|
|
|
|
}
|
|
|
|
|
|
|
|
public BlockPosition up(int i) {
|
|
|
|
- return this.shift(EnumDirection.UP, i);
|
|
|
|
+ return i == 0 ? this : new BlockPosition(this.getX(), this.getY() + i, 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 i) {
|
|
|
|
- return this.shift(EnumDirection.DOWN, i);
|
|
|
|
+ return i == 0 ? this : new BlockPosition(this.getX(), this.getY() - i, 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 i) {
|
|
|
|
- return this.shift(EnumDirection.NORTH, i);
|
|
|
|
+ return i == 0 ? this : new BlockPosition(this.getX(), this.getY(), this.getZ() - i); // 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 i) {
|
|
|
|
- return this.shift(EnumDirection.SOUTH, i);
|
|
|
|
+ return i == 0 ? this : new BlockPosition(this.getX(), this.getY(), this.getZ() + i); // 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 i) {
|
|
|
|
- return this.shift(EnumDirection.WEST, i);
|
|
|
|
+ return i == 0 ? this : new BlockPosition(this.getX() - i, 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 i) {
|
|
|
|
- return this.shift(EnumDirection.EAST, i);
|
|
|
|
+ return i == 0 ? this : new BlockPosition(this.getX() + i, 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 i) {
|
|
|
|
--
|
2019-06-25 21:18:50 +02:00
|
|
|
2.22.0
|
2019-01-01 04:15:55 +01:00
|
|
|
|