|
1 | 1 | # BasicModInfoParser |
2 | | -A basic parser for minecraft mod info. |
3 | | -Currently supports: |
4 | | -- Legacy Forge (mcmod.info) |
5 | | -- Forge and NeoForge (mods.toml and neoforge.mods.toml) |
6 | | -- Fabric (fabric.mod.json) |
| 2 | + |
| 3 | +[](https://jitpack.io/#RaydanOMGr/BasicModInfoParser) |
| 4 | + |
| 5 | +BasicModInfoParser is a lightweight Java library that helps you extract basic information from mod files (such as `.jar` files) for platforms like Minecraft Forge or Fabric. The library parses data such as mod ID, name, version, and description, making it easier to handle mod metadata programmatically. |
| 6 | + |
| 7 | +## Features |
| 8 | +- Supports detecting mod platforms (Forge, Fabric, etc.). |
| 9 | +- Parses mod metadata, including: |
| 10 | + - Mod ID |
| 11 | + - Mod Name |
| 12 | + - Version |
| 13 | + - Description |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +To include this library in your project using JitPack, follow these steps: |
| 18 | + |
| 19 | +1. Add the JitPack repository to your project's `build.gradle` file (or equivalent for other build systems). |
| 20 | + |
| 21 | +### Gradle |
| 22 | + |
| 23 | +```groovy |
| 24 | +repositories { |
| 25 | + maven { url 'https://jitpack.io' } |
| 26 | +} |
| 27 | +
|
| 28 | +dependencies { |
| 29 | + implementation 'com.github.RaydanOMGr:BasicModInfoParser:1.0.1' |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +### Maven |
| 34 | + |
| 35 | +```xml |
| 36 | +<repositories> |
| 37 | + <repository> |
| 38 | + <id>jitpack.io</id> |
| 39 | + <url>https://jitpack.io</url> |
| 40 | + </repository> |
| 41 | +</repositories> |
| 42 | + |
| 43 | +<dependency> |
| 44 | + <groupId>com.github.RaydanOMGr</groupId> |
| 45 | + <artifactId>BasicModInfoParser</artifactId> |
| 46 | + <version>1.0.1</version> |
| 47 | +</dependency> |
| 48 | +``` |
| 49 | + |
| 50 | +## Usage |
| 51 | + |
| 52 | +Here's a simple example demonstrating how to use `BasicModInfoParser` to extract mod information from `.jar` files: |
| 53 | + |
| 54 | +```java |
| 55 | +import me.andreasmelone.basicmodinfoparser.Platform; |
| 56 | +import me.andreasmelone.basicmodinfoparser.BasicModInfo; |
| 57 | + |
| 58 | +import java.io.File; |
| 59 | +import java.io.IOException; |
| 60 | +import java.util.jar.JarFile; |
| 61 | + |
| 62 | +public class ModInfoExample { |
| 63 | + public static void main(String[] args) { |
| 64 | + // Specify the folder containing your .jar files |
| 65 | + File folder = new File("mods/"); |
| 66 | + File[] modFiles = folder.listFiles((dir, name) -> name.endsWith(".jar")); |
| 67 | + |
| 68 | + if (modFiles != null) { |
| 69 | + for (File modFile : modFiles) { |
| 70 | + try (JarFile jarFile = new JarFile(modFile)) { |
| 71 | + // Detect the mod platform (Forge, Fabric, etc.) |
| 72 | + Platform[] platforms = Platform.findModPlatform(modFile); |
| 73 | + for (Platform platform : platforms) { |
| 74 | + // Get the mod info content and parse it |
| 75 | + String modInfoContent = platform.getInfoFileContent(jarFile); |
| 76 | + BasicModInfo modInfo = platform.parse(modInfoContent); |
| 77 | + |
| 78 | + // Output the parsed mod information |
| 79 | + System.out.println("Mod ID: " + modInfo.getId()); |
| 80 | + System.out.println("Mod Name: " + modInfo.getName()); |
| 81 | + System.out.println("Mod Version: " + modInfo.getVersion()); |
| 82 | + System.out.println("Mod Description: " + modInfo.getDescription()); |
| 83 | + } |
| 84 | + } catch (IOException e) { |
| 85 | + System.err.println("Failed to read mod file: " + modFile.getName()); |
| 86 | + e.printStackTrace(); |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +### BasicModInfo Object |
| 95 | + |
| 96 | +The `BasicModInfo` object stores the following details about a mod: |
| 97 | +- **id**: The unique identifier for the mod. |
| 98 | +- **name**: The name of the mod. |
| 99 | +- **version**: The version of the mod. |
| 100 | +- **description**: A brief description of the mod. |
| 101 | + |
| 102 | +## License |
| 103 | + |
| 104 | +This project is licensed under the MIT License. See the `LICENSE` file for more details. |
0 commit comments