Cache BlockImpl hashcode

This commit is contained in:
TheMode 2021-08-16 20:07:57 +02:00
parent bfdc5a53ca
commit 2339fe1c07

View File

@ -69,6 +69,8 @@ final class BlockImpl implements Block {
private final NBTCompound nbt; private final NBTCompound nbt;
private final BlockHandler handler; private final BlockHandler handler;
private int hashCode; // Cache
BlockImpl(@NotNull Registry.BlockEntry registry, BlockImpl(@NotNull Registry.BlockEntry registry,
@NotNull Map<Map<String, String>, Block> propertyEntry, @NotNull Map<Map<String, String>, Block> propertyEntry,
@NotNull Map<String, String> properties, @NotNull Map<String, String> properties,
@ -151,7 +153,12 @@ final class BlockImpl implements Block {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(stateId(), nbt, handler); int result = hashCode;
if (result == 0) {
result = Objects.hash(stateId(), nbt, handler);
this.hashCode = result;
}
return result;
} }
@Override @Override