mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-20 20:22:28 +00:00
Allow providing a BufferedImage for banner render generation (#5041)
* Adds an Event to allow providing a BufferedImage for the banner render generation (cached) This allows mods to provide generated banner textures, since banners don't use an atlas. Includes reference/test implementation. * Missed some copyright; might as well absolut text match, I guess * Remove unneeded patch change * Fix event variable access convention * Formatting fix * Improve event handling registration * Import cleanup * Replace event approach with Supplier approach * Better name for test mod (now that it's no longer an event); adds ENABLE flag * Moves MC code into net.minecraftforge.client.MinecraftForgeClient.getImageLayer to simplify patch * Generalize naming
This commit is contained in:
1 parent
857573f10f
commit
1ba084f131
3 files changed
+224
No files matched your search
@@ -19,12 +19,22 @@
|
||||
|
||||
package net.minecraftforge.client;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
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.TextureUtil;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.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 +134,21 @@ public class MinecraftForgeClient
|
||||
regionCache.invalidateAll();
|
||||
regionCache.cleanUp();
|
||||
}
|
||||
|
||||
private static HashMap<ResourceLocation, Supplier<BufferedImage>> bufferedImageSuppliers = new HashMap<ResourceLocation, Supplier<BufferedImage>>();
|
||||
public static void registerImageLayerSupplier(ResourceLocation resourceLocation, Supplier<BufferedImage> supplier)
|
||||
{
|
||||
bufferedImageSuppliers.put(resourceLocation, supplier);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static BufferedImage getImageLayer(ResourceLocation resourceLocation, IResourceManager resourceManager) throws IOException
|
||||
{
|
||||
Supplier<BufferedImage> supplier = bufferedImageSuppliers.get(resourceLocation);
|
||||
if (supplier != null)
|
||||
return supplier.get();
|
||||
|
||||
IResource iresource1 = resourceManager.getResource(resourceLocation);
|
||||
return TextureUtil.readBufferedImage(iresource1.getInputStream());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user