9
0
mirror of https://github.com/Dreeam-qwq/Gale.git synced 2025-12-30 03:59:08 +00:00
Files
Gale/gale-server/minecraft-patches/features/0056-Cache-BlockStatePairKey-hash.patch
2025-01-27 09:45:41 -05:00

58 lines
2.5 KiB
Diff

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/net/minecraft/world/level/material/FlowingFluid.java b/net/minecraft/world/level/material/FlowingFluid.java
index e30499bdcd6600e5c9d4a755c1182fb6dff3735f..c47a33a989d7ffea4f0bbae39fd64869369e9bda 100644
--- a/net/minecraft/world/level/material/FlowingFluid.java
+++ b/net/minecraft/world/level/material/FlowingFluid.java
@@ -535,7 +535,26 @@ public abstract class FlowingFluid extends Fluid {
: this.shapes.computeIfAbsent(state, fluidState -> Shapes.box(0.0, 0.0, 0.0, 1.0, fluidState.getHeight(level, pos), 1.0));
}
- record BlockStatePairKey(BlockState first, BlockState second, Direction direction) {
+ // Gale start - Lithium - cache BlockStatePairKey hash
+ 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;
+ }
+ // Gale end - Lithium - cache BlockStatePairKey hash
+
@Override
public boolean equals(Object object) {
return object instanceof FlowingFluid.BlockStatePairKey blockStatePairKey
@@ -546,9 +565,7 @@ public abstract class FlowingFluid extends Fluid {
@Override
public int hashCode() {
- int i = System.identityHashCode(this.first);
- i = 31 * i + System.identityHashCode(this.second);
- return 31 * i + this.direction.hashCode();
+ return this.hash; // Gale - Lithium - cache BlockStatePairKey hash
}
}