Posted September 20, 201411 yr 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!
September 21, 201411 yr 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. -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
September 21, 201411 yr 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.