-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 499fbc2
Showing
12 changed files
with
87,502 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.metadata/** | ||
.recommenders/** | ||
.settings/** | ||
bin/** | ||
target/** | ||
**/psd/** | ||
*.class | ||
*.dtd | ||
*.sh | ||
*.bat | ||
*.lnk | ||
|
||
.classpath | ||
.project | ||
|
||
# IntelliJ IDEA Project stuff | ||
.idea/ | ||
out/ | ||
*.iws | ||
*.iml | ||
*___jb_*___ | ||
/target/ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Recaf plugin workspace | ||
|
||
This is a sample maven workspace for creating plugins for Recaf `2.X`. | ||
|
||
## Plugin documentation | ||
|
||
The official documentation can be found here: [Recaf Docs:Plugins](https://col-e.github.io/Recaf/doc-advanced-plugin.html). | ||
|
||
The source and javadoc artifacts are also available and can be fetched in your IDE workspace. | ||
|
||
## Building & modification | ||
|
||
Once you've downloaded or cloned the repository, you can compile with `mvn clean package`. | ||
This will generate the file `target/plugin-{VERSION}.jar`. To add your plugin to Recaf: | ||
|
||
1. Navigate to the `plugins` folder. | ||
- Windows: `%HOMEPATH%/Recaf/plugins` | ||
- Linux: `$HOME/Recaf/plugins` | ||
2. Copy your plugin jar into this folder | ||
3. Run Recaf to verify your plugin loads. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<div align="center"> | ||
|
||
# Recaf4Forge | ||
|
||
Inspired by [Luyten4Forge](https://github.com/KevinPriv/Luyten4Forge) | ||
|
||
![VERSION](https://img.shields.io/github/v/release/1fxe/Recaf4Forge?style=flat-square) | ||
![ISSUES](https://img.shields.io/github/issues/1fxe/Recaf4Forge?style=flat-square) | ||
|
||
</div> | ||
|
||
## What is this? | ||
|
||
This is a plugin for Recaf which can automatically detects a Minecraft Forge Mods version using the mcmod.info and | ||
applies the correct mapping. | ||
|
||
The mappings are stored in this jar file, so you don't have to manually find them. | ||
|
||
It currently works for 1.8, 1.8.9 and 1.9.4 | ||
|
||
### Example Usage | ||
|
||
<details> | ||
<summary>Click here to see an example of automatic mappings</summary> | ||
|
||
![Automatic Example](.github/automatic.gif) | ||
|
||
</details> | ||
|
||
<details> | ||
<summary>Click here to see an example of manual mappings</summary> | ||
|
||
![Manual Example](.github/manual.gif) | ||
|
||
</details> | ||
|
||
## TODO | ||
|
||
- Extract source to relevant forge MDK | ||
- Add support for other versions | ||
- Add translations? | ||
|
||
### Contributing | ||
|
||
See [Contributing](CONTRIBUTING.md) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<!-- Your personal package --> | ||
<groupId>dev.fxe</groupId> | ||
<artifactId>recaf4forge</artifactId> | ||
<version>1.0.0</version> | ||
<name>Recaf4Forge</name> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<!-- Additional repo's --> | ||
<repositories> | ||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
</repository> | ||
</repositories> | ||
<!-- Dependencies, most are inferred by Recaf's own dependency list --> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.github.Col-E</groupId> | ||
<artifactId>recaf</artifactId> | ||
<version>2.4.0</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.7.0</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package dev.fxe.recaf_forge; | ||
|
||
import me.coley.recaf.ui.controls.ExceptionAlert; | ||
import org.apache.commons.io.IOUtils; | ||
import org.jline.utils.Log; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.InputStream; | ||
import java.nio.file.Path; | ||
|
||
/** | ||
* @author Filip | ||
*/ | ||
public class ExtractMappings { | ||
|
||
public static Path getMappingsPath(String resourcePath) { | ||
try (InputStream in = ExtractMappings.class.getResourceAsStream(resourcePath)) { | ||
String[] strings = resourcePath.split("\\."); | ||
String suffix = strings[strings.length - 1]; | ||
if (in != null) { | ||
File tempFile = File.createTempFile(String.valueOf(in.hashCode()), suffix); | ||
tempFile.deleteOnExit(); | ||
try (FileOutputStream out = new FileOutputStream(tempFile)) { | ||
byte[] array = IOUtils.toByteArray(in); | ||
out.write(array); | ||
return tempFile.toPath(); | ||
} catch (Exception ex) { | ||
ExceptionAlert.show(ex, "Failed to create mappings file"); | ||
} | ||
} else { | ||
Log.info("InputStream is null"); | ||
} | ||
} catch (Exception ex) { | ||
ExceptionAlert.show(ex, "Failed to read resources"); | ||
} | ||
return null; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package dev.fxe.recaf_forge; | ||
|
||
import com.eclipsesource.json.Json; | ||
import com.eclipsesource.json.JsonValue; | ||
import javafx.scene.control.Menu; | ||
import javafx.scene.control.MenuItem; | ||
import me.coley.recaf.config.Conf; | ||
import me.coley.recaf.mapping.MappingImpl; | ||
import me.coley.recaf.mapping.Mappings; | ||
import me.coley.recaf.plugin.api.ConfigurablePlugin; | ||
import me.coley.recaf.plugin.api.MenuProviderPlugin; | ||
import me.coley.recaf.plugin.api.WorkspacePlugin; | ||
import me.coley.recaf.ui.controls.ActionMenuItem; | ||
import me.coley.recaf.ui.controls.ExceptionAlert; | ||
import me.coley.recaf.util.struct.ListeningMap; | ||
import me.coley.recaf.workspace.Workspace; | ||
import org.jline.utils.Log; | ||
import org.plugface.core.annotations.Plugin; | ||
|
||
import java.nio.file.Path; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
/** | ||
* @author Filip | ||
*/ | ||
@Plugin(name = "Recaf4Forge") | ||
public class Recaf4Forge implements ConfigurablePlugin, MenuProviderPlugin, WorkspacePlugin { | ||
|
||
private final String[] versions = {"1.8", "1.8.9", "1.9.4"}; | ||
private final ExecutorService executor = Executors.newSingleThreadExecutor(); | ||
private Workspace currentWorkspace = null; | ||
private String currentVersion = "None"; | ||
|
||
@Conf(value = "Automatically apply mappings", noTranslate = true) | ||
private boolean autoApply = false; | ||
|
||
@Override | ||
public String getName() { | ||
return "Recaf4Forge"; | ||
} | ||
|
||
@Override | ||
public String getVersion() { | ||
return "1.0"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Recaf4Forge will automatically try apply the correct mappings for a forge mod"; | ||
} | ||
|
||
@Override | ||
public Menu createMenu() { | ||
MenuItem[] itemList = new MenuItem[versions.length]; | ||
int index = 0; | ||
for (String version : versions) { | ||
MenuItem item = new ActionMenuItem(version, () -> { | ||
currentVersion = version; | ||
applyMapping(); | ||
}); | ||
itemList[index] = item; | ||
index++; | ||
} | ||
return new Menu(getName(), null, itemList); | ||
} | ||
|
||
@Override | ||
public void onClosed(Workspace workspace) { | ||
currentWorkspace = null; | ||
} | ||
|
||
|
||
@Override | ||
public void onOpened(Workspace workspace) { | ||
currentWorkspace = workspace; | ||
if (this.autoApply) { | ||
CompletableFuture.runAsync(this::detectVersion, executor); | ||
} | ||
} | ||
|
||
private void detectVersion() { | ||
ListeningMap<String, byte[]> data = currentWorkspace.getPrimary().getFiles(); | ||
byte[] mcModInfo = data.get("mcmod.info"); | ||
JsonValue jsonValue = Json.parse(new String(mcModInfo)); | ||
String version = jsonValue.asArray().get(0).asObject().get("mcversion").asString(); | ||
for (String s : versions) { | ||
if (s.equalsIgnoreCase(version)) { | ||
currentVersion = version; | ||
applyMapping(); | ||
return; | ||
} | ||
} | ||
Log.info(getName() + " Failed to find mod version"); | ||
currentVersion = ""; | ||
} | ||
|
||
private void applyMapping() { | ||
String path = "/mappings/" + currentVersion.replaceAll("\\.", "_") + "/mappings.srg"; | ||
Path mappingPath = ExtractMappings.getMappingsPath(path); | ||
if (mappingPath == null) { | ||
Log.info(getName() + " Could not find mappings"); | ||
return; | ||
} | ||
try { | ||
Mappings mappings = MappingImpl.SRG.create(mappingPath, currentWorkspace); | ||
mappings.setCheckFieldHierarchy(true); | ||
mappings.setCheckMethodHierarchy(true); | ||
mappings.accept(currentWorkspace.getPrimary()); | ||
} catch (Exception ex) { | ||
ExceptionAlert.show(ex, getName() + " Failed to apply mappings"); | ||
} | ||
} | ||
|
||
@Override | ||
public String getConfigTabTitle() { | ||
return getName(); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.