Skip to content

Instantly share code, notes, and snippets.

@sathonay
Last active May 8, 2024 10:48
Show Gist options
  • Save sathonay/6c2cac4d42503ec6553b9b6c604926c3 to your computer and use it in GitHub Desktop.
Save sathonay/6c2cac4d42503ec6553b9b6c604926c3 to your computer and use it in GitHub Desktop.
Implement ResourcePackImageScaler (a class by @prplz) in mcp
import java.awt.Graphics;
import java.awt.image.BufferedImage;
public class ResourcePackImageScaler {
public static final int SIZE = 64;
public static BufferedImage scalePackImage(BufferedImage image) {
if (image == null) {
return null;
}
if (image.getWidth() == image.getHeight() && image.getWidth() < SIZE) return image; // avoid scaling up images
System.out.println("Scaling resource pack icon from " + image.getWidth() + " to " + SIZE);
BufferedImage smallImage = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_ARGB);
Graphics graphics = smallImage.getGraphics();
graphics.drawImage(image, 0, 0, SIZE, SIZE, null);
graphics.dispose();
return smallImage;
}
}
//create the class ResourcePackImageScaler.java from https://github.com/prplz/MemoryFix/blob/master/src/main/java/io/prplz/memoryfix/ResourcePackImageScaler.java
//go to net.minecraft.client.resources.ResourcePackRepository.Entry
//find the method named updateResourcePack()
public void updateResourcePack() throws IOException
{
this.reResourcePack = (IResourcePack)(this.resourcePackFile.isDirectory() ? new FolderResourcePack(this.resourcePackFile) : new FileResourcePack(this.resourcePackFile));
this.rePackMetadataSection = (PackMetadataSection)this.reResourcePack.getPackMetadata(ResourcePackRepository.this.rprMetadataSerializer, "pack");
try
{
- this.texturePackIcon = this.reResourcePack.getPackImage();
+ this.texturePackIcon = ResourcePackImageScaler.scalePackImage(this.reResourcePack.getPackImage());
}
catch (IOException var2)
{
;
}
if (this.texturePackIcon == null)
{
this.texturePackIcon = ResourcePackRepository.this.rprDefaultResourcePack.getPackImage();
}
this.closeResourcePack();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment