Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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!

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.

  • Author

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!

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.