2020-05-06 11:48:49 +02:00
|
|
|
From 0000000000000000000000000000000000000000 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
|
2020-08-25 04:22:08 +02:00
|
|
|
index f112fe95cb89f6196a41252193e9eb44008cfc5f..f068436960c96b0df427bcdf337a4dcc6a9f66f5 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
|
2020-08-25 04:22:08 +02:00
|
|
|
@@ -115,58 +115,75 @@ public class BlockPosition extends BaseBlockPosition {
|
2019-01-01 04:15:55 +01:00
|
|
|
|
2020-08-25 04:22:08 +02:00
|
|
|
@Override
|
2019-01-01 04:15:55 +01:00
|
|
|
public BlockPosition up() {
|
2019-12-12 01:03:31 +01:00
|
|
|
- return this.shift(EnumDirection.UP);
|
2019-01-01 04:15:55 +01:00
|
|
|
+ return new BlockPosition(this.getX(), this.getY() + 1, this.getZ()); // Paper - Optimize BlockPosition
|
|
|
|
}
|
|
|
|
|
2020-08-25 04:22:08 +02:00
|
|
|
@Override
|
2019-01-01 04:15:55 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-12-12 01:03:31 +01:00
|
|
|
@Override
|
2019-01-01 04:15:55 +01:00
|
|
|
public BlockPosition down() {
|
2019-12-12 01:03:31 +01:00
|
|
|
- return this.shift(EnumDirection.DOWN);
|
2019-01-01 04:15:55 +01:00
|
|
|
+ return new BlockPosition(this.getX(), this.getY() - 1, this.getZ()); // Paper - Optimize BlockPosition
|
|
|
|
}
|
|
|
|
|
2019-12-12 01:03:31 +01:00
|
|
|
@Override
|
2019-01-01 04:15:55 +01:00
|
|
|
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() {
|
2019-12-12 01:03:31 +01:00
|
|
|
- return this.shift(EnumDirection.NORTH);
|
2019-01-01 04:15:55 +01:00
|
|
|
+ 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() {
|
2019-12-12 01:03:31 +01:00
|
|
|
- return this.shift(EnumDirection.SOUTH);
|
2019-01-01 04:15:55 +01:00
|
|
|
+ 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() {
|
2019-12-12 01:03:31 +01:00
|
|
|
- return this.shift(EnumDirection.WEST);
|
2019-01-01 04:15:55 +01:00
|
|
|
+ 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() {
|
2019-12-12 01:03:31 +01:00
|
|
|
- return this.shift(EnumDirection.EAST);
|
2019-01-01 04:15:55 +01:00
|
|
|
+ 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) {
|
2019-12-12 01:03:31 +01:00
|
|
|
- return new BlockPosition(this.getX() + enumdirection.getAdjacentX(), this.getY() + enumdirection.getAdjacentY(), this.getZ() + enumdirection.getAdjacentZ());
|
2019-01-01 04:15:55 +01:00
|
|
|
+ // 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
|
|
|
|
}
|
|
|
|
|
2019-12-12 01:03:31 +01:00
|
|
|
@Override
|