Jump to content

[1.8.9]Loading text from an assets file


captaincleric

Recommended Posts

Is this possible? I've created a TextResource class as detailed below:

 

package com.nosrick.masterofmagic.text;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.data.IMetadataSection;
import net.minecraft.util.ResourceLocation;

public class TextResource implements IResource 
{
protected ResourceLocation m_ResourceLocation;

public TextResource(String location)
{
	m_ResourceLocation = new ResourceLocation(location);
}

@Override
public ResourceLocation getResourceLocation() 
{
	return m_ResourceLocation;
}

@Override
public InputStream getInputStream()
{
	try 
	{
		return new FileInputStream(m_ResourceLocation.getResourceDomain() + "/" + m_ResourceLocation.getResourcePath());
	} 
	catch (FileNotFoundException e) 
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
		return null;
	}
}

@Override
public boolean hasMetadata() 
{
	return false;
}

@Override
public <T extends IMetadataSection> T getMetadata(String p_110526_1_) 
{
	return null;
}

@Override
public String getResourcePackName() 
{
	return null;
}

}

 

 

But I have no idea where it's looking for these files, or if it's doing it correctly. Every time I run it, it throws the exception saying the file can't be found, even though the path appears to be correct.

 

Does anyone know anything about this, or is it better to load a file from outside of the jar?

Link to comment
Share on other sites

InputStream is = Schematic.class.getResourceAsStream("/assets/extendedvillages/schematics/"+name+".schematic");

This is my code to access everything inside assets/extendedvillages/schematics/VARIABLENAME.schematic

You can replace the Schematic.class with TextResource.class if im not mistaken

Link to comment
Share on other sites

I know this is more of a Java problem now (and I am truly thankful for the help), but it always seems to fail to find the asset, even though I appear to be pointing it to the correct path.

 

InputStream stream = TextResource.class.getResourceAsStream("assets/" + MoMMod.MODID + "/text/life_magic.txt");

 

Now, I went into the .jar and looked for this file; it's there, so I don't know why it isn't finding it.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.