Files
AkarinMC/patches/server/0016-Cache-hashcode-for-BlockPosition.patch
ㄗㄠˋ ㄑㄧˊ 518c6e1ce6 Updated Upstream (Tuinity)
Upstream has released updates that appears to apply and compile correctly
Tuinity Changes:
12efad6 Prevent log spam for "Block is water but TE is chest"
6d4fc1f Prevent unload() calls removing tickets for sync loads
f9de229 Allow entities to be removed during entity tick
ca376d1 Make sure flush consolidation works
16b65f0 Make setting of TE less hacky
7c03cbe Rebuild patches
da09c8c Merge branch 'master' of github.com:Spottedleaf/Tuinity
7ed0891 Remove an unused patch (#133)
fc37bbd Remove allocation of Long by the light engine
1bb0c6a Updated Upstream (Paper)
eb0ca1a Ensure pistons moving signs drops signs items if they can't be placed
35bd141 Add the option to allow pistons to push tile entities
f355806 Fix incorrect async future completion by worldgen thread
2051fe3 Revert frustrum priority in ChunkMapDistance
7e7af54 Updated Upstream (Paper)
8c4edd5 Prevent getChunkAt from retaining chunks for long periods of time
42ce364 Updated Upstream (Paper)
391273f Fix newer jdk compile
2020-06-19 19:40:28 +08:00

73 lines
3.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Sotr <i@omc.hk>
Date: Wed, 15 Apr 2020 04:28:25 +0700
Subject: [PATCH] Cache hashcode for BlockPosition
diff --git a/src/main/java/net/minecraft/server/BaseBlockPosition.java b/src/main/java/net/minecraft/server/BaseBlockPosition.java
index a0450a7ddf21659c5636b3f298e6bf4f0a93fc4d..c4227ff056f906c6ea1fec0330d2db84409a6482 100644
--- a/src/main/java/net/minecraft/server/BaseBlockPosition.java
+++ b/src/main/java/net/minecraft/server/BaseBlockPosition.java
@@ -19,6 +19,7 @@ public class BaseBlockPosition implements Comparable<BaseBlockPosition> {
return y < 0 || y >= 256;
}
// Paper end
+ protected int hash; // Akarin - cache hashcode
public BaseBlockPosition(int i, int j, int k) {
this.x = i;
@@ -43,8 +44,20 @@ public class BaseBlockPosition implements Comparable<BaseBlockPosition> {
}
public final int hashCode() { // Paper
- return (this.y + this.z * 31) * 31 + this.x; // Paper
+ // Akarin start - cache hashcode
+ int result = hash; // Make the situation not too bad when it is modified by multiple threads
+ if (result == 0) {
+ result = (this.y + this.z * 31) * 31 + this.x; // Paper
+ hash = result;
+ }
+ return result;
+ // return (this.getY() + this.getZ() * 31) * 31 + this.getX();
+ }
+
+ public final void recalcHashCode() {
+ hash = 0;
}
+ // Akarin end
public int compareTo(BaseBlockPosition baseblockposition) {
return this.getY() == baseblockposition.getY() ? (this.getZ() == baseblockposition.getZ() ? this.getX() - baseblockposition.getX() : this.getZ() - baseblockposition.getZ()) : this.getY() - baseblockposition.getY();
diff --git a/src/main/java/net/minecraft/server/BlockPosition.java b/src/main/java/net/minecraft/server/BlockPosition.java
index 4c64798fbc50f4d8b08502ba865c5fde5c968e62..ba6d9c838bf7cd16ad300029521f089d48f19547 100644
--- a/src/main/java/net/minecraft/server/BlockPosition.java
+++ b/src/main/java/net/minecraft/server/BlockPosition.java
@@ -437,6 +437,7 @@ public class BlockPosition extends BaseBlockPosition implements MinecraftSeriali
this.y = j;
this.z = k;
// Paper end
+ this.recalcHashCode(); // Akarin - cache hashcode
return this;
}
@@ -477,16 +478,19 @@ public class BlockPosition extends BaseBlockPosition implements MinecraftSeriali
public final void setX(final int x) { this.o(x); } // Paper - OBFHELPER
public void o(int i) {
this.x = i; // Paper change to x
+ this.recalcHashCode(); // Akarin - cache hashcode
}
public final void setY(final int y) { this.p(y); } // Paper - OBFHELPER
public void p(int i) {
this.y = i; // Paper change to y
+ this.recalcHashCode(); // Akarin - cache hashcode
}
public final void setZ(final int z) { this.q(z); } // Paper - OBFHELPER
public void q(int i) {
this.z = i; // Paper change to z
+ this.recalcHashCode(); // Akarin - cache hashcode
}
@Override