Jump to content

[1.7.10] How do I load textures outside of the mod jar?


Eternaldoom

Recommended Posts

Hi,

 

I am creating a mod that allows users to create content (blocks and items) in a JSON file. Since they shouldn't have to open up the mod jar in order to add resources, I need to find a way to load textures and localization from an outside folder. Any idea how to do this? Thanks!

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

Link to comment
Share on other sites

You're also going to need to do a whole lot of sanity checking when you start allowing arbitrary user content in that form into the game. Keep that in mind when you start getting floods of reports of crashes with no explanation.

Link to comment
Share on other sites

So far, I have the following code for my IResourcePack:

public class ResourceLoader implements IResourcePack
{
    public static final Set defaultResourceDomains = ImmutableSet.of("jsoncontent");
    private final Map amap;

    public ResourceLoader(Map par)
    {
        this.amap = par;
    }

    @Override
    public InputStream getInputStream(ResourceLocation location) throws IOException
    {
        InputStream var2 = this.getResourceStream(location);

        if (var2 != null)
        {
            return var2;
        }
        else
        {
            InputStream var3 = this.getStream(location);

            if (var3 != null)
            {
                return var3;
            }
            else
            {
                throw new FileNotFoundException(location.getResourcePath());
            }
        }
    }

    public InputStream getStream(ResourceLocation location) throws IOException
    {
        File var2 = (File)this.amap.get(location.toString());
        return var2 != null && var2.isFile() ? new FileInputStream(var2) : null;
    }

    private InputStream getResourceStream(ResourceLocation location)
    {
        return ResourceLoader.class.getResourceAsStream("assets/" + location.getResourcePath());
    }

    @Override
    public boolean resourceExists(ResourceLocation location)
    {
        return this.getResourceStream(location) != null || this.amap.containsKey(location.toString());
    }

    @Override
    public Set getResourceDomains()
    {
        return defaultResourceDomains;
    }

    @Override
    public IMetadataSection getPackMetadata(IMetadataSerializer p_135058_1_, String p_135058_2_) throws IOException
    {
        return null;
    }

    @Override
    public BufferedImage getPackImage() throws IOException
    {
        return ImageIO.read(ResourceLoader.class.getResourceAsStream("/" + (new ResourceLocation("pack.png")).getResourcePath()));
    }

    @Override
    public String getPackName()
    {
        return "Default";
    }
}

 

I know how to use reflection to set the field value, but what should I use for the map instance? And will my current code for the IResourcePack work? Sequituri, I understand that, and I plan to post tutorials on how to use the mod and have strict crash report guidelines.

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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