Bugzoo Posted August 30, 2014 Posted August 30, 2014 I have a file static File combinedLocation = new File(""); but I need this file location to be the same as this resource location public ResourceLocation combinedTexture = new ResourceLocation("tvmod", "textures/blocks/combined.png"); How would I do this? Quote
Bugzoo Posted August 30, 2014 Author Posted August 30, 2014 On 8/30/2014 at 2:58 PM, diesieben07 said: A ResourceLocation does not necessarily point to a File. A ResourceLocation can point to a file into your mod's jar file, or in the minecraft.jar. All you get is an InputStream via Minecraft.getMinecraft().getResourceManager().getResource(location).getInputStream(); So then how would I link my file to my mod's assets? Quote
NomNuggetNom Posted August 30, 2014 Posted August 30, 2014 On 8/30/2014 at 3:13 PM, ITzZ DannieXD said: Quote A ResourceLocation does not necessarily point to a File. A ResourceLocation can point to a file into your mod's jar file, or in the minecraft.jar. All you get is an InputStream via Minecraft.getMinecraft().getResourceManager().getResource(location).getInputStream(); So then how would I link my file to my mod's assets? In Eclipse, your should have a folder named "src/main/resources". In this folder, you can create an "assets" folder and then your mod ID. So the final path is roughly "src/main/resources/assets/modid." I have my image in the folder: src/main/resources/assets/modid/image.png To reference it, I do: new ResourceLocation("modid", "image.png"); Does that answer your question? Quote
Bugzoo Posted August 30, 2014 Author Posted August 30, 2014 On 8/30/2014 at 5:03 PM, NomNuggetNom said: Quote Quote A ResourceLocation does not necessarily point to a File. A ResourceLocation can point to a file into your mod's jar file, or in the minecraft.jar. All you get is an InputStream via Minecraft.getMinecraft().getResourceManager().getResource(location).getInputStream(); So then how would I link my file to my mod's assets? In Eclipse, your should have a folder named "src/main/resources". In this folder, you can create an "assets" folder and then your mod ID. So the final path is roughly "src/main/resources/assets/modid." I have my image in the folder: src/main/resources/assets/modid/image.png To reference it, I do: new ResourceLocation("modid", "image.png"); Does that answer your question? No, it doesn't. I know how to reference a resource location. The resource location is linked to my mods assets. I want to know how to link a file to my mods assets Quote
NomNuggetNom Posted August 31, 2014 Posted August 31, 2014 On 8/30/2014 at 5:55 PM, ITzZ DannieXD said: Quote Quote Quote A ResourceLocation does not necessarily point to a File. A ResourceLocation can point to a file into your mod's jar file, or in the minecraft.jar. All you get is an InputStream via Minecraft.getMinecraft().getResourceManager().getResource(location).getInputStream(); So then how would I link my file to my mod's assets? In Eclipse, your should have a folder named "src/main/resources". In this folder, you can create an "assets" folder and then your mod ID. So the final path is roughly "src/main/resources/assets/modid." I have my image in the folder: src/main/resources/assets/modid/image.png To reference it, I do: new ResourceLocation("modid", "image.png"); Does that answer your question? No, it doesn't. I know how to reference a resource location. The resource location is linked to my mods assets. I want to know how to link a file to my mods assets So, theoretically, download an image and then use it as a ResourceLocation? I was struggling to do that today myself. Even if that's not your problem I'm curious about a solution Quote
jabelar Posted August 31, 2014 Posted August 31, 2014 You can use file like methods to access an asset, but only read access, not write access because resources are in the JAR which is technically compressed. If you just want to read the file, then you can use various file and streaming Java methods. For example I use the getResourceAsStream() method: readIn = new BufferedReader(new InputStreamReader(getClass().getClassLoader() .getResourceAsStream("assets/magicbeans/structures/schematic.txt"), "UTF-8")); Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
Bugzoo Posted August 31, 2014 Author Posted August 31, 2014 On 8/31/2014 at 6:52 AM, jabelar said: You can use file like methods to access an asset, but only read access, not write access because resources are in the JAR which is technically compressed. If you just want to read the file, then you can use various file and streaming Java methods. For example I use the getResourceAsStream() method: readIn = new BufferedReader(new InputStreamReader(getClass().getClassLoader() .getResourceAsStream("assets/magicbeans/structures/schematic.txt"), "UTF-8")); So, does that mean it's impossible to write to a mods assets? Quote
Bugzoo Posted August 31, 2014 Author Posted August 31, 2014 Well, is there anyway I could make a file and a resource location have the same path? Quote
jabelar Posted August 31, 2014 Posted August 31, 2014 On 8/31/2014 at 10:53 AM, ITzZ DannieXD said: So, does that mean it's impossible to write to a mods assets? Minecraft is Java and you can do whatever Java can do. However in this case I think even Java it may be "impossible" (at least not normal or easy) to change assets within the JAR. However, you can write and read from filesystem like normal Java. For example, you could put this asset in the configuration folder (which is usually in user directory). So imagine you have a default asset inside your JAR, then when game starts you check to see if there is a newer copy in some file location in user directory, and if not copy it there. After that you can write it how you like. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
Bugzoo Posted August 31, 2014 Author Posted August 31, 2014 On 8/31/2014 at 5:11 PM, jabelar said: Quote So, does that mean it's impossible to write to a mods assets? Minecraft is Java and you can do whatever Java can do. However in this case I think even Java it may be "impossible" (at least not normal or easy) to change assets within the JAR. However, you can write and read from filesystem like normal Java. For example, you could put this asset in the configuration folder (which is usually in user directory). So imagine you have a default asset inside your JAR, then when game starts you check to see if there is a newer copy in some file location in user directory, and if not copy it there. After that you can write it how you like. How exactly would I copy it there? If you have any code that would be nice Quote
jabelar Posted August 31, 2014 Posted August 31, 2014 On 8/31/2014 at 7:41 PM, ITzZ DannieXD said: How exactly would I copy it there? If you have any code that would be nice Like I said, you should just look up examples in regular Java. I understand that file I/O in any computer language can be a bit confusing, but I already gave you an example on how to read a file from your assets folder into a buffer. Then you just need standard Java to output the buffer with file writer type code. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
NomNuggetNom Posted August 31, 2014 Posted August 31, 2014 On 8/31/2014 at 8:07 PM, diesieben07 said: You cannot write to your assets. Why do you want to? What are you trying to do? A lot of methods require a ResourceLocation as a parameter. I think the OP is trying to use a file that is outside assets folder, which obviously has no ResourceLocation. Quote
NomNuggetNom Posted August 31, 2014 Posted August 31, 2014 On 8/31/2014 at 9:41 PM, diesieben07 said: Quote A lot of methods require a ResourceLocation as a parameter. I think the OP is trying to use a file that is outside assets folder, which obviously has no ResourceLocation. Ok, that's something else. But then they should have asked for that and not how to write to the assets folder. To do that, implement IResourcePack yourself and register it. This is just me inferring. I'm having the same problem he is, as far as I can tell. I'm digging around in the IResourcePack code and I'm not sure how it would help me. Let's say, for example, you download an image and want to draw it on the screen. I have no problem downloading the image, but let's say it ends up in the root .minecraft directory. Now I have a method that requires a ResourceLocation, such as bindTexture - how do I reference the image I just downloaded? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.