aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0268-Optimize-BlockPosition-helper-methods.patch
blob: d248d915c63d0654cf1044a7d089f426ff6fd009 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
From 0000000000000000000000000000000000000000 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/core/BlockPosition.java b/src/main/java/net/minecraft/core/BlockPosition.java
index 370b2c4460d6b52b5ef7da89f5ebf7ef50deb582..4c9ec211470f95d538d1d95c74796190edf99b87 100644
--- a/src/main/java/net/minecraft/core/BlockPosition.java
+++ b/src/main/java/net/minecraft/core/BlockPosition.java
@@ -121,58 +121,75 @@ public class BlockPosition extends BaseBlockPosition {
 
     @Override
     public BlockPosition up() {
-        return this.shift(EnumDirection.UP);
+        return new BlockPosition(this.getX(), this.getY() + 1, this.getZ()); // Paper - Optimize BlockPosition
     }
 
     @Override
     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
     }
 
     @Override
     public BlockPosition down() {
-        return this.shift(EnumDirection.DOWN);
+        return new BlockPosition(this.getX(), this.getY() - 1, this.getZ()); // Paper - Optimize BlockPosition
     }
 
     @Override
     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.shift(EnumDirection.NORTH);
+        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.shift(EnumDirection.SOUTH);
+        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.shift(EnumDirection.WEST);
+        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.shift(EnumDirection.EAST);
+        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 new BlockPosition(this.getX() + enumdirection.getAdjacentX(), this.getY() + enumdirection.getAdjacentY(), this.getZ() + enumdirection.getAdjacentZ());
+        // 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
     }
 
     @Override