Allow providing a BufferedImage for banner render generation (#5041)

Ported to 1.13 using NativeImage

Co-authored-by: tterrag <tterrag1098@gmail.com>
This commit is contained in:
XCompWizandtterrag authored and tterrag committed 2019-01-11 18:32:17 -05:00
1 parent 497bc10d0a
commit f2b54acd67
3 files changed
+222

No files matched your search

@@ -19,12 +19,21 @@
package net.minecraftforge.client;
import java.io.IOException;
import java.util.BitSet;
import java.util.HashMap;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import javax.annotation.Nonnull;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.NativeImage;
import net.minecraft.resources.IResource;
import net.minecraft.resources.IResourceManager;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ChunkCache;
import net.minecraft.world.World;
@@ -124,4 +133,21 @@ public class MinecraftForgeClient
regionCache.invalidateAll();
regionCache.cleanUp();
}
private static HashMap<ResourceLocation, Supplier<NativeImage>> bufferedImageSuppliers = new HashMap<ResourceLocation, Supplier<NativeImage>>();
public static void registerImageLayerSupplier(ResourceLocation resourceLocation, Supplier<NativeImage> supplier)
{
bufferedImageSuppliers.put(resourceLocation, supplier);
}
@Nonnull
public static NativeImage getImageLayer(ResourceLocation resourceLocation, IResourceManager resourceManager) throws IOException
{
Supplier<NativeImage> supplier = bufferedImageSuppliers.get(resourceLocation);
if (supplier != null)
return supplier.get();
IResource iresource1 = resourceManager.getResource(resourceLocation);
return NativeImage.read(iresource1.getInputStream());
}
}