Skip to content

Commit

Permalink
make mipmaps derive from previous texture if one is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
Jab125 committed Jan 10, 2025
1 parent bfa3281 commit 4bc4ff2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.InputStream;
import java.nio.file.Path;
import java.util.Optional;
import java.util.function.Consumer;

/**
* Mipmap helper for creating mipmap types
Expand Down Expand Up @@ -83,6 +84,14 @@ public static void addManualMipmaps(int mipmapLevels, NativeImage[] mipmaps, Res
}
}

/// Adds manual mipmaps in `textures/ltmipmaps`
public static void maybeGetMipmapForLevel(int level, Consumer<NativeImage> consumer, ResourceLocation currentResourceLocation) {
if (!Tweaks.MIPMAPPING.manualMipmapping.isEnabled()) return;
if (currentResourceLocation == null) return;
Optional<NativeImage> nativeImage = fromResource(ResourceLocation.fromNamespaceAndPath(currentResourceLocation.getNamespace(), "textures/ltmipmaps/" + currentResourceLocation.getPath() + "/" + level + ".png"));
nativeImage.ifPresent(consumer::accept);
}


/// Gets an {@link Optional}`<`{@link NativeImage}`>` from a {@link ResourceLocation}
private static Optional<NativeImage> fromResource(ResourceLocation resourceLocation) {
Expand Down Expand Up @@ -143,6 +152,8 @@ public static NativeImage[] mipmapTU1(NativeImage[] originals, int mipmap) {
}
}
nativeImages[i] = nativeImage2;
int finalI = i;
maybeGetMipmapForLevel(i, g -> nativeImages[finalI] = g, currentResourceLocation);
}
}
return nativeImages;
Expand Down Expand Up @@ -179,6 +190,8 @@ public static NativeImage[] mipmapTU3(NativeImage[] originals, int mipmap) {
}
}
nativeImages[i] = nativeImage2;
int finalI = i;
maybeGetMipmapForLevel(i, g -> nativeImages[finalI] = g, currentResourceLocation);
}
}
return nativeImages;
Expand Down Expand Up @@ -217,6 +230,8 @@ public static NativeImage[] mipmapTU12(NativeImage[] originals, int mipmap) {
}
}
nativeImages[i] = nativeImage2;
int finalI = i;
maybeGetMipmapForLevel(i, g -> nativeImages[finalI] = g, currentResourceLocation);
}
}
return nativeImages;
Expand Down Expand Up @@ -253,6 +268,8 @@ public static NativeImage[] mipmapJava(NativeImage[] originals, int mipmap) {
}

nativeImages[i] = nativeImage2;
int finalI = i;
maybeGetMipmapForLevel(i, g -> nativeImages[finalI] = g, currentResourceLocation);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ public class MipmapGeneratorMixin {
private static void changeMipmapType(NativeImage[] nativeImages, int i, CallbackInfoReturnable<NativeImage[]> cir) throws IOException {
ResourceLocation currentResourceLocation = MipmapTypeHelper.currentResourceLocation;
MipmapTypeHelper.setMipmapType(nativeImages, i, currentResourceLocation, cir);
if (cir.isCancelled()) {
MipmapTypeHelper.addManualMipmaps(i, cir.getReturnValue(), currentResourceLocation);
}
}

@Inject(method = "generateMipLevels", at = @At("RETURN"))
Expand Down

0 comments on commit 4bc4ff2

Please sign in to comment.