Skip to content

Commit

Permalink
Reenable resourcepack injection, but in a sub-folder. Automatically c…
Browse files Browse the repository at this point in the history
…reate folder structure. Remove the book list setting from the config.
  • Loading branch information
gigaherz committed Jan 26, 2017
1 parent 1ae5470 commit fc0645a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
4 changes: 0 additions & 4 deletions src/main/java/gigaherz/guidebook/GuidebookMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,10 @@ public void preInit(FMLPreInitializationEvent event)
logger = event.getModLog();

Configuration config = new Configuration(event.getSuggestedConfigurationFile());
String[] books = config.get("Books", "BookList", new String[]{GuidebookMod.location("xml/guidebook.xml").toString()}).getStringList();
String[] give = config.get("Books", "GiveOnFirstJoin", new String[0]).getStringList();
bookGUIScale = config.get("general", "BookGUIScale", -1, "-1 for same as GUI scale, 0 for auto, 1+ for small/medium/large").getInt();
config.save();

for (String book : books)
{ BookRegistry.registerBook(new ResourceLocation(book)); }

giveOnFirstJoin = Lists.newArrayList(give);

booksDirectory = new File(event.getModConfigurationDirectory(), "books");
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/gigaherz/guidebook/client/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static void registerModels(ModelRegistryEvent event)
@Override
public void preInit()
{
//injectCustomResourcePack();
injectCustomResourcePack();

MinecraftForge.EVENT_BUS.post(new BookRegistryEvent());
}
Expand All @@ -54,16 +54,29 @@ public void preInit()
@SuppressWarnings("unchecked")
private void injectCustomResourcePack()
{
File booksFolder = GuidebookMod.booksDirectory;
File resourcesFolder = new File(GuidebookMod.booksDirectory, "resources");

if (!booksFolder.exists() || !booksFolder.isDirectory())
if (!resourcesFolder.exists())
{
GuidebookMod.logger.info("The resources folder does not exist, creating...");
if (!resourcesFolder.mkdirs())
{
GuidebookMod.logger.info("The resources folder could not be created, and it won't be injected as a resource pack folder.");
return;
}
}

if (!resourcesFolder.exists() || !resourcesFolder.isDirectory())
{
GuidebookMod.logger.info("There's a file called books, but it's not a directory, so it won't be injected as a resource pack folder.");
return;
}

try
{
List<IResourcePack> rp = (List<IResourcePack>) _defaultResourcePacks.get(Minecraft.getMinecraft());

rp.add(new FolderResourcePack(booksFolder)
rp.add(new FolderResourcePack(resourcesFolder)
{
String prefix = "assets/" + GuidebookMod.MODID + "/";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,21 @@ private static void loadRawBookFiles(IResourceManager manager)
{
File booksFolder = GuidebookMod.booksDirectory;

if (!booksFolder.exists())
{
GuidebookMod.logger.info("The books folder does not exist, creating...");
if (!booksFolder.mkdirs())
{
GuidebookMod.logger.info("The books folder could not be created. Books can't be loaded from it.");
return;
}
}

if (!booksFolder.exists() || !booksFolder.isDirectory())
{
GuidebookMod.logger.info("There's a file called books, but it's not a directory. Books can't be loaded from it.");
return;
}

Collection<File> xmlFiles = FileUtils.listFiles(booksFolder, new String[]{"xml"}, true);

Expand Down

0 comments on commit fc0645a

Please sign in to comment.