Skip to content

Commit

Permalink
fix path issue for getting jar assets
Browse files Browse the repository at this point in the history
  • Loading branch information
DomAmato committed May 16, 2018
1 parent 63bbf4e commit 1406f4e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repositories {
}
}

version = "0.10.0"
version = "0.10.1"
group = "com.dom.robot" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "Roboticraft"

Expand Down
24 changes: 16 additions & 8 deletions src/main/java/com/dyn/robot/RobotMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
Expand Down Expand Up @@ -205,17 +208,23 @@ public void deathEvent(LivingDeathEvent event) {
}
}

private File getJarFile(String dir) {
private File getJarFile(File dir) {
String path = RobotMod.class.getResource("/assets/roboticraft").getPath();

dir = dir.replace("\\", "/");
if (dir.endsWith(".")) {
dir = dir.substring(0, dir.length() - 1);
try {
path = path.substring(path.indexOf(dir.toURI().toURL().getPath()));
} catch (MalformedURLException e) {
RobotMod.logger.error("Problem getting path to jar file", e);
}

path = path.substring(path.indexOf(dir));
path = path.substring(0, path.lastIndexOf('!'));

try {
path = URLDecoder.decode(path, "UTF-8");
} catch (UnsupportedEncodingException e) {
RobotMod.logger.error("Problem decoding path", e);
}

return new File(path);
}

Expand Down Expand Up @@ -385,9 +394,8 @@ public void preInit(FMLPreInitializationEvent event) {
if (!(boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment")) {
try {
JarFile roboMod = new JarFile(getJarFile(FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT
? net.minecraft.client.Minecraft.getMinecraft().mcDataDir.getAbsolutePath()
: FMLCommonHandler.instance().getMinecraftServerInstance().getDataDirectory()
.getAbsolutePath()));
? net.minecraft.client.Minecraft.getMinecraft().mcDataDir
: FMLCommonHandler.instance().getMinecraftServerInstance().getDataDirectory()));
Enumeration<JarEntry> resources = roboMod.entries();
while (resources.hasMoreElements()) {
JarEntry entry = resources.nextElement();
Expand Down

1 comment on commit 1406f4e

@DomAmato
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fix issue #2

Please sign in to comment.