From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Martijn Muijsers 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..f1480625eaece1553d4a96ec54138a463a6fc1ca 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 - Lithium - 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 - Lithium - cache FluidOcclusionCacheKey hash }