Cache the blockState and biome wrapper hashCodes

This commit is contained in:
James Seibel
2024-03-19 17:36:22 -05:00
parent 592a1c3601
commit 5d60251da0
3 changed files with 9 additions and 4 deletions
@@ -88,7 +88,8 @@ public class BiomeWrapper implements IBiomeWrapper
#endif
/** technically final, but since it requires a method call to generate it can't be marked as such */
private String serialString = null;
private String serialString;
private int hashCode;
@@ -119,6 +120,7 @@ public class BiomeWrapper implements IBiomeWrapper
{
this.biome = biome;
this.serialString = this.serialize(levelWrapper);
this.hashCode = Objects.hash(this.serialString);
LOGGER.trace("Created BiomeWrapper ["+this.serialString+"] for ["+biome+"]");
}
@@ -127,6 +129,7 @@ public class BiomeWrapper implements IBiomeWrapper
{
this.biome = null;
this.serialString = EMPTY_STRING;
this.hashCode = Objects.hash(this.serialString);
}
@@ -168,7 +171,7 @@ public class BiomeWrapper implements IBiomeWrapper
}
@Override
public int hashCode() { return Objects.hash(this.getSerialString()); }
public int hashCode() { return this.hashCode; }
@Override
public String getSerialString() { return this.serialString; }
@@ -83,6 +83,7 @@ public class BlockStateWrapper implements IBlockStateWrapper
public final BlockState blockState;
/** technically final, but since it requires a method call to generate it can't be marked as such */
private String serialString;
private final int hashCode;
/**
* Cached opacity value, -1 if not populated. <br>
* Should be between {@link IBlockStateWrapper#FULLY_OPAQUE} and {@link IBlockStateWrapper#FULLY_OPAQUE}
@@ -121,6 +122,7 @@ public class BlockStateWrapper implements IBlockStateWrapper
{
this.blockState = blockState;
this.serialString = this.serialize(levelWrapper);
this.hashCode = Objects.hash(this.serialString);
this.irisBlockMaterialId = this.calculateIrisBlockMaterialId();
LOGGER.trace("Created BlockStateWrapper ["+this.serialString+"] for ["+blockState+"] with material ID ["+this.irisBlockMaterialId+"]");
}
@@ -245,7 +247,7 @@ public class BlockStateWrapper implements IBlockStateWrapper
}
@Override
public int hashCode() { return Objects.hash(this.getSerialString()); }
public int hashCode() { return this.hashCode; }
@Override