9
0
mirror of https://github.com/Dreeam-qwq/Gale.git synced 2026-01-04 15:31:45 +00:00

Added back Cache BlockStatePairKey hash

This commit is contained in:
Dreeam
2024-12-12 03:10:52 -05:00
parent 39616a908a
commit 50d2b7fcbf
3 changed files with 62 additions and 51 deletions

View File

@@ -0,0 +1,62 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Wed, 30 Nov 2022 15:51:59 +0100
Subject: [PATCH] Cache BlockStatePairKey hash
License: LGPL-3.0 (https://www.gnu.org/licenses/lgpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following mixin:
"net/caffeinemc/mods/lithium/mixin/cached_hashcode/FlowingFluid$BlockStatePairKeyMixin.java"
By: Angeline <jellysquid3@users.noreply.github.com>
As part of: Lithium (https://github.com/CaffeineMC/lithium-fabric)
Licensed under: LGPL-3.0 (https://www.gnu.org/licenses/lgpl-3.0.html)
diff --git a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
index f4fbcbb8ff6d2677af1a02a0801a323c06dce9b1..221978c64cf6171db078c6cbfc850f6aeae73884 100644
--- a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
+++ b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
@@ -577,8 +577,27 @@ public abstract class FlowingFluid extends Fluid {
});
}
- private static record BlockStatePairKey(BlockState first, BlockState second, Direction direction) {
+ // Gale start - Lithium - cache BlockStatePairKey hash
+ private static class BlockStatePairKey {
+
+ private final BlockState first;
+ private final BlockState second;
+ private final Direction direction;
+ private final int hash;
+
+ private BlockStatePairKey(BlockState first, BlockState second, Direction direction) {
+ this.first = first;
+ this.second = second;
+ this.direction = direction;
+ int hash = System.identityHashCode(this.first);
+
+ hash = 31 * hash + System.identityHashCode(this.second);
+ hash = 31 * hash + this.direction.hashCode();
+ this.hash = hash;
+ }
+ @Override
+ // Gale end - Lithium - cache BlockStatePairKey hash
public boolean equals(Object object) {
boolean flag;
@@ -593,12 +612,9 @@ public abstract class FlowingFluid extends Fluid {
return flag;
}
+ @Override // Gale - Lithium - cache BlockStatePairKey hash
public int hashCode() {
- int i = System.identityHashCode(this.first);
-
- i = 31 * i + System.identityHashCode(this.second);
- i = 31 * i + this.direction.hashCode();
- return i;
+ return this.hash; // Gale - Lithium - cache BlockStatePairKey hash
}
}

View File

@@ -1,50 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Wed, 30 Nov 2022 15:51:59 +0100
Subject: [PATCH] Cache BlockStatePairKey hash
License: LGPL-3.0 (https://www.gnu.org/licenses/lgpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following mixin:
"me/jellysquid/mods/lithium/mixin/cached_hashcode/BlockNeighborGroupMixin.java"
By: Angeline <jellysquid3@users.noreply.github.com>
As part of: Lithium (https://github.com/CaffeineMC/lithium-fabric)
Licensed under: LGPL-3.0 (https://www.gnu.org/licenses/lgpl-3.0.html)
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 29947de9eb6887f2e61516523ff08d8b581b0f53..b807f4a5239f32e6b6080a58e055357b7341cf00 100644
--- a/src/main/java/net/minecraft/world/level/block/Block.java
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
@@ -600,11 +600,18 @@ public class Block extends BlockBehaviour implements ItemLike {
private final BlockState first;
private final BlockState second;
private final Direction direction;
+ private final int hash; // Gale - Lithium - cache BlockStatePairKey hash
public BlockStatePairKey(BlockState self, BlockState other, Direction facing) {
this.first = self;
this.second = other;
this.direction = facing;
+ // Gale start - Lithium - cache BlockStatePairKey hash
+ int hash = this.first.hashCode();
+ hash = 31 * hash + this.second.hashCode();
+ hash = 31 * hash + this.direction.hashCode();
+ this.hash = hash;
+ // Gale end - Lithium - cache BlockStatePairKey hash
}
public boolean equals(Object object) {
@@ -620,11 +627,7 @@ public class Block extends BlockBehaviour implements ItemLike {
}
public int hashCode() {
- int i = this.first.hashCode();
-
- i = 31 * i + this.second.hashCode();
- i = 31 * i + this.direction.hashCode();
- return i;
+ return this.hash; // Gale - Lithium - cache BlockStatePairKey hash
}
}
}

View File

@@ -1,6 +1,5 @@
## TODOs
Do a benchmark for `Remove streams and iterators from range check`, getEffectiveRange in ChunkMap
Do benchmark for reduce entity fluid lookup on 1.21.3
Block shape pair key hashcode cache
Check gale force load chunk option whether need or whether need to change.
Apply patches in work