mirror of
https://github.com/LeavesMC/Leaves.git
synced 2026-01-03 14:22:09 +00:00
Cache BlockStatePairKey hash
This commit is contained in:
@@ -128,10 +128,10 @@ index 35d2da9d91dcdd89de7c0f4af028fd182376ea8d..d73482fb1e71fe2951e96ae0593de268
|
||||
.withRequiredArg()
|
||||
diff --git a/src/main/java/top/leavesmc/leaves/LeavesConfig.java b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..deb8b7e2e71fc8308d28e5d2ad352c1292394202
|
||||
index 0000000000000000000000000000000000000000..af0e5cdf562f437abef4a417cb93643d3c12cd4f
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
|
||||
@@ -0,0 +1,871 @@
|
||||
@@ -0,0 +1,876 @@
|
||||
+package top.leavesmc.leaves;
|
||||
+
|
||||
+import com.destroystokyo.paper.util.SneakyThrow;
|
||||
@@ -828,6 +828,11 @@ index 0000000000000000000000000000000000000000..deb8b7e2e71fc8308d28e5d2ad352c12
|
||||
+ storeMobCountsInArray = getBoolean("settings.performance.store-mob-counts-in-array", storeMobCountsInArray);
|
||||
+ }
|
||||
+
|
||||
+ public static boolean cacheBlockStatePairKeyHash = true;
|
||||
+ private static void cacheBlockStatePairKeyHash() {
|
||||
+ cacheBlockStatePairKeyHash = getBoolean("settings.performance.cache-BlockStatePairKey-hash", cacheBlockStatePairKeyHash);
|
||||
+ }
|
||||
+
|
||||
+ public static final class WorldConfig {
|
||||
+
|
||||
+ public final String worldName;
|
||||
|
||||
52
patches/server/0096-Cache-BlockStatePairKey-hash.patch
Normal file
52
patches/server/0096-Cache-BlockStatePairKey-hash.patch
Normal file
@@ -0,0 +1,52 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: violetc <58360096+s-yh-china@users.noreply.github.com>
|
||||
Date: Tue, 18 Jul 2023 14:59:26 +0800
|
||||
Subject: [PATCH] Cache BlockStatePairKey hash
|
||||
|
||||
This patch is Powered by Gale(https://github.com/GaleMC/Gale)
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/Block.java b/src/main/java/net/minecraft/world/level/block/Block.java
|
||||
index 4dc1cd1b1355ca401cc5094d8e3cdbcd980befb5..96b9d47aa3720491424c35c9e73fc996bfc8cd20 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/Block.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
|
||||
@@ -609,11 +609,18 @@ public class Block extends BlockBehaviour implements ItemLike {
|
||||
private final BlockState first;
|
||||
private final BlockState second;
|
||||
private final Direction direction;
|
||||
+ private final int hash; // Leaves - cache BlockStatePairKey hash
|
||||
|
||||
public BlockStatePairKey(BlockState self, BlockState other, Direction facing) {
|
||||
this.first = self;
|
||||
this.second = other;
|
||||
this.direction = facing;
|
||||
+ // Leaves start - cache BlockStatePairKey hash
|
||||
+ int hash = this.first.hashCode();
|
||||
+ hash = 31 * hash + this.second.hashCode();
|
||||
+ hash = 31 * hash + this.direction.hashCode();
|
||||
+ this.hash = hash;
|
||||
+ // Leaves end - cache BlockStatePairKey hash
|
||||
}
|
||||
|
||||
public boolean equals(Object object) {
|
||||
@@ -629,11 +636,17 @@ public class Block extends BlockBehaviour implements ItemLike {
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
- int i = this.first.hashCode();
|
||||
+ // Leaves start - cache BlockStatePairKey hash
|
||||
+ if (!top.leavesmc.leaves.LeavesConfig.cacheBlockStatePairKeyHash) {
|
||||
+ int i = this.first.hashCode();
|
||||
|
||||
- i = 31 * i + this.second.hashCode();
|
||||
- i = 31 * i + this.direction.hashCode();
|
||||
- return i;
|
||||
+ i = 31 * i + this.second.hashCode();
|
||||
+ i = 31 * i + this.direction.hashCode();
|
||||
+ return i;
|
||||
+ } else {
|
||||
+ return this.hash;
|
||||
+ }
|
||||
+ // Leaves end - cache BlockStatePairKey hash
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user