Skip to content

Commit

Permalink
fix: Fix textures always being stitched
Browse files Browse the repository at this point in the history
Textures were always being stitched instead of loaded from cache, because `AtlasTextureIdentifier` did not override `equals()` and `hashCode()`.
  • Loading branch information
Steveplays28 committed Aug 5, 2024
1 parent 858b829 commit b24045e
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

@SuppressWarnings({"FieldCanBeLocal", "FieldMayBeFinal", "unused"})
public class AtlasTextureIdentifier {
private @Nullable Identifier identifier;
Expand All @@ -20,4 +22,29 @@ public AtlasTextureIdentifier(@Nullable Identifier identifier, @Nullable Integer
public @Nullable Integer getMipLevel() {
return mipLevel;
}

@Override
public boolean equals(Object other) {
if (!(other instanceof AtlasTextureIdentifier otherAtlasTextureIdentifier)) {
return false;
}

return Objects.equals(getIdentifier(), otherAtlasTextureIdentifier.getIdentifier()) && Objects.equals(
getMipLevel(), otherAtlasTextureIdentifier.getMipLevel());
}

@Override
public int hashCode() {
var identifierHashCode = 1;
if (getIdentifier() != null) {
identifierHashCode = getIdentifier().hashCode();
}

var mipLevelHashCode = 1;
if (getMipLevel() != null) {
mipLevelHashCode = getMipLevel().hashCode();
}

return identifierHashCode * mipLevelHashCode;
}
}

0 comments on commit b24045e

Please sign in to comment.