Created
April 29, 2025 01:46
-
-
Save zaralX/2834cc8206cb81afdc98ab3318758f73 to your computer and use it in GitHub Desktop.
dump all minecraft items Fabric 1.21.5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ru.zaralx.mineAssets.client; | |
import com.mojang.blaze3d.systems.RenderSystem; | |
import net.fabricmc.api.ClientModInitializer; | |
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; | |
import net.minecraft.client.MinecraftClient; | |
import net.minecraft.client.gl.Framebuffer; | |
import net.minecraft.item.Item; | |
import net.minecraft.item.ItemStack; | |
import org.lwjgl.opengl.GL11; | |
import ru.zaralx.mineAssets.client.utils.Color; | |
import javax.imageio.ImageIO; | |
import java.awt.image.BufferedImage; | |
import java.io.File; | |
import java.io.IOException; | |
import java.lang.reflect.Field; | |
import java.nio.ByteBuffer; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Objects; | |
import java.util.concurrent.CompletableFuture; | |
public class MineAssetsClient implements ClientModInitializer { | |
private static final MinecraftClient client = MinecraftClient.getInstance(); | |
private static List<Item> allItems = new ArrayList<>(); | |
private static int ticks = 0; | |
private static final int cooldown = 20; | |
private static final int wait = 100; | |
private static boolean isCapturing = false; | |
private static int captureDelay = 0; | |
private static String currentItemName = null; | |
@Override | |
public void onInitializeClient() { | |
HudRenderCallback.EVENT.register((drawContext, tickDelta) -> { | |
if (client.player == null || client.world == null) return; | |
if (allItems.isEmpty()) { | |
allItems = getAllItems(); | |
System.out.println("Items: " + allItems.size()); | |
File screenshotsDir = new File("screenshots"); | |
int fileCount = screenshotsDir.list() != null ? Objects.requireNonNull(screenshotsDir.list()).length : 0; | |
System.out.println("Screenshots has: " + fileCount + " files"); | |
} | |
if (!isCapturing) { | |
ticks++; | |
} | |
if (ticks < wait) { | |
return; | |
} | |
int currentIndex = (ticks - wait) / cooldown; | |
if (currentIndex >= allItems.size()) { | |
return; | |
} | |
Item currentItem = allItems.get(currentIndex); | |
// Draw the item with increased size | |
drawContext.getMatrices().push(); | |
drawContext.getMatrices().scale(8.0f, 8.0f, 8.0f); | |
drawContext.drawItem(new ItemStack(currentItem), 0, 0); | |
drawContext.getMatrices().pop(); | |
// Handle capture timing | |
if (!isCapturing && (ticks - wait) % cooldown == 0) { | |
currentItemName = currentItem.getRegistryEntry().getKey().get().getValue().getPath(); | |
isCapturing = true; | |
captureDelay = 0; | |
} | |
if (isCapturing) { | |
captureDelay++; | |
if (captureDelay >= 5) { // Wait for 5 ticks to ensure proper rendering | |
capture(currentItemName); | |
isCapturing = false; | |
currentItemName = null; | |
} | |
} | |
}); | |
} | |
public static List<Item> getAllItems() { | |
List<Item> items = new ArrayList<>(); | |
try { | |
Class<?> itemsClass = Class.forName("net.minecraft.item.Items"); | |
Field[] fields = itemsClass.getFields(); | |
for (Field field : fields) { | |
if (Item.class.isAssignableFrom(field.getType())) { | |
items.add((Item) field.get(null)); | |
} | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
return items; | |
} | |
public static void capture(String name) { | |
try { | |
File screenshotsDir = new File("screenshots"); | |
if (!screenshotsDir.exists()) { | |
screenshotsDir.mkdir(); | |
} | |
BufferedImage image = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB); | |
ByteBuffer buffer = ByteBuffer.allocateDirect(256 * 256 * 4); | |
int x = 0; | |
int y = client.getWindow().getScaledHeight() - 16; | |
GL11.glReadPixels(x, y, 256, 256, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); | |
int[] pixels = new int[256 * 256]; | |
buffer.rewind(); | |
for (int i = 0; i < pixels.length; i++) { | |
int r = buffer.get() & 0xFF; | |
int g = buffer.get() & 0xFF; | |
int b = buffer.get() & 0xFF; | |
int a = buffer.get() & 0xFF; | |
pixels[i] = (a << 24) | (r << 16) | (g << 8) | b; | |
} | |
for (int yy = 0; yy < 256; yy++) { | |
for (int xx = 0; xx < 256; xx++) { | |
image.setRGB(xx, 255 - yy, pixels[yy * 256 + xx]); | |
} | |
} | |
File outputFile = new File(screenshotsDir, name + ".png"); | |
ImageIO.write(image, "PNG", outputFile); | |
System.out.println("Screenshot saved as: " + outputFile.getAbsolutePath()); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Author
zaralX
commented
Apr 29, 2025
- dump item categories
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment