diff --git a/projects/pswg/src/main/java/com/parzivail/pswg/character/SwgSpecies.java b/projects/pswg/src/main/java/com/parzivail/pswg/character/SwgSpecies.java index 6869ff483..aa420767d 100644 --- a/projects/pswg/src/main/java/com/parzivail/pswg/character/SwgSpecies.java +++ b/projects/pswg/src/main/java/com/parzivail/pswg/character/SwgSpecies.java @@ -78,11 +78,27 @@ protected static Identifier getClothes(SwgSpecies species, PlayerEntity player) ); } - private static int hashVariableValues(SwgSpecies species, SpeciesVariable... variables) + private static long longHashCode(String s) { - var hash = 0; + var h = 0L; + for (byte v : s.getBytes()) + h = 31 * h + (v & 0xff); + return h; + } + + private static long hashVariableValues(SwgSpecies species, SpeciesVariable... variables) + { + var hash = 0L; for (var variable : variables) - hash = 31 * hash + species.getVariable(variable).hashCode(); + hash = 31 * hash + longHashCode(species.getVariable(variable)); + return hash; + } + + private static long hashVariableValues(Map variables) + { + var hash = 0L; + for (var variable : variables.entrySet()) + hash = 31 * hash + longHashCode(variable.getKey() + "=" + variable.getValue()); return hash; } @@ -273,9 +289,14 @@ public boolean equals(Object o) @Override public int hashCode() { - var result = getSlug().hashCode(); + return (int)longHashCode(); + } + + public long longHashCode() + { + var result = longHashCode(getSlug().toString()); result = 31 * result + gender.hashCode(); - result = 31 * result + variables.hashCode(); + result = 31 * result + hashVariableValues(variables); return result; } diff --git a/projects/pswg/src/main/java/com/parzivail/pswg/client/species/SwgSpeciesRenderer.java b/projects/pswg/src/main/java/com/parzivail/pswg/client/species/SwgSpeciesRenderer.java index 1fcb3a29c..72f41673f 100644 --- a/projects/pswg/src/main/java/com/parzivail/pswg/client/species/SwgSpeciesRenderer.java +++ b/projects/pswg/src/main/java/com/parzivail/pswg/client/species/SwgSpeciesRenderer.java @@ -70,8 +70,8 @@ private static void register(Identifier speciesSlug, Supplier Client.TEX_TRANSPARENT, () -> species.getTextureStack(player)); + var hashCode = species.longHashCode(); + return Client.stackedTextureProvider.getId(String.format("species/%016x", hashCode), () -> Client.TEX_TRANSPARENT, () -> species.getTextureStack(player)); } public static void animateTwilek(AbstractClientPlayerEntity entity, PlayerEntityModel model, PlayerSpeciesModelRenderer renderer, float tickDelta)