<commit_before>package mezz.texturedump;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.nio.IntBuffer;
import java.nio.charset.Charset;
import java.util.Set;
import java.util.stream.Collectors;

import com.google.gson.stream.JsonWriter;
import mezz.texturedump.util.Log;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.apache.commons.io.IOUtils;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

@Mod(modid = TextureDump.MODID, name = "Texture Dump", version = TextureDump.VERSION, clientSideOnly = true)
public class TextureDump {
	public static final String MODID = "texturedump";
	public static final String VERSION = "1.0";

	@Mod.EventHandler
	public void preInit(FMLPreInitializationEvent event) {
		MinecraftForge.EVENT_BUS.register(this);
	}

	@SubscribeEvent
	public void postTextureStitch(TextureStitchEvent.Post event) {
		TextureMap map = event.getMap();
		String name = map.getBasePath().replace('/', '_');
		int mip = map.getMipmapLevels();
		File outputFolder = new File("texture_dump");
		if (!outputFolder.exists()) {
			if (!outputFolder.mkdir()) {
				Log.error("Failed to create directory " + outputFolder);
				return;
			}
		}
		saveGlTexture(name, map.getGlTextureId(), mip, outputFolder);
		try {
			saveTextureInfo(name, map, mip, outputFolder);
		} catch (IOException e) {
			Log.error("Failed to save texture info.", e);
		}
	}

	public static void saveTextureInfo(String name, TextureMap map, int mipmapLevels, File outputFolder) throws IOException {
		for (int level = 0; level <= mipmapLevels; level++) {
			Set<String> animatedTextures = map.listAnimatedSprites.stream()
					.map(TextureAtlasSprite::getIconName)
					.collect(Collectors.toSet());
<commit_msg>Skip dumping the first (incomplete) texture map<commit_after>package mezz.texturedump;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.nio.IntBuffer;
import java.nio.charset.Charset;
import java.util.Set;
import java.util.stream.Collectors;

import com.google.gson.stream.JsonWriter;
import mezz.texturedump.util.Log;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.apache.commons.io.IOUtils;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

@Mod(modid = TextureDump.MODID, name = "Texture Dump", version = TextureDump.VERSION, clientSideOnly = true)
public class TextureDump {
	public static final String MODID = "texturedump";
	public static final String VERSION = "1.0";

	@Mod.EventHandler
	public void preInit(FMLPreInitializationEvent event) {
		MinecraftForge.EVENT_BUS.register(this);
	}

	@SubscribeEvent
	public void postTextureStitch(TextureStitchEvent.Post event) {
		TextureMap map = event.getMap();
		if (map.mapUploadedSprites.size() <= 1) {
			return; // skip the first texture stitch event that only contains the missing texture
		}
		String name = map.getBasePath().replace('/', '_');
		int mip = map.getMipmapLevels();
		File outputFolder = new File("texture_dump");
		if (!outputFolder.exists()) {
			if (!outputFolder.mkdir()) {
				Log.error("Failed to create directory " + outputFolder);
				return;
			}
		}
		saveGlTexture(name, map.getGlTextureId(), mip, outputFolder);
		try {
			saveTextureInfo(name, map, mip, outputFolder);
		} catch (IOException e) {
			Log.error("Failed to save texture info.", e);
		}
	}

	public static void saveTextureInfo(String name, TextureMap map, int mipmapLevels, File outputFolder) throws IOException {
		for (int level = 0; level <= mipmapLevels; level++) {
			Set<String> animatedTextures = map.listAnimatedSprites.stream()
					.map(TextureAtlasSprite::getIconName)
					.collect(Collectors.toSet());

{'fraction_non_alphanumeric': 0.11426806670784435, 'fraction_numerical': 0.0030883261272390363, 'mean_word_length': 5.425925925925926, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7652130', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1565, 'n_words': 324}