9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0055-Cache-BlockStatePairKey-hash.patch

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 6bac3fb751e114855b9b072a7880ab370f111218..91567d45fd809f2fee7ab9abbd27f43869b71016 100644
--- a/net/minecraft/world/level/material/FlowingFluid.java
+++ b/net/minecraft/world/level/material/FlowingFluid.java
@@ -536,7 +536,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
@@ -547,9 +566,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
}
}