mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-30 12:29:18 +00:00
1.20.6 (#216)
--------- Co-authored-by: MC_XiaoHei <xiaohei.xor7studio@foxmail.com> Co-authored-by: Bluemangoo <chenfy2006@qq.com>
This commit is contained in:
52
patches/server/0086-Cache-BlockStatePairKey-hash.patch
Normal file
52
patches/server/0086-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 41f1a7bf2fb87b6d28d2ca392dfee5d5032d2151..c6bb82c8b755b012735d74bd27deab8e380858c1 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/Block.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
|
||||
@@ -629,11 +629,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) {
|
||||
@@ -649,11 +656,17 @@ public class Block extends BlockBehaviour implements ItemLike {
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
- int i = this.first.hashCode();
|
||||
+ // Leaves start - cache BlockStatePairKey hash
|
||||
+ if (!org.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