9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-26 10:29:13 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0052-Cache-FluidOcclusionCacheKey-hash.patch
2025-07-25 10:22:55 +08:00

75 lines
2.6 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 FluidOcclusionCacheKey hash
License: LGPL-3.0 (https://www.gnu.org/licenses/lgpl-3.0.html)
Gale - https://galemc.org
The JMH benchmark of this patch can be found in SunBox's `RecordHashCode`
diff --git a/ca/spottedleaf/moonrise/patches/collisions/util/FluidOcclusionCacheKey.java b/ca/spottedleaf/moonrise/patches/collisions/util/FluidOcclusionCacheKey.java
index cf9ffdeff6bf0b62a45f7a44dbfe0dd7d17dc4f4..fcff01c84d611a75dbf79b1644092516c7cfb0bc 100644
--- a/ca/spottedleaf/moonrise/patches/collisions/util/FluidOcclusionCacheKey.java
+++ b/ca/spottedleaf/moonrise/patches/collisions/util/FluidOcclusionCacheKey.java
@@ -3,5 +3,58 @@ package ca.spottedleaf.moonrise.patches.collisions.util;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.state.BlockState;
-public record FluidOcclusionCacheKey(BlockState first, BlockState second, Direction direction, boolean result) {
+// Gale start - cache FluidOcclusionCacheKey hash
+public final class FluidOcclusionCacheKey {
+ private final BlockState first;
+ private final BlockState second;
+ private final Direction direction;
+ private final boolean result;
+ private final int hash;
+
+ public FluidOcclusionCacheKey(BlockState first, BlockState second, Direction direction, boolean result) {
+ this.first = first;
+ this.second = second;
+ this.direction = direction;
+ this.result = result;
+ this.hash = java.util.Objects.hash(first, second, direction, result);
+ }
+
+ public BlockState first() {
+ return first;
+ }
+
+ public BlockState second() {
+ return second;
+ }
+
+ public Direction direction() {
+ return direction;
+ }
+
+ public boolean result() {
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof FluidOcclusionCacheKey fluidOcclusionCacheKey
+ && this.first == fluidOcclusionCacheKey.first
+ && this.second == fluidOcclusionCacheKey.second
+ && this.direction == fluidOcclusionCacheKey.direction;
+ }
+
+ @Override
+ public int hashCode() {
+ return hash;
+ }
+
+ @Override
+ public String toString() {
+ return "FluidOcclusionCacheKey[" +
+ "first=" + first + ", " +
+ "second=" + second + ", " +
+ "direction=" + direction + ", " +
+ "result=" + result + ']';
+ }
+ // Gale end - cache FluidOcclusionCacheKey hash
}